← Blog

Claude API Temperature Settings Explained

2026-10-16 · 4 min read · SubToAPI Team

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:

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

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.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →