Temperature

Temperature is a setting on a language model that controls how much randomness goes into choosing each next token: low values make output more predictable, higher values make it more varied.

Also known as: Sampling temperature

Related terms in this glossary

How it works

At each step a model produces a probability for every possible next token. Temperature rescales those probabilities before one is picked. Near zero, the most likely token almost always wins, so output becomes focused and repeatable. Higher values flatten the distribution, so less likely tokens get chosen more often, giving more varied and sometimes less coherent text.

  • Anthropic's API accepts values from 0 to 1; OpenAI's accepts 0 to 2. Defaults differ by provider.
  • Related settings include top-p (nucleus sampling) and top-k, which cut off unlikely tokens. Providers generally suggest adjusting temperature or top-p, not both.
  • Some reasoning models fix or ignore sampling settings, so check each model's documentation.

Why it matters

Temperature is one of the simplest controls over output style. Low temperature suits extraction, classification, code and factual answers where you want consistency. Moderate to higher values suit brainstorming, marketing drafts and varied phrasing. Two misunderstandings are common. First, temperature 0 does not guarantee identical output every time; small differences in serving infrastructure can still change results, so do not rely on it for strict reproducibility. Second, low temperature does not stop hallucination: a model can be confidently and consistently wrong. Accuracy comes from grounding, good prompts and evaluation. When testing a prompt change, run the eval set several times if temperature is above zero so random variation is not mistaken for improvement. See AI evaluation and observability.

Temperature in depth

Choosing settings by task

Sampling settings should follow from what the output is for. A starting guide, to be confirmed with your own evaluation:

TaskTypical starting pointReason
Extraction, classification, structured outputLow temperature, at or near 0One correct answer; variation only adds errors
Customer replies, summariesLow to moderateConsistent facts with natural phrasing
Code generationLowCorrectness matters; retries can use slightly higher values
Brainstorming, marketing variantsModerate to highDiversity is the goal
Generating several candidates to pick fromModerateNeed different options, then a judge or person selects

Provider defaults are tuned for general chat, so do not assume they suit your task. Ranges differ by provider, so a value that is moderate on one API may be low on another.

Example: tuning a reply drafter

Example: a team's agent drafts replies to customer emails. At the provider's default temperature, drafts sometimes add friendly but unrequested promises, and repeated runs on the same email vary widely. The team tests three temperatures on a fixed set of real emails, running each setting five times per email, and scores drafts with an LLM judge for accuracy and policy compliance, checked against a supervisor's ratings. A low temperature gives the most consistent accurate drafts with acceptable tone; the team adopts it and adds a rule to the prompt about promises. They also set a separate, higher temperature for a "suggest alternative wording" button where variety is wanted.

Testing with randomness in mind

When temperature is above zero, a single run tells you little. Good practice:

  1. Run each test case several times and look at the spread of scores, not one result.
  2. Report pass rates, such as how often a case passes across runs, alongside averages.
  3. Fix temperature and other sampling settings in the evaluation configuration, versioned with the prompt.
  4. When comparing two prompts, use the same settings and enough runs that differences are larger than run-to-run noise.

Some APIs offer a seed parameter for more repeatable sampling, but providers describe it as best effort, so do not rely on exact reproducibility.

  • Top-p: samples only from the smallest set of tokens whose probabilities add up to p.
  • Top-k: samples only from the k most likely tokens.
  • Frequency and presence penalties (on some APIs): discourage repeating tokens or topics.
  • Maximum output tokens: not a sampling control, but often tuned alongside them.

Change one control at a time, and usually only temperature or top-p, not both.

Typical problems are high temperature on extraction tasks, testing a prompt once and calling it fixed, assuming temperature 0 makes outputs identical, and copying settings between models with different ranges. Temperature is one of the levers in prompt engineering; it shapes how tokens are chosen but does not fix hallucination, which needs grounding. Reasoning models may fix these settings. Gepton tunes and tests them in AI evaluation and observability.

Questions about Temperature

Something else? Send us your question and an engineer replies with next steps.

Why do I get different answers at temperature 0?

At temperature 0 the model should pick the most likely token each time, but small numerical differences in how requests are batched and computed on the provider's hardware can change which token is most likely when two are nearly tied. Once one token differs, the rest of the output can diverge. Providers may also update models or serving infrastructure. Design tests and systems to tolerate small variation rather than depend on identical output.

Should temperature be different for Hindi responses?

There is no rule that it must be, but test it. Generating less common languages can be more sensitive to sampling, and higher temperatures may increase spelling inconsistencies, script switching or odd word choices in Hindi and Hinglish. Run your evaluation set separately by language at a few temperatures, and use a lower setting for a language if it clearly improves consistency without making replies stiff.

Articles that mention Temperature

All articles

Jump to

↑↓ to move↵ to open