← Blog

Claude API Parameters: Temperature, top_p, max_tokens for CCA-F

October 7, 2026

Claude API temperature, top_p, and max_tokens explained — with defaults, when to tune each, and the extended thinking hard constraint the CCA-F exam tests.

Claude's API exposes five sampling parameters — temperature, top_p, top_k, max_tokens, and stop_sequences — that control how responses are generated and capped. For most production deployments, the defaults work fine. For CCA-F, know the one hard constraint: extended thinking locks temperature to 1 and disables top_p and top_k entirely.

What Does Temperature Control in the Claude API?

Temperature determines how much randomness Claude introduces when selecting each next token. The parameter accepts a float between 0 and 1, and defaults to 1.

At temperature=0, Claude deterministically picks the highest-probability token at each step, producing predictable, reproducible output. At the default of 1, it samples more freely from the probability distribution, yielding more varied and creative responses.

Lower values suit tasks where consistency matters — structured data extraction, code generation, classification. The default (or values closer to 1) suits creative writing, brainstorming, or any task where output variety is a feature rather than a liability.

response = client.messages.create(
    model="claude-sonnet-4-6",
    max_tokens=1024,
    temperature=0.2,
    messages=[{"role": "user", "content": "Extract the invoice date from this text..."}]
)

One critical rule on current Claude models: temperature and top_p are mutually exclusive. Passing both in the same request returns a 400 error. Choose one or leave both at their defaults.

CCA-F note: The exam tests that temperature ranges from 0 to 1, that 1 is the default, and that it cannot coexist with top_p in the same request on Claude 4 and later models.

How Do top_p and top_k Affect Response Diversity?

Both parameters restrict which tokens Claude considers at each sampling step, but they work differently — and neither is applied by default.

top_p (nucleus sampling) limits token candidates to the smallest set whose cumulative probability sums to the top_p value. Setting top_p=0.9 means only the tokens that together account for 90% of the probability mass are eligible at each step. Values closer to 0 narrow the distribution further; the parameter is off by default.

top_k limits sampling to the top k most probable tokens at each step. top_k=40 means only the 40 highest-probability tokens are ever in the candidate pool. Like top_p, it is not applied unless you set it.

In most production integrations both parameters are left unset. They are available for specialized scenarios — creative writing pipelines, research experiments, or comparative benchmarking — where fine-grained control over the token distribution matters. The mutual-exclusion rule applies here too: top_p and temperature cannot appear in the same request.

What Does max_tokens Cap — and What Happens When the Limit Is Reached?

max_tokens is the only required sampling parameter. It sets a hard ceiling on how many output tokens Claude can generate in a single response. Unlike the other four, it has no default and must be specified on every API call.

When Claude reaches the limit, generation stops immediately. The API returns stop_reason: "max_tokens" rather than the normal "end_turn". Your code should check this field: a "max_tokens" stop reason means the response was truncated and the content may be incomplete.

if response.stop_reason == "max_tokens":
    # Response was cut off — increase max_tokens or use streaming
    ...

For conversational tasks, 1,024–4,096 tokens usually suffices. For code generation, long-form content, or agentic tasks, set it higher. Most current Claude models support up to 128K output tokens at the high end, though streaming is required at that scale.

CCA-F note: max_tokens caps output only. It is distinct from the context window, which governs the combined total of input plus output. The exam tests both concepts separately, and confusing them is a common mistake.

When Should You Set stop_sequences?

stop_sequences is an optional list of strings. When Claude generates any of the specified strings, it stops immediately and excludes that string from the response. The API reports stop_reason: "stop_sequence" when this occurs. The parameter defaults to an empty list — no stop sequences are active unless you configure them.

Practical use cases:

  • Structured output: Instruct Claude to emit a sentinel like </output> when done, then stop on it to get clean, delimited content without trailing explanation.
  • Code generation: Stop at a closing delimiter to prevent output that extends past the intended function or class boundary.
  • Conversational harnesses: Use a specific token as a turn delimiter in multi-agent or scripted dialogue systems.
response = client.messages.create(
    model="claude-opus-4-8",
    max_tokens=2048,
    stop_sequences=[""],
    messages=[{"role": "user", "content": "..."}]
)

Stop sequences are particularly useful when your prompt gives Claude explicit instructions about what to emit at the end of its response — they let you enforce those instructions at the API level rather than in post-processing.

How Does Extended Thinking Change the Sampling Rules?

This is the constraint that distinguishes Claude's API from generic LLM sampling guides — and the one the Claude Certified Architect Foundations exam specifically targets.

When extended thinking is enabled, temperature is locked to 1 and top_p and top_k are disabled. Sending any of these parameters alongside a thinking configuration returns a 400 error. The reason: extended thinking uses a fixed, high-entropy sampling distribution for its internal reasoning chain, and manual sampling overrides would interfere with that process.

This rule applies to the original extended thinking interface (thinking: {type: "enabled", budget_tokens: N}) supported on models including Claude 3.7 Sonnet. On current-generation Opus models (4.7 and 4.8), the restriction is even stricter: temperature, top_p, and top_k are removed entirely from the API — sending any of them returns a 400 whether or not thinking is active on those models.

response = client.messages.create(
    model="claude-opus-4-8",
    max_tokens=16000,
    thinking={"type": "adaptive"},
    messages=[{"role": "user", "content": "Work through this step by step..."}]
)
# Do NOT pass temperature, top_p, or top_k alongside thinking

The rule to internalize for the CCA-F exam: extended thinking and manual sampling-parameter tuning are mutually exclusive. If a request enables thinking, remove temperature, top_p, and top_k.

Which Parameter Defaults Does the Claude Certified Architect Exam Expect You to Know?

The CCA-F exam rewards platform-specific knowledge that goes beyond generic LLM familiarity. Here is the sampling-parameter summary worth memorizing before exam day:

Parameter Valid range Default Required?
temperature0–11No
top_p0–1Not appliedNo
top_kInteger ≥ 0Not appliedNo
max_tokensInteger ≥ 1NoneYes
stop_sequencesList of stringsEmpty listNo

The three facts the exam is most likely to probe:

  1. max_tokens is the only required parameter. Every other sampling parameter is optional with working defaults.
  2. temperature and top_p are mutually exclusive on current Claude models. Using both in the same request returns a 400 error.
  3. Extended thinking locks temperature to 1 and disables top_p and top_k. On Opus 4.7 and 4.8, all three are removed entirely regardless of thinking mode.

Knowing these rules at the API level — not just conceptually — is what separates a well-prepared CCA-F candidate from someone who has only read about LLMs in general.

PlinthPrep is an independent study resource, not affiliated with Anthropic. This post explains how the parameters work conceptually, but knowing how something works and being able to answer a question about it under exam conditions are different things. PlinthPrep's practice questions on the Claude API surface include scenarios that probe the extended thinking constraint and the mutual-exclusion rules directly — the kind that look obvious until you're choosing between two plausible wrong answers. Visit plinthprep.com to work through the question bank before your exam.

Frequently asked questions

What are the default values for Claude's API sampling parameters?
Claude's API defaults temperature to 1, does not apply top_p or top_k by default, initializes stop_sequences as an empty list, and has no default for max_tokens — it is the only required parameter and must be set explicitly on every Messages API request.
Does Claude's extended thinking require temperature to be set to 1?
Yes. When extended thinking is enabled on Claude, temperature is locked to 1 and top_p and top_k are disabled — the API returns a 400 error if you try to set them. On Opus 4.7 and 4.8 with adaptive thinking, all three sampling parameters are removed entirely.
Can you use temperature and top_p together in a Claude API request?
No. On Claude 4 and later models, temperature and top_p are mutually exclusive — passing both in the same request returns a 400 error. They are alternative methods for controlling token sampling. Use one or the other, or omit both to rely on Claude's defaults.
What happens when a Claude API response hits the max_tokens limit?
When a response reaches the max_tokens ceiling, generation stops and the API sets stop_reason to 'max_tokens' instead of 'end_turn'. This signals a truncated, potentially incomplete response. Unlike other sampling parameters, max_tokens has no default and must be specified on every Claude API request.
What is the difference between max_tokens and Claude's context window?
max_tokens caps the number of output tokens Claude generates in a single response. The context window governs the total combined length of input plus output in a conversation. Both are measured in tokens, but they are separate limits — the CCA-F exam tests each concept independently.

Share this post

Plinth Prep is an independent study resource and is not affiliated with, endorsed by, or sponsored by Anthropic. Practice material is written by Plinth Prep and does not reproduce real exam content.