Temperature
Temperature is a scalar Hyperparameter that controls how sharply or flatly a language model's probability distribution is peaked before a token is sampled. Mathematically it divides the raw logits by the temperature value before the Softmax function converts them to probabilities: a value below 1.0 sharpens the distribution so the most likely tokens dominate, while a value above 1.0 flattens it so lower-probability tokens become more competitive. Setting temperature to 0 makes sampling deterministic — the model always picks the single highest-probability token.
Think of it like the heat on a wax seal. Cool wax (low temperature) holds its shape rigidly and produces the same crisp impression every time. Hot, fluid wax (high temperature) spreads unpredictably, creating unique but harder-to-control results.
import anthropic
client = anthropic.Anthropic()
# Precise, factual response
factual = client.messages.create(model="claude-opus-4-5", max_tokens=256,
temperature=0.1,
messages=[{"role":"user","content":"What is the boiling point of water at sea level?"}])
# Creative brainstorm
creative = client.messages.create(model="claude-opus-4-5", max_tokens=256,
temperature=1.0,
messages=[{"role":"user","content":"Give me five unusual names for a detective agency."}])
Temperature is often paired with top-p (nucleus) sampling, and both sit alongside Prompt Engineering and Context Window management as the main runtime controls over generation behaviour. Raising temperature too high can amplify Hallucination because improbable — and potentially incorrect — tokens become more likely to be sampled. Inference frameworks expose temperature as a first-class API parameter precisely because the right value is task-dependent rather than universal.
You will encounter temperature every time you call a generation API or configure a chat product: code generation tasks favour values near 0, while creative writing or brainstorming tools typically use 0.7–1.2.