AI

LLM Temperature and Top-P Explained Simply

LLM temperature controls how random a model's answers are. See how temperature, top-p and top-k work, what temperature 0 does, and which settings to use.

By OmniAI Editorial · Nov 20, 2026 · 9 min read

LLM temperature is a setting that controls how predictable or varied a language model's answers are. At a low temperature, the model almost always picks its most likely next word, so answers are focused and repeatable. At a high temperature, it takes more chances on less likely words, so answers become more varied and creative, and eventually random. Top-p and top-k are related settings that limit which words the model is allowed to pick from at all.

This guide explains how these settings work with a simple numeric example, what temperature 0 really means, how temperature compares with top-p, which values to use for different tasks, and why some newer APIs no longer let you change them.

What Is LLM Temperature?

A language model writes one token at a time. A token is a word or part of a word; our guide to LLM tokens explains them. For each step, the model doesn't produce one answer. It produces a score for every possible next token, which turns into a list of probabilities: maybe 60% "blue", 25% "grey", 15% "green".

The model then samples from that list, like drawing from a weighted lottery. Temperature changes the weights before the draw:

  • Low temperature sharpens the list. The favourite gets even more likely, and the long shots almost disappear.
  • Temperature 1 leaves the probabilities as the model produced them.
  • High temperature flattens the list. The favourite loses some of its lead, and unlikely tokens get a real chance.

That's all temperature does. It doesn't make the model smarter or more knowledgeable. It only changes how adventurous the model is when choosing among words it already considered.

How Temperature Works: A Simple Example

Under the hood, the model's raw scores (called logits) are divided by the temperature, then converted into probabilities with a function called softmax.

Say the model is finishing the sentence "The sky is" and scores three candidate words: "blue" 2.0, "grey" 1.0, "green" 0.5.

Temperature"blue""grey""green"
0.5 (low)84%11%4%
1.0 (neutral)63%23%14%
2.0 (high)48%29%23%

At 0.5, "blue" wins almost every time. At 2.0, "green" shows up nearly a quarter of the time. Over a long answer, those small choices add up: low temperature gives safe, consistent text, while high temperature gives more surprising text that is also more likely to drift off-topic or make mistakes.

Three groups of three grey bars side by side: the left group with one very tall bar, the middle group more even, the right group nearly flat, with the tallest bar of the left group in orange.
Low temperature sharpens the odds; high temperature flattens them.

Temperature 0 vs 1: What Changes?

Temperature 0 is a special case. Dividing by zero isn't possible, so providers treat it as "always take the single most likely token." This is called greedy decoding. It's the most predictable setting, and a good choice for tasks with one right answer, such as extracting data, classifying text or writing code.

One surprise: temperature 0 doesn't guarantee identical answers every time. Large models run on GPUs that process many requests together, and tiny floating-point differences can change which token comes out on top when two options are nearly tied. Expect answers that are very similar, not byte-for-byte identical. If you need exact repeatability, store the output instead of regenerating it.

Temperature 1 is the model's natural distribution and the default in many APIs. It gives a good balance for conversation.

Above 1 answers get noticeably more varied. The LLM temperature range depends on the provider: OpenAI's Chat Completions API accepts values between 0 and 2, while some tools use 0 to 1. OpenAI's documentation describes 0.8 as more random and 0.2 as more focused and deterministic. Very high values often produce rambling or nonsense.

What Is Top-P (Nucleus Sampling)?

Top-p, also called nucleus sampling, takes a different approach. Instead of reshaping the probabilities, it cuts off the unlikely tail.

The model sorts tokens from most to least likely and keeps only the smallest group whose probabilities add up to p. Then it samples from that group.

Using the temperature-1 numbers above, with top-p set to 0.8:

  • "blue" (63%) alone isn't enough to reach 80%.
  • "blue" + "grey" = 86%, which passes 80%.
  • So "green" is removed, and the model picks between "blue" and "grey" only.

A top-p of 1.0 keeps everything. A top-p of 0.1 keeps only the tokens that make up the top 10% of probability, which is often just one or two. The nice thing about top-p is that it adapts: when the model is confident, the nucleus is tiny; when many words fit, it stays wide.

Top-K and Min-P

Two more sampling settings appear in local model tools and some APIs.

  • Top-k keeps only the k most likely tokens, whatever their probabilities. Top-k 1 is the same as greedy decoding. Top-k 40 means "choose among the 40 best options."
  • Min-p keeps tokens whose probability is at least a set fraction of the top token's probability. With min-p 0.05 and a top token at 90%, anything below 4.5% is dropped.

If you run models locally with Ollama, its documented defaults are temperature 0.8, top-k 40 and top-p 0.9, with min-p off (0.0). Tools such as llama.cpp, LM Studio and vLLM expose similar settings.

A row of grey vertical bars sorted from tallest to shortest, with an ink bracket over the first three bars and the tallest bar in orange.
Top-p keeps only the most likely tokens until their probabilities add up to the cut-off.

LLM Temperature vs Top P: Which Should You Change?

Both settings control randomness, so changing both at once makes behaviour hard to predict. OpenAI's API documentation says it generally recommends altering temperature or top-p, but not both.

A simple way to think about temperature vs top-p:

  • Temperature turns the overall "creativity" dial up or down.
  • Top-p removes the long tail of odd choices, which keeps text sensible even at higher temperatures.

In practice, most people adjust temperature and leave top-p at its default. Change top-p only if you see occasional strange words creeping in and want to clip them without making everything else more rigid.

There's no official best value; these are common starting points to test on your own prompts:

TaskStarting temperature
Data extraction, classification, JSON output0 to 0.2
Coding and maths0 to 0.3
Answering from documents (RAG), factual Q&A0 to 0.5
General chat and writing help0.5 to 0.8
Brainstorming, fiction, marketing ideas0.8 to 1.2

Two tips:

  1. Lower temperature doesn't fix wrong facts. If the model doesn't know something, a low temperature makes it consistently wrong rather than randomly wrong.
  2. For structured output, use the right tool. Low temperature helps, but schema-enforced output is far more reliable; see our guide to LLM JSON output.

Why Some APIs No Longer Let You Change Temperature

A growing number of models don't expose these dials at all.

  • Reasoning models often accept only the default. Developers have reported errors such as "Unsupported parameter: 'temperature'" when sending it to some of OpenAI's reasoning models.
  • Anthropic removed them from its API. In Claude API version 2026-10-21, the temperature, top_p and top_k request parameters are removed, and a request that sends any of them returns an error on every model.

The reasoning is that modern models are tuned to work best at their default sampling, and the dials mostly let people make results worse by accident. So how do you control behaviour without them?

  • Say what you want in the prompt. "Give one concise answer" or "List ten very different ideas" steers variety more precisely than a number. Our prompt engineering guide covers techniques.
  • Use examples. Showing the style you want narrows the output more than a low temperature.
  • Use structured outputs for data you need in a fixed format.
  • Generate several answers and pick one when you want variety, or check them against each other when you want reliability.

Temperature and top-p still matter for open models you run yourself and for many APIs, so it's worth understanding them. Just don't build a system that depends on fine-tuning a dial your provider might remove.

FAQ

What does temperature do in an LLM?

Temperature controls how random the model's word choices are. Low values make it pick the most likely words, giving focused and consistent answers. High values give less likely words more chance, making answers more varied and creative but also more error-prone.

What is the best LLM temperature?

It depends on the task. Use 0 to 0.3 for code, data extraction and factual answers, around 0.5 to 0.8 for general chat and writing, and 0.8 or higher for brainstorming and creative work. Test on your own prompts, because models respond differently.

Does temperature 0 make an LLM deterministic?

Not completely. Temperature 0 makes the model pick the most likely token at each step, so answers become very consistent. But hardware and batching effects can still cause small differences between runs, especially in long answers.

What is the difference between temperature and top-p?

Temperature reshapes the probabilities of all possible next tokens, making the favourite more or less dominant. Top-p removes unlikely tokens by keeping only the most probable ones that add up to a set share, such as 90%. Most guides recommend changing one, usually temperature, and leaving the other at its default.

Top K vs Top P: what's the difference?

Top k keeps a fixed number of the most likely next tokens, such as the best 40, no matter how probable they are. Top p keeps a variable number: just enough of the most likely tokens to add up to a set share of probability, such as 90%. Top p adapts to how confident the model is, which is why many APIs offer it instead of top k. Ollama uses top k 40 and top p 0.9 by default.

All articles

Read next

Language

EnglishEnglish · en TürkçeTurkish · tr DeutschGerman · de العربيةArabic · ar

Account

Enter your email. We’ll send you a sign-in link and a 6-digit code. No password needed.

Sign in

Theme

Language

Show our email address

To keep spam out of our inbox, please confirm your own email first. We will send you a 6-digit code.

We send codes only to these providers: gmail.com, googlemail.com, outlook.com, hotmail.com, live.com, msn.com, proton.me, protonmail.com, pm.me, icloud.com, me.com, mac.com, yahoo.com, aol.com, gmx.de, gmx.net, web.de, t-online.de, yandex.com, omniai.blog