GENERATIVE AI / SAMPLING / FIELD GUIDEscores → probabilities → token
Back to field guides

FIELD GUIDE 06

LLM Temperature:
What It Does, With Examples

A sampling control, not a truth meter.

Short answerLow temperature sharpens the next-token odds; high temperature flattens them. It never makes answers more accurate.
Hand turning a round analog dial on a wall at home, warm light
Temperature is a dial for how adventurous the next-token pick is, not for how correct it is.
Updated October 12, 2026Beginner-first / source-linked / no hype

00 Short answer

The quick
version.

Short answer: LLM temperature is a setting that changes how a language model picks its next token. The model scores every possible next token; temperature divides those scores before they are turned into probabilities. A low temperature sharpens the distribution, so the top choice wins almost every time and output is focused and repetitive. A high temperature flattens it, so less likely tokens get picked more often and output becomes more varied, and also more likely to drift. Temperature does not add knowledge or make answers more accurate.

01 Start here

What is temperature in an LLM?

A large language model writes one token at a time. At every step it produces a score, called a logit, for each token in its vocabulary. A decoding step then turns those scores into probabilities and selects the next token.

Temperature sits in that decoding step. It is a request-level setting: it doesn’t retrain the model, change its weights or give it new information. It only changes how concentrated or spread out the probabilities are when the model samples. If you want to see where those scores come from, the how a transformer works lesson walks through the forward pass.

Two practical consequences:

  • The same prompt can produce different answers at the same temperature, because sampling is random by design.
  • Every token is sampled with the same temperature, so a small change compounds over a long answer. The longer the output (and the fuller the context window), the more chances there are for a low-probability token to send the text somewhere new.

02 The math

The LLM temperature formula (softmax with temperature)

Logits become probabilities through the softmax function. Temperature T divides every logit before softmax:

P(i)=exp⁡(zi/T)∑jexp⁡(zj/T)

In plain text: P(token i) = exp(z_i / T) / Σ_j exp(z_j / T), where z_i is the logit of token i and T > 0.

What happens as T changes:

  • T = 1: the logits are used as they are. This is the model’s “native” distribution.
  • T < 1: dividing by a number below 1 stretches the gaps between scores, so the top token takes a bigger share.
  • T > 1: the gaps shrink, so the distribution becomes flatter and unlikely tokens get more probability.
  • T → 0: the top token’s probability approaches 100%. Many implementations treat a temperature of 0 as “always pick the most likely token” (greedy decoding), because dividing by zero is undefined.

Temperature never changes the ranking of tokens. The most likely token stays the most likely; only the size of its lead changes. If two tokens have equal scores, they stay equally likely at any temperature.

This is a simplified view. Real serving stacks may combine temperature with other rules (top-p, top-k, penalties), and some APIs restrict or ignore the parameter for certain models.

03 Worked example

Worked example: low vs high temperature

The numbers below are illustrative. They are made-up logits for three candidate next words after the prompt “The sky is”, not output from a real model. A real model scores tens of thousands of tokens at every step.

Candidate Logit P at T = 0.2 P at T = 0.5 P at T = 1.0 P at T = 1.5
“blue” 2.0 99.3% 84.4% 62.9% 53.2%
“clear” 1.0 0.7% 11.4% 23.1% 27.3%
“falling” 0.5 0.1% 4.2% 14.0% 19.6%

How to read it:

  • At T = 0.2, “blue” is picked about 99 times in 100. Run the prompt ten times and you’ll almost always get the same sentence.
  • At T = 1.0, “blue” still leads, but roughly one run in three picks something else.
  • At T = 1.5, the odd choice (“falling”) shows up about one time in five. That might be a creative spark in a poem and a derailment in a support answer.

You can check any column yourself: divide each logit by T, take exp() of each result, then divide each by their sum.

Pair of dice mid-roll above a wooden table, soft daylight
Sampling is a weighted roll. Temperature changes the weights, not the fact that it’s a roll.

↻ Try it live

Watch the odds
move.

This tiny demonstration uses three fictional token scores. It is not a model benchmark.

A toy next-token distribution

sharperflatter
  • candidate A—
  • candidate B—
  • candidate C—

Loading the toy distribution…

The same three made-up scores stay fixed; only temperature changes. A real model has many candidate tokens and different scores at every step.

At lower temperatures, the leading candidate dominates more of this toy distribution. Raising the temperature gives the alternatives more room. Sampling still means a token is selected from the distribution; a higher probability is not a guarantee that a particular token will be chosen.

04 Cut the tail

Top-p sampling (nucleus sampling)

Top-p sampling, also called nucleus sampling, takes a different approach. Instead of reshaping the probabilities, it cuts off the tail. The model sorts tokens from most to least likely, keeps the smallest set whose probabilities add up to at least p, renormalizes that set, and samples only from it.

Using the T = 1.0 column above with top_p = 0.8: “blue” (62.9%) alone isn’t enough, so “clear” is added (62.9 + 23.1 = 86% ≥ 80%). “falling” is dropped entirely. The model then samples between “blue” and “clear” only.

Why it’s useful: the size of the kept set adapts. When the model is confident, the nucleus may be one or two tokens; when it’s unsure, many tokens fit inside the same p. OpenAI’s API reference describes top_p as “an alternative to sampling with temperature”, with 0.1 meaning only the tokens in the top 10% of probability mass are considered.

Top-k is the blunter cousin: keep the k most likely tokens, whatever their probabilities, and sample among them.

05 Compare controls

Temperature vs top-p vs top-k

Temperature Top-p (nucleus) Top-k
What it changes The shape of the whole distribution Which tokens are allowed (by cumulative probability) Which tokens are allowed (by count)
How it works Divides logits by T before softmax Keeps the smallest set reaching probability mass p Keeps the k highest-probability tokens
Lower value means Sharper, more predictable output Smaller candidate pool, safer choices Fewer candidates, safer choices
Higher value means Flatter, more varied output Larger pool, more variety More candidates, more variety
Adapts to model confidence? No, it scales every step the same way Yes, pool size varies per step No, pool size is fixed
Typical availability Very common across APIs Common Some APIs only; some models reject it

The controls can be combined: for example, Google’s Gemini API documentation says Gemini models use top-p (nucleus) sampling or a combination of top-k and nucleus sampling. OpenAI’s reference says it generally recommends altering temperature or top_p, but not both. Changing one control at a time also makes your experiments easier to interpret.

06 Check the docs

Vendor ranges and defaults (as documented)

Numeric scales are not universal. A “0.7” on one API is not necessarily the same as “0.7” on another. From the vendor references we checked on 2026-10-10:

API Documented temperature range Default / notes
OpenAI Responses API 0 to 2 Example values in the docs: 0.8 = more random, 0.2 = more focused and deterministic. Recommends altering temperature or top_p, not both.
Anthropic Messages API 0.0 to 1.0 Defaults to 1.0. Suggests closer to 0.0 for analytical / multiple-choice tasks and closer to 1.0 for creative tasks; notes that 0.0 is still not fully deterministic. The parameter is marked deprecated: models released after Claude Opus 4.6 only accept 1.0.
Google Gemini API 0.0 to 2.0 The default varies by model (reported by the model’s metadata). Default top-p also varies by model.

Always check the page for the exact model and endpoint you call. Some newer models restrict or drop the parameter.

08 Keep the boundary clear

What temperature does not do

  • It doesn’t make answers true. OpenAI’s prompt-engineering guidance separates temperature from truthfulness: higher values make output more random, not more accurate. A focused answer can still be wrong.
  • It doesn’t guarantee repeatability. Even at 0, Anthropic’s docs note results are not fully deterministic. Model updates and serving differences can change output too.
  • It doesn’t change what the model knows or how much text it can read at once. That’s the context window.
  • It isn’t a safety filter. Low temperature won’t stop a model from following injected instructions. See indirect prompt injection.
Person at a desk typing on a laptop with the screen turned away, notebook and coffee nearby
Pick the setting for the task, then test it on real examples.

FAQ Temperature / quick answers

Questions,
answered.

Short explanations with the limits left visible.

· informational guide

01 / answerWhat is temperature in an LLM?

Temperature is a decoding setting that controls how random the model’s next-token choice is. It divides the model’s token scores (logits) before softmax: lower values make the top token dominate, and higher values spread probability to less likely tokens.

02 / answerWhat does LLM temperature 0 mean?

Many implementations treat temperature 0 as greedy decoding: always pick the most likely token. It makes output much more consistent, but vendors such as Anthropic note it is still not fully deterministic.

03 / answerIs a higher temperature better?

Only for tasks that benefit from variety, such as brainstorming or fiction. For extraction, code or factual answers, lower values are a more common starting point. Higher temperature doesn’t make a model smarter or more accurate.

04 / answerWhat is the formula for LLM temperature?

P(i) = exp(z_i / T) / Σ_j exp(z_j / T), where z_i is the logit for token i and T is the temperature. It’s the softmax function with every logit divided by T.

05 / answerWhat is top-p sampling?

Top-p (nucleus) sampling keeps only the smallest set of most likely tokens whose probabilities add up to at least p, then samples from that set. With top_p = 0.1, only tokens in the top 10% of probability mass are considered.

06 / answerShould I change temperature and top-p together?

OpenAI recommends altering one or the other, not both. Changing one control at a time also makes it easier to see which setting caused a difference.

07 / answerWhat temperature range can I use?

It depends on the API. OpenAI documents 0 to 2, Google’s Gemini API documents 0.0 to 2.0, and Anthropic documents 0.0 to 1.0 (with newer Claude models only accepting the default). Check the docs for your exact model.

Sources Official API / technical docs

Read the
model docs.

Vendor references checked on 2026-10-10. Parameter behavior is model- and interface-specific; check the page for the exact model and endpoint you call.

↗keep exploring

More explainAI
field guides.