Temperature and top-p are sampling parameters that control how a language model picks each next token from its list of possible continuations. Temperature reshapes the probabilities (low values make the most likely token dominate; high values flatten the odds), while top-p cuts the list down to the smallest set of tokens whose combined probability reaches a threshold. Neither adds knowledge or reasoning, and on many of the newest models from Anthropic, OpenAI and Google they are no longer adjustable at all.
That last point changes how this topic should be approached in 2026. Below you will find how the two parameters work, a worked numeric example, which current models still accept them, practical starting values for models that do, and what to use instead when they are gone.
How a model chooses the next token
A language model generates text one token at a time, and at every step it produces a score for every token in its vocabulary. A token is a chunk of text, often a word or part of a word (see how tokenization works). The raw scores, called logits, are turned into probabilities that add up to 100% using a function called softmax. The model then samples: it picks one token at random, weighted by those probabilities.
Sampling parameters sit between the probabilities and the random pick. Temperature changes the shape of the distribution; top-p and its sibling top-k change which tokens are allowed to be picked at all. Always choosing the single most probable token is called greedy decoding.
What temperature does
Temperature divides the logits by a number before softmax is applied. Dividing by a value below 1 stretches the gaps between scores, so the top token becomes even more likely. Dividing by a value above 1 shrinks the gaps, so less likely tokens get a bigger share. A temperature of 1 leaves the model’s distribution as it is.
Worked example with four candidate tokens
Imagine the model is completing “The sky today is” and, to keep the math simple, only four tokens are in play with illustrative logits of 3, 2, 1 and 0. Applying softmax at different temperatures gives these probabilities (computed directly from the formula, rounded):
| Token | Logit | T = 0.2 | T = 0.5 | T = 1.0 | T = 1.5 |
|---|---|---|---|---|---|
| blue | 3 | 99.3% | 86.5% | 64.4% | 52.3% |
| clear | 2 | 0.7% | 11.7% | 23.7% | 26.8% |
| grey | 1 | ~0% | 1.6% | 8.7% | 13.8% |
| falling | 0 | ~0% | 0.2% | 3.2% | 7.1% |
At 0.2 the model almost always says “blue”. At 1.5, “falling” (a strange continuation) has a 7% chance at every opportunity. Over a 500-token answer, those small odds add up, which is why high temperatures can drift into incoherent text: one odd token changes the context for every token after it.
Temperature 0 is treated as greedy decoding by most APIs. It makes output much more repeatable, but providers do not promise identical results. Anthropic’s Opus 5.5 migration guide states that temperature 0 never guaranteed identical outputs, and small numerical differences on server hardware can still change a token, after which the rest of the answer diverges.
What top-p (nucleus sampling) does
Top-p, also called nucleus sampling, removes the long tail of unlikely tokens before the random pick. The model sorts tokens from most to least likely, keeps adding them until their probabilities sum to at least the top-p value, discards the rest and renormalizes. Google’s Gemini documentation describes it in exactly those terms and lists 0.95 as its default.
Using the T = 1.0 column above:
- top_p = 0.8: “blue” (64.4%) plus “clear” (23.7%) reaches 88.1%, so only those two survive. “grey” and “falling” can never be picked.
- top_p = 0.95: “blue”, “clear” and “grey” reach 96.8%; “falling” is cut.
- top_p = 1.0: nothing is cut.
The advantage of top-p over a fixed cut-off is that it adapts. When the model is confident, the nucleus may contain one or two tokens; when many continuations are plausible, it widens automatically.
Top-k, for completeness
Top-k keeps only the k most probable tokens regardless of their probabilities. A top-k of 1 is greedy decoding. Gemini’s docs explain that it applies top-k first, then top-p, then picks the final token with temperature sampling. OpenAI’s Chat Completions API does not expose top-k.
Change one parameter, not both
OpenAI’s API reference describes top_p as an alternative to temperature and recommends altering one or the other but not both. The practical reason is diagnostic: if you lower temperature and top-p at the same time and output gets worse, you cannot tell which change caused it. Their effects also overlap, since both reduce the influence of unlikely tokens. Pick one dial (temperature is the more common choice), leave the other at its default, and test.
Which current models still accept these parameters
Many current flagship models no longer let you set temperature or top-p, because they spend part of each request on internal reasoning and the providers control sampling themselves. Sending the parameters can produce an error, a warning or be silently ignored, depending on provider. The table summarizes official documentation as of October 2026; check the linked pages before relying on it.
| Provider | Current guidance | What to use instead |
|---|---|---|
| Anthropic | Opus 5.5 migration guide: omit temperature, top_p and top_k. On Opus 5 and Sonnet 5, sampling parameters return a 400 error. | Prompting and the effort setting |
| OpenAI | GPT-6 guide: when reasoning effort is anything other than none, remove temperature, top_p and top_logprobs. Some GPT-6 models do not support none at all. | Reasoning effort, prompting, structured outputs |
Gemini 4 and Gemini 3.6+ ignore custom temperature, top_p and top_k and return deprecation warnings; earlier Gemini 3 models should keep defaults to avoid degraded reasoning. | Prompting and thinking settings |
The parameters still matter for older API models that remain available, for many open-weight models you run yourself, and for local inference tools. If you are working with current reasoning models, the related controls are compared in reasoning effort parameters across Claude, OpenAI and Gemini.
Starting values for models that still accept them
There is no universally correct temperature; the right value depends on the model and the task, and the only reliable way to choose is to compare outputs on your own inputs. These ranges are reasonable starting points, not tested optima:
| Task | Starting temperature | Why |
|---|---|---|
| Extraction, classification, structured JSON | 0 to 0.2 | There is one correct answer; variety only adds error |
| Code generation and SQL | 0 to 0.3 | Unusual tokens are more likely to be bugs than ideas |
| Summaries and Q&A over documents | 0.2 to 0.5 | Some freedom in phrasing, little room for invention |
| Marketing copy, email drafts | 0.6 to 0.9 | Natural variety without losing the thread |
| Brainstorming, naming, fiction | 0.8 to 1.0+ | You want options you would not think of, and you will filter them |
How to pick a value for your own prompt
Choosing a temperature is a small experiment, and it only takes a few steps to do properly:
- Collect 10 to 20 real inputs, including at least a few awkward ones.
- Run each input three times at two or three candidate values (for example 0.2, 0.5 and 0.8), keeping everything else fixed.
- Score the outputs with the same rubric each time: correct, format respected, tone acceptable. A reusable rubric is described in this LLM eval rubric guide.
- Look at two things: average quality and how much the three runs of the same input disagree. For production tasks, low disagreement often matters more than a slightly higher best case.
- Pick the lowest value that gives acceptable variety, write it down next to the prompt version, and retest when you change models.
Ranges differ by provider: OpenAI’s Chat Completions API accepts temperature from 0 to 2, while Anthropic’s older models used 0 to 1. A value of 0.8 is therefore not the same “amount” of randomness everywhere.
Getting consistency without temperature
When temperature is unavailable, or when temperature 0 still gives answers that vary too much, the fix is to constrain the task rather than the sampler. Anthropic’s migration guide makes the same recommendation: guide behavior with prompting. Techniques that do this well:
- Fix the output format. A schema leaves far fewer places for variation than free text. See getting structured JSON output.
- Give a closed set of answers. “Answer with one of: approve, reject, escalate” is more stable than “decide what to do”.
- Show examples. Two or three demonstrations of the exact output pin down tone and length.
- Ask for one option, not “some ideas”. Open-ended requests produce open-ended variety.
- Run multiple times and vote when correctness matters, as in self-consistency prompting; variation becomes a signal rather than a problem.
Before and after: replacing temperature with instructions
An illustrative case: a team previously ran a product-review tagger at temperature 0 and moved to a model that rejects the parameter. The old prompt relied on the sampler for stability:
Read this review and tell me what the customer thinks about the product.
The revised prompt makes the output stable through constraints instead:
Classify the product review below.
Return JSON only, with exactly these keys:
- "sentiment": one of "positive", "negative", "mixed"
- "topics": array using only these values: "price", "quality",
"shipping", "support", "usability" (empty array if none apply)
- "quote": the shortest exact sentence from the review that
supports the sentiment
If the review is not about the product, return
{"sentiment": "mixed", "topics": [], "quote": ""}.
<review>
{{review_text}}
</review>
Each part removes a source of variation: a closed label set for sentiment, a fixed vocabulary for topics, an exact quote instead of a paraphrase, and a defined answer for the edge case. A sampler setting can only make the model prefer its most likely wording; these constraints decide what the wording is allowed to be.
Common misconceptions
- “Higher temperature makes the model more creative or smarter.” It only makes less likely tokens more likely. Sometimes that produces a fresh phrase; often it produces errors. It does not add knowledge.
- “Temperature 0 stops hallucinations.” A model can be confidently and repeatably wrong. Grounding the model in source documents and verifying its claims address hallucination; sampling settings do not.
- “Temperature 0 means identical output every time.” Providers do not guarantee this.
- “Settings transfer between providers.” Ranges, defaults and support differ, and many current models ignore or reject these values entirely.



