Claude API Temperature Settings Explained
Temperature is the parameter that controls how deterministic or varied Claude's responses are. It accepts a value between 0 and 1, where lower values make the model pick the highest-probability next token almost every time, and higher values let it sample from a wider range of plausible tokens, producing more varied and creative output.
If you're trying to decide what value to use: start at 0 for anything that needs consistency (data extraction, classification, code generation, structured JSON output), and move toward 0.7–1.0 for anything that benefits from variety (brainstorming, creative writing, conversational tone). Most production use cases don't need the full range — the practical sweet spot for most apps is between 0 and 0.5.
How temperature actually works
Language models generate text one token at a time. At each step, the model computes a probability distribution over possible next tokens. Temperature scales that distribution before a token is sampled:
- Low temperature (0–0.2): the distribution is sharpened, so the model almost always picks the most likely token. Output is deterministic and repeatable across calls with the same prompt.
- Medium temperature (0.3–0.6): some randomness is introduced, giving slightly different phrasing between runs while staying on-topic and coherent.
- High temperature (0.7–1.0): the distribution is flattened, so lower-probability tokens get picked more often. Output becomes more varied, sometimes more creative, but also more prone to drifting off-topic or producing inconsistent formatting.
Note that temperature 0 doesn't guarantee bit-for-bit identical output across every call — there's still some non-determinism at the infrastructure level — but it gets you as close to repeatable as the API allows.
Setting temperature in a request
Here's a basic request with temperature set explicitly:
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-5",
"max_tokens": 500,
"temperature": 0.2,
"messages": [
{"role": "user", "content": "Summarize this changelog in three bullet points."}
]
}'
If you're routing requests through SubToAPI instead of calling the model directly, the parameter works the same way — SubToAPI passes it straight through to the underlying model:
curl https://api.subtoapi.app/v1/messages \
-H "Authorization: Bearer $SUBTOAPI_KEY" \
-H "content-type: application/json" \
-d '{
"model": "claude-sonnet-4-5",
"max_tokens": 500,
"temperature": 0.2,
"messages": [
{"role": "user", "content": "Summarize this changelog in three bullet points."}
]
}'
See /docs/messages for the full request schema and /docs/quickstart if you're setting up your first API key.
Choosing a value by use case
Data extraction, classification, structured output (temperature 0) Anything that needs to produce the same answer given the same input — pulling fields out of an invoice, tagging support tickets, generating valid JSON against a schema — should use temperature 0. Variance here is a bug, not a feature. If you're also using tool calling for structured output, see /docs/tools for schema design that reduces the need to rely on temperature at all.
Code generation (temperature 0–0.3) Low temperature keeps code idiomatic and reduces the chance of the model inventing APIs that don't exist. A small amount of variance (0.1–0.3) can help when you want multiple candidate solutions to pick from.
Customer-facing chat and support bots (temperature 0.3–0.5) You want consistent tone and accurate answers, but fully deterministic responses can feel robotic when the same question is asked slightly differently. A moderate temperature keeps answers grounded while allowing natural phrasing variation.
Brainstorming, copywriting, creative writing (temperature 0.7–1.0) When the goal is variety — multiple headline options, story ideas, alternative phrasings — higher temperature is appropriate. Just expect more passes through human review, since higher temperature also increases the odds of factual drift or odd phrasing.
Temperature vs. top_p
The Claude API also exposes top_p, which is a related but distinct sampling control. top_p restricts sampling to the smallest set of tokens whose cumulative probability exceeds the given threshold, rather than scaling the whole distribution like temperature does. Anthropic recommends not setting both temperature and top_p in the same request — pick one and leave the other at default. For most applications, temperature alone is simpler to reason about, so start there and only reach for top_p if you have a specific need for distribution-shape control that temperature doesn't give you.
Common mistakes
- Using a high temperature for structured output and then fighting the model to produce valid JSON. Fix the temperature first before adding more prompt instructions.
- Assuming temperature 0 means fully deterministic. It's close, but don't build logic that depends on byte-identical output every time.
- Setting both temperature and top_p without understanding the interaction. This usually makes behavior harder to predict, not easier.
- Not testing across temperature values before shipping. A quick A/B test with 10–20 representative prompts at temperature 0, 0.3, and 0.7 will show you the actual tradeoff for your use case faster than guessing.
If you're building an internal tool or app on top of Claude and want a single API surface with metered usage per key, team seats, and streaming already handled, SubToAPI wraps your existing Claude access into a standard HTTPS API — temperature and every other request parameter pass through unchanged. Check /pricing for plan details or /docs/streaming if you're combining variable temperature with streamed responses.
Questions
What's the default temperature if I don't set it? If you omit the parameter, Claude uses a model-specific default, typically around 1.0. For predictable behavior in production, it's best practice to always set temperature explicitly rather than relying on the default.
Does lower temperature make responses shorter? No. Temperature controls token selection, not length. Response length is governed by max_tokens and the model's judgment about how to complete the task, independent of temperature.
Can I change temperature mid-conversation? Yes. Temperature is set per request, not per conversation, so you can use a low temperature for one turn (e.g., extracting data) and a higher one for the next (e.g., generating a creative reply) within the same session.