Temperature controls how much randomness enters token selection during language-model generation. Lower values favor higher-probability tokens, making responses more predictable and reproducible. Higher values increase variation and can make responses more conversational. For a production chatbot, choose it according to the task: a policy answer needs a different level of variation from a creative list. section 2.2.1 section 2.2
The same question, two styles
Asked for iPhone 14 specifications, a chatbot at temperature 0.3 gives a concise list of the display, chip, cameras, and storage options. At 0.8, it gives a longer, more enthusiastic answer about the same features. The change is in the response’s predictability and style—not proof that either answer is correct. section 2.2.1
Set temperature with the task and provider in mind:
- Start around 0.5, then adjust toward specificity or creativity. Review the resulting answers rather than assuming a setting guarantees accuracy. section 2.9 section 2.2.1
- Check the model’s supported range. GPT-4.1 supports 0–2 and Claude Sonnet 4.6 supports 0–1; the cited reasoning-focused models do not support temperature. section 2.2.1
- For answers based on retrieved documents, pair a low temperature with retrieval, a prompt restricting answers to the supplied context, and source information. Low temperature alone does not ground an answer. section 4.5.4 section 2.2.1
import anthropic
client = anthropic.Anthropic()
response = client.messages.create(
model="claude-sonnet-4-6",
max_tokens=1024,
temperature=0.3, # Claude uses 0-1 range
messages=[
{"role": "user", "content": "What are 10 unique things to do at the
grocery store?"}
]
)
print(response.content[0].text)
This Claude API call sets temperature to 0.3 within the provider’s 0–1 range for a grocery-store ideas prompt. section 2.2.1
Do not equate temperature zero with factual reliability. A predictable answer can be consistently wrong, and setting temperature to zero does not reliably reduce hallucinations. When facts must be grounded, use techniques such as retrieval-augmented generation or tool use alongside sampling choices. section 2.2.1
















