Temperature
A sampling parameter that controls randomness in an LLM's output by scaling the probability distribution of tokens before sampling - lower values produce more deterministic results, higher values produce more varied results.
When an LLM generates the next token, it produces a probability distribution over its entire vocabulary. Temperature scales this distribution before sampling: low temperatures sharpen the distribution (the most likely token becomes overwhelmingly favored), while high temperatures flatten it (unlikely tokens get more chances to appear).
Temperature values in practice
- 0: Close to greedy decoding: the highest-probability token almost always wins. Output is far more consistent, though hosted APIs do not guarantee identical results across runs. Best for factual extraction, code generation, and structured data.
- 0.1 to 0.3: Near-deterministic with small variation between runs. Suitable for most production tasks where consistency matters.
- 0.7 to 1.0: Noticeable variation across outputs. Useful for creative writing, brainstorming, and cases where diversity is desired.
- Above 1.0: Very high randomness. OpenAI and Gemini have allowed values up to 2.0, while Anthropic's range for Claude models that accept temperature is 0 to 1. Output quality typically degrades. Rarely useful in practice.
Temperature and token sampling
Temperature works together with top-p (nucleus) sampling and top-k sampling. Providers generally recommend adjusting temperature or top-p, not both, and Anthropic enforces this: Claude 4.x models before Opus 4.7 return a 400 error when a request sets both. A common configuration on models that accept it is a low temperature such as 0.2 with top-p left at its default. Some open-weight runtimes also support min-p sampling as an alternative constraint.
Many current models no longer accept it
On recent reasoning models, temperature is often fixed. Claude Fable 5.2, Claude Opus 5.5, Claude Sonnet 5.5 and Claude Haiku 5.5 return a 400 error for any non-default temperature, top_p or top_k, and from API version 2026-10-21 the Claude API rejects all three at any value on every model. OpenAI's GPT-6 models accept temperature and top_p only when reasoning effort is set to none, which GPT-6.1 Terra, GPT-6 Luna and the older GPT-6 Sol support and GPT-6 Astra and GPT-6.1 Sol do not. Google's Gemini 4 Argon ignores temperature, top_p and top_k if you send them. On these models, steer output with the prompt, structured outputs, and effort or thinking-level settings instead. Temperature remains a working control on older API models and on open-weight models you run yourself.
Temperature does not determine quality
A common misconception is that higher temperature means lower quality and lower temperature means higher quality. The correct temperature depends on your task. Code output at temperature=1.0 is unreliable; creative writing at temperature=0 is robotic. Match temperature to your specific use case.