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.
- Penalties change the scores of tokens that already appeared in the text.
- Temperature flattens or sharpens the distribution.
- Top-K, top-p or min-p remove unlikely candidates.
- 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.
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.
- Temperature
- 0 to 0.3
- Note
- Consistent answers matter more than variety.
- Temperature
- about 0.7
- Note
- A good balance of natural wording and reliability.
- Temperature
- 0.9 to 1.2
- Note
- More variety, but more outliers. Values above 1.5 are rarely useful.
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.”
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:
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.
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.”
Invented example outputs. Real measurements are in this entry’s own test.
Prompt: “Name three fruits.”
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:
- llama.cpp
- 0.8
- Ollama
- 0.8
- llama.cpp
- 40
- Ollama
- 40
- llama.cpp
- 0.95
- Ollama
- 0.9
- llama.cpp
- 0.05
- Ollama
- 0 (off)
- llama.cpp
- 1.0 (off)
- Ollama
- 1.0 (off)
- llama.cpp
- 64
- Ollama
- 64
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.”
Invented example outputs. Real measurements are in this entry’s own test.
Prompt: “Tell me something about traveling.”
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.
- Temperature
- 0.0
- Different answers
- 3 of 3
- Different servers
- 3 of 3
- Temperature
- 0.7
- Different answers
- 3 of 3
- Different servers
- 3 of 3
- Temperature
- 1.5
- Different answers
- 3 of 3
- Different servers
- 1 of 3
- Temperature
- 0.0
- Different answers
- 2 of 3
- Different servers
- 1 of 3
- Temperature
- 0.7
- Different answers
- 3 of 3
- Different servers
- 1 of 3
- Temperature
- 1.5
- Different answers
- 3 of 3
- Different servers
- 2 of 3
DeepSeek V4.1 Flash returned three different sentences at temperature 0. All three start the same way and then drift apart.
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.
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.
- German
- 4 different in 20, most common 10 times
- English
- 4 different in 20, most common 16 times
- German
- 3 different in 20, most common 11 times
- English
- 4 different in 20, most common 14 times
- German
- 5 different in 5
- English
- 5 different in 5
- German
- 5 different in 5
- English
- 3 different in 5
- German
- 5 different in 5, 2 with garbled words
- English
- 5 different in 5
- German
- 4 different in 5
- English
- 4 different in 5
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.
- 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
- 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
- Claude API
- Claude Opus 5.5: omit, otherwise error 400
- OpenAI API
- Not available
- Gemini API
- Silently ignored from Gemini 3.6 Flash
- 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
- 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
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.
