Skip to main content

Sampling Parameters: Which Controls Models Lock

Top-k, top-p, temperature and presence penalty explained, with a table of which controls Claude, GPT-6 and Gemini lock, our own test and Ollama defaults.

FHFinn Hillebrandt
Last updated:
Basics
Sampling Parameters: Which Controls Models Lock

Sampling parameters such as temperature, top-p and top-k control how a language model picks one word from the possible next words. They decide whether answers come out consistent and predictable or varied and surprising. Penalties additionally dampen repetition.

Think of loaded dice. The model rolls the dice for every word, and the parameters change the dice. With a low temperature, the same side almost always comes up. With a high one, all sides are close together. Take the sentence start "The sky is" as an example. With a low temperature, "blue" follows almost surely, and with a high one sometimes "red" does.

You set these controls when you use a model through an API or a playground. In ChatGPT and Claude.ai you steer the same thing through the instruction, more on that in the second to last section. And even at temperature 0 with a fixed seed, a model at a fixed provider gave 3 to 4 different answers in 20 requests. On some current models the controls are even locked: Claude Opus 5.5 rejects temperature, top-p and top-k with error 400, GPT-6 accepts them only without reasoning, and Gemini from 3.6 Flash silently ignores them. The overview is in section 6.

1. How a model picks the next word

A language model computes a probability for every possible next token. Then one is drawn from these candidates, and this is where the parameters step in. In many implementations the steps run in this order, though details differ between software.

  1. Penalties change the scores of tokens that already appeared in the text.
  2. Temperature flattens or sharpens the distribution.
  3. Top-K, top-p or min-p remove unlikely candidates.
  4. One of the remaining candidates is drawn at random, weighted by its probability.

Which of these steps matters how much is easiest to see in numbers. The example starts with temperature, the most important control.

2. Temperature: why the same question sounds tame or wild

The worked example uses four candidates for the word after "The sky is". The starting scores are made up, while the math behind the bars is real. Temperature divides the raw scores of the candidates (logits) before the softmax function turns them into probabilities, so p = softmax(z / T). A value below 1 sharpens the distribution, a value above 1 flattens it.

Temperature 0.2
blue99.3 %
gray0.7 %
clear0 %
red0 %
Temperature 1
blue64.4 %
gray23.7 %
clear8.7 %
red3.2 %
Temperature 2
blue45.5 %
gray27.6 %
clear16.7 %
red10.2 %
A worked example with made-up starting scores. At 0.2, "blue" wins almost surely, at 2 every candidate is in the race.

These ranges work as starting values, not as a fixed rule. The ideal setting depends on the model. In OpenAI's chat API, temperature runs from 0 to 2, and if you set nothing you get 1. Google's Gemini API also allows 0 to 2, with a default that depends on the model.

Facts, extraction, code
Temperature
0 to 0.3
Note
Consistent answers matter more than variety.
General text, chat
Temperature
about 0.7
Note
A good balance of natural wording and reliability.
Creative writing, brainstorming
Temperature
0.9 to 1.2
Note
More variety, but more outliers. Values above 1.5 are rarely useful.
Practical starting values, not provider rules

The control shows, as an example, how one sentence changes at different values. Pick a value and read the output below it.

Prompt: “Describe a sunset in one sentence.”

Choose a value

Invented example outputs. Real measurements are in this entry’s own test.

In the API, temperature is a parameter of the call. With OpenAI’s current GPT-6 models this only works with reasoning switched off (effort “none”), which GPT-6 Astra, GPT-6.1 Sol and GPT-6.2 do not support. An example with GPT-6.1 Terra:

python
from openai import OpenAI

client = OpenAI()
response = client.responses.create(
    model="gpt-6.1-terra",
    reasoning={"effort": "none"},
    input="Summarize the text in three sentences.",
    temperature=0.2,
)

Temperature changes all probabilities at once. The next three controls work differently and drop unlikely candidates altogether.

3. Top-P, top-K and min-P

These three controls remove unlikely candidates before the draw. The remaining probabilities are then scaled back up to 100%.

  • Top-K keeps the K most probable words. The number is fixed, no matter how sure the model is.
  • Top-P (nucleus sampling, Holtzman et al., 2019) keeps the smallest group of words whose probabilities add up to at least P. At P = 0.9, words stay until together they cover 90%. When the model is sure, that is few words. When it is unsure, it is more.
  • Min-P (Nguyen et al., 2024) keeps every word whose probability reaches at least a fixed fraction of the top candidate's probability. The threshold therefore moves with the model's confidence. You mostly find min-p in locally run models. Hugging Face names 0.01 to 0.2 as typical values.

If top-k and top-p are both set, the two filters apply one after the other, and only what passes both remains. In Hugging Face's Transformers library, top-k defaults to 50 when the model itself sets nothing. Top-p defaults to 1.0 there and so filters nothing. Top-k 1 is a special case, because only the most probable candidate is left.

Here are the three filters applied to the same example at temperature 1. Struck-through words are removed, and the remaining values are recalculated.

Top-K = 2
blue73.1 %
gray26.9 %
clear0 %
red0 %
Top-P = 0.9
blue66.5 %
gray24.5 %
clear9 %
red0 %
Min-P = 0.1
blue66.5 %
gray24.5 %
clear9 %
red0 %
Worked example with invented starting scores. Top-P 0.9 keeps three words, because 'blue' and 'gray' only reach 88% together.

The usual advice is to change only one of the controls, either temperature or top-p. If you adjust both, you can no longer tell which one caused a change. The sliders below show the effect of top-p and top-k on made-up examples.

Prompt: “Explain why the sky is blue.”

Choose a value

Invented example outputs. Real measurements are in this entry’s own test.

Prompt: “Name three fruits.”

Choose a value

Invented example outputs. Real measurements are in this entry’s own test.

3.1 Default values in llama.cpp and Ollama

If you run models locally, you get the runtime's presets unless you set something yourself. They differ, and Ollama applies top-k and top-p even though you specified nothing:

temperature
llama.cpp
0.8
Ollama
0.8
top_k
llama.cpp
40
Ollama
40
top_p
llama.cpp
0.95
Ollama
0.9
min_p
llama.cpp
0.05
Ollama
0 (off)
repeat_penalty
llama.cpp
1.0 (off)
Ollama
1.0 (off)
repeat_last_n
llama.cpp
64
Ollama
64
Source code and docs, 9 Nov 2026

In one place the llama.cpp server documentation gives 1.1 for repeat_penalty, while the source code and the command-line help give 1.0. The source code is what counts here. Individual models can ship their own values in an Ollama Modelfile, which override this preset.

Filters and temperature decide how widely the model spreads its choices. If it still repeats itself, you need another lever.

4. Frequency penalty, presence penalty and repeat_penalty

Penalties lower the scores of tokens that already appeared in the text, usually before temperature is applied.

  • Frequency penalty penalizes a token more the more often it already appeared. High values near 2 cut repetition but can sound stilted.
  • Presence penalty penalizes a token simply for having appeared at all, regardless of how often. The model then tends to pick up new topics. At OpenAI, both penalties range from −2 to 2, with a default of 0.
  • repeat_penalty is the counterpart in locally run models, for example in llama.cpp. There, 1.0 means no penalty and larger values dampen repetition.

Negative values flip the effect and reward repetition. Google warns in its Gemini reference that strongly negative frequency penalty values make the model repeat a common token until it hits the output limit. Here too, change only one of the two penalty controls. The sliders show the effect on made-up sample texts.

Prompt: “Write a short text about dogs.”

Choose a value

Invented example outputs. Real measurements are in this entry’s own test.

Prompt: “Tell me something about traveling.”

Choose a value

Invented example outputs. Real measurements are in this entry’s own test.

With the right controls you get consistent answers. Or do you?

5. Why temperature 0 is not always the same

At temperature 0, the model picks the most probable word every time. Still, the same request can return two different answers. A test run by gradually.ai shows this.

On November 7, 2026, gradually.ai gave two models the same task through OpenRouter. It read “Describe a sunset in one sentence.” The models were DeepSeek V4.1 Flash with reasoning disabled and Llama 3.1 8B Instruct, three times each at temperature 0, 0.7 and 1.5. Every request ran exactly once, with no retries.

DeepSeek V4.1 Flash
Temperature
0.0
Different answers
3 of 3
Different servers
3 of 3
DeepSeek V4.1 Flash
Temperature
0.7
Different answers
3 of 3
Different servers
3 of 3
DeepSeek V4.1 Flash
Temperature
1.5
Different answers
3 of 3
Different servers
1 of 3
Llama 3.1 8B Instruct
Temperature
0.0
Different answers
2 of 3
Different servers
1 of 3
Llama 3.1 8B Instruct
Temperature
0.7
Different answers
3 of 3
Different servers
1 of 3
Llama 3.1 8B Instruct
Temperature
1.5
Different answers
3 of 3
Different servers
2 of 3
gradually.ai test, November 7, 2026
gradually.ai

DeepSeek V4.1 Flash returned three different sentences at temperature 0. All three start the same way and then drift apart.

Answers from DeepSeek V4.1 Flash, temperature 0
The sky bled into gold and crimson as the sun sank slowly beneath the horizon, painting the clouds in fleeting shades of fire.

The sky bled from gold to crimson as the sun sank slowly beneath the horizon, setting the clouds ablaze like embers in a dying fire.

The sky bled into a brilliant tapestry of orange and violet as the sun sank slowly beneath the horizon.

Llama 3.1 8B Instruct also returned two different sentences at temperature 0. In the English run, all three answers came from the same server, and one still differed.

At temperature 1.5, DeepSeek V4.1 Flash stayed readable, only the wording changed. Llama 3.1 8B Instruct kept its English answers mostly readable at 1.5, but one of them slid into word salad halfway through.

Answer from Llama 3.1 8B Instruct, temperature 1.5
A sunset unfolds as the sky transforms into a breathtaking tapestry of warm, fiery hues, swirling savoir strides of orange, pink, and purple lurking above the flat 많은 petals stitch sketch gesture calming water lens poetry […]

In the German version of the same test, all three answers from Llama 3.1 8B Instruct at 1.5 fell apart into word salad. Three requests per setting is a small sample. It is enough, though, to show that temperature 0 does not guarantee identical answers from a hosted model and that a small model can become unusable at a high temperature.

There are two reasons for the variation at temperature 0. The first is visible in the test. OpenRouter routes requests to different providers, and the three answers from DeepSeek V4.1 Flash at temperature 0 came from three different servers. Horace He and the team at Thinking Machines described the second reason in 2025. The compute kernels on the GPU are not batch-invariant, so their order of operations changes with the number of simultaneous requests on the server. Tiny rounding differences are enough for a different word to win when two words are almost equally likely.

For you, that means temperature 0 sharply lowers variation but does not guarantee repeatability. Some APIs also offer a seed parameter. It does not guarantee repeatability either, as the check below shows. If identical results matter, store the answers instead of regenerating them.

5.1 A check with a fixed provider

To rule out provider variation, gradually.ai repeated the test on November 9, 2026. Mistral Small 2603 ran through OpenRouter pinned to the provider Mistral with no fallback, and all 120 answers came from there. At temperature 0 there were 20 requests per language without and 20 with seed 42, and 5 requests per setting at 0.7 and 1.5. Counted are the distinct answer texts.

Temperature 0, no seed
German
4 different in 20, most common 10 times
English
4 different in 20, most common 16 times
Temperature 0, seed 42
German
3 different in 20, most common 11 times
English
4 different in 20, most common 14 times
Temperature 0.7, no seed
German
5 different in 5
English
5 different in 5
Temperature 0.7, seed 42
German
5 different in 5
English
3 different in 5
Temperature 1.5, no seed
German
5 different in 5, 2 with garbled words
English
5 different in 5
Temperature 1.5, seed 42
German
4 different in 5
English
4 different in 5
Own test, 9 Nov 2026

Even with one provider, temperature 0 and a fixed seed, the same request produced 3 to 4 different answers in 20 tries. The differences were small, the same opening and a different ending. Seed 42 changed nothing measurable. Server-side batching and hardware are likely causes, but that was not measured. The test covers one model with one prompt and says nothing about other models or providers.

Anyone who knows the controls often meets a different problem on new models. They cannot be set at all.

6. Locked settings on current models

On new models, you often cannot set these controls anymore. Anthropic requires you to omit temperature, top_p and top_k for Claude Opus 5.5. Behavior is steered through the prompt and the effort parameter. For OpenAI's GPT-6 models, temperature, top_p and top_logprobs must be removed whenever reasoning effort is anything other than none, and in the chat API logprobs as well. For GPT-6 Astra, GPT-6.1 Sol, GPT-6.2 Astra, and GPT-6.2 Sol that always applies, because they do not support none.

The overview shows the state of the documentation. Google takes a third route. From Gemini 3.6 Flash, the Gemini API silently ignores temperature, top-p and top-k. The call does not fail, the values just have no effect. Support changes from model to model, so check the docs every time you switch.

Temperature
Claude API
Claude Opus 5.5: omit, otherwise error 400
OpenAI API
GPT-6: only with effort none, never on GPT-6 Astra, GPT-6.1 Sol and GPT-6.2, range 0 to 2
Gemini API
Silently ignored from Gemini 3.6 Flash, otherwise 0 to 2
Top P
Claude API
Claude Opus 5.5: omit, otherwise error 400
OpenAI API
GPT-6: only with effort none, never on GPT-6 Astra, GPT-6.1 Sol and GPT-6.2
Gemini API
Silently ignored from Gemini 3.6 Flash
Top K
Claude API
Claude Opus 5.5: omit, otherwise error 400
OpenAI API
Not available
Gemini API
Silently ignored from Gemini 3.6 Flash
Frequency Penalty
Claude API
Not available
OpenAI API
In the chat API, −2 to 2, default 0
Gemini API
Listed as a field in the API reference
Presence Penalty
Claude API
Not available
OpenAI API
In the chat API, −2 to 2, default 0
Gemini API
Listed as a field, works as an on-off penalty
Provider docs, checked on Nov 7, 2026

What is left when a control is missing? The same as in the chat interfaces.

7. What you can do in ChatGPT and Claude.ai

In the chat interfaces of ChatGPT and Claude.ai you do not send API parameters. You steer the effect through the instruction.

  • For consistent answers: ask for brief, factual answers without embellishment and specify a fixed format.
  • For variety: ask for five distinct variants that clearly differ in tone, and pick the best.
  • For depth: with reasoning models, you steer effort through the thinking setting, not through temperature.

More on how to word instructions is in the entries on the prompt and the system prompt.

8. What this means for you

  • Change only one control at a time. Otherwise you will not know what caused the change.
  • Start with temperature. Top-p, top-k and the penalties are fine-tuning.
  • Read the model's docs. On new models the control may be locked, and a call with a locked parameter can return an error.
  • Do not expect a guarantee at temperature 0. Store results that must not change.
  • Steer through the prompt when controls are missing. That applies to chat interfaces and to models with locked parameters.

Frequently Asked Questions

Temperature controls how random the model's choice of the next token is. At low values the most probable token almost always wins, so answers are consistent and predictable. At high values less probable tokens get picked more often, which makes the text more varied and less predictable.

Top-k keeps only the k most probable next tokens at each step and samples only from them. At top-k 1, only the most probable candidate is left, at top-k 50 there are fifty. In Hugging Face's Transformers library, 50 is the default when the model sets nothing else. The OpenAI API does not offer top-k.

Top-p limits the choice to the smallest group of words whose probabilities add up to at least p. At p = 0.9, the most probable words stay until together they cover 90%, and the rest is dropped. The number of candidates adapts to the situation.

Temperature reshapes the probabilities themselves by flattening or sharpening them. Top-p keeps the probabilities as they are and cuts off the unlikely tail of the list. The usual advice is to change only one of the two so you can tell which one caused a change.

As starting values, use about 0 to 0.3 for facts and code, around 0.7 for general text, and about 1.0 for creative tasks. The ideal setting depends on the model, so try it on your own tasks.

Temperature 0 is the right value if the model should always pick the most probable word. It is not a guarantee of identical answers. In a test run by gradually.ai on November 7, 2026, DeepSeek V4.1 Flash returned a different sentence three times for the same request at temperature 0. If results must not change, store them.

OpenAI names a temperature value only for the API, not for the ChatGPT app. In the API, the default for models that support the setting is 1. For current reasoning models the setting is locked while reasoning is on. On GPT-6 Astra, GPT-6.1 Sol and GPT-6.2 it stays locked, because those models reject effort none.

GPT-5 is a reasoning model, and developers report that the API rejects the parameter. OpenAI gives no official reason for GPT-5. Its guide for the GPT-6 models tells developers to remove temperature, top_p and top_logprobs whenever reasoning effort is anything other than none. Control runs through that effort setting instead, and the docs do not give a longer explanation.

Both reduce repetition. Frequency penalty penalizes a word more the more often it already appeared. Presence penalty penalizes a word simply for having appeared at all, which pushes the model toward new topics. Claude's Messages API does not list these parameters.
Sources and References
FH

Finn Hillebrandt

AI Expert & Blogger

Finn Hillebrandt is the founder of Gradually AI, an SEO and AI expert. He helps online entrepreneurs simplify and automate their processes and marketing with AI. Finn shares his knowledge here on the blog in 50+ articles as well as through the AI Business Club.

Learn more about Finn and the team, follow Finn on LinkedIn, join his Facebook group for ChatGPT, OpenAI & AI Tools or do like 17,500+ others and subscribe to his AI Newsletter with tips, news and offers about AI tools and online business. Also visit his other blog, Blogmojo, which is about WordPress, blogging and SEO.