Temperature and Top-P: What They Do and Which APIs Still Support Them (2026)
How temperature, top-p and top-k sampling work, which OpenAI, Anthropic and Gemini models accept them today, why no setting guarantees deterministic output, and a reproducible protocol for testing settings yourself.
Temperature and top-p are sampling settings: they change how a language model picks each next token from its probability distribution. For years, guides (including an earlier version of this one) handed out "use 0.2 for code, 0.9 for creative writing" recipes. Two things make that advice unreliable now:
- Support has narrowed. Several current models reject or ignore these parameters, especially reasoning models.
- There is no universal right value. The effect depends on the model, the prompt and the task, so a number that works on one model is not a recipe for another.
This guide explains what the settings do, documents what each major API accepts (checked against official docs on 2026-11-05), and gives you a protocol to test settings on your own task.
What the Settings Do
At each step, a model assigns a probability to every possible next token. Sampling settings change how one is chosen.
- Temperature rescales the distribution. Lower values concentrate probability on the most likely tokens, so output becomes more focused and repetitive. Higher values flatten it, so less likely tokens are picked more often and output becomes more varied, and eventually less coherent. OpenAI's API reference describes it this way: "Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic" (OpenAI Responses API reference, checked 2026-11-05).
- Top-p (nucleus sampling) keeps only the smallest set of tokens whose combined probability reaches p, then samples from that set.
top_p = 0.1means only tokens in the top 10% of probability mass are considered. - Top-k keeps only the k most likely tokens. Not every API exposes it.
Two practical points follow from this:
- Temperature and top-p both narrow or widen the candidate pool, so changing both at once makes results hard to interpret. OpenAI's reference says: "We generally recommend altering this or
top_pbut not both" (checked 2026-11-05). - Low temperature does not make output correct. It makes the model's most likely continuation more likely. If that continuation is wrong, a low temperature makes it consistently wrong.
Which APIs Accept These Settings
All details below were checked against official documentation on 2026-11-05. They change often, so check the linked pages before you rely on them.
OpenAI
- Ranges and defaults. In the Responses API and Chat Completions API references,
temperatureaccepts values "between 0 and 2" with a default of 1, andtop_pdefaults to 1 (Responses API reference; Chat Completions reference). - Reasoning models. The Chat Completions reference warns that "Parameter support can differ depending on the model used to generate the response, particularly for newer reasoning models." OpenAI's guide for its latest model family says: "When reasoning effort is not
none, removetemperature,top_p, andtop_logprobs" (OpenAI latest-model guide). For those models, the main lever is reasoning effort, not sampling. - Seed. Chat Completions has a
seedparameter, marked as beta. With it, "our system will make a best effort to sample deterministically," but "Determinism is not guaranteed, and you should refer to thesystem_fingerprintresponse parameter" to detect backend changes (Chat Completions reference). We did not find aseedparameter in the Responses API reference.
Anthropic (Claude)
- Current API version removes sampling parameters. Under Messages API version
2026-10-21, "a request that sendstemperature,top_p, ortop_kreturns a 400 error, even at the parameter's default value." Requests sample with the defaults, "including atemperatureof 1.0" (Claude API migration guide for 2026-10-21, checked 2026-11-05). - Newer models already accepted only defaults. The same guide says "Models that already accept only the defaults, such as Claude 4.7 and later models, sample as before" after the change. On older models that accepted other values, a request that lowered
temperaturefor more consistent output "loses that effect. No other setting replaces it." If you depend on a non-default value, the guide's options are to stop sending it or keep that request on the older2023-06-01version. - Depth of reasoning on current Claude models is controlled with adaptive thinking and an
effortsetting rather than sampling (Claude thinking docs, checked 2026-11-05).
Google Gemini
- Ranges and defaults. In the Gemini API's
GenerationConfig,temperature"can range from [0.0, 2.0]" and its default "varies by model" (see thetemperatureattribute returned bygetModel).topPandtopKdefaults also vary by model, and some models don't allowtopKat all (Gemini API reference, checked 2026-11-05). - Newer models ignore them. The same reference says each of
temperature,topPandtopK"is no longer supported and is silently ignored on Gemini 3.6 Flash and newer models." Silent ignoring is easy to miss: your request succeeds, but the setting has no effect. - Seed.
seedis documented as "Seed used in decoding. If not set, the request uses a randomly generated seed." The reference does not promise identical outputs.
Summary
| Temperature / top-p | Determinism controls | |
|---|---|---|
| OpenAI | 0-2 / default 1 where supported; remove for latest reasoning models when reasoning effort isn't none | seed in Chat Completions (beta, best effort, not guaranteed) |
| Anthropic | Rejected (400) on API version 2026-10-21; Claude 4.7+ already accepted only defaults | None documented as a replacement |
| Gemini | Temperature 0-2, defaults vary by model; ignored on Gemini 3.6 Flash and newer | seed (no identical-output guarantee stated) |
All rows checked 2026-11-05 against the sources above.
Why You Can't Count on Deterministic Output
Even where you can set temperature to 0 or pass a seed, providers don't promise byte-identical responses. OpenAI says so explicitly for seed and points to system_fingerprint because backend changes can alter outputs. Model versions are updated or retired, and on newer models the parameters may not apply at all.
If you need reproducibility, design for it outside the model:
- Store outputs you need to reproduce (with the prompt, model ID, date and settings) instead of regenerating them.
- Validate structure with structured output or JSON schemas where your provider supports them, and check results in code.
- Pin the model version where the provider offers dated or versioned model IDs, and re-test when it changes.
- Accept variation and test for it. Run the same input several times and check that every output passes your checks, not just one.
What to Use When Sampling Settings Aren't Available
On models that ignore or reject sampling parameters, these levers do the work temperature used to:
| You wanted | Try instead |
|---|---|
| More consistent wording or format | Explicit format instructions, one or two examples, structured output / JSON schema |
| Fewer factual mistakes | Provide the source material, ask for quotes or citations, validate against the source |
| More careful reasoning | The provider's reasoning or effort setting |
| More variety (brainstorming) | Ask for N distinct options in one response, vary the prompt ("from a cost angle", "from a user's angle"), or run several requests |
| Pick the best of several | Generate several candidates, then score them with tests or a rubric |
If Your Model Does Accept Them
Treat any value as a starting point to test, not a rule:
- Change one parameter at a time; leave the other at its default.
- Move in large steps first (for example default vs. noticeably lower vs. noticeably higher) to see whether the setting matters at all for your task before fine-tuning.
- Check the response for signs the setting was ignored: if outputs look the same across very different values, look at the docs for your exact model.
- Re-test whenever you change model or prompt.
Example requests
OpenAI Chat Completions, on a model that accepts sampling settings:
from openai import OpenAI
client = OpenAI()
response = client.chat.completions.create(
model="YOUR_MODEL", # check the model's parameter support first
messages=[{"role": "user", "content": "Write three taglines for a budgeting app."}],
temperature=1.2, # alter temperature OR top_p, not both
seed=42, # best effort only; compare system_fingerprint
)
print(response.choices[0].message.content, response.system_fingerprint)
Anthropic Messages API on version 2026-10-21: no sampling fields. Shape output with instructions instead.
curl https://api.anthropic.com/v1/messages \
-H "x-api-key: $ANTHROPIC_API_KEY" \
-H "anthropic-version: 2026-10-21" \
-H "content-type: application/json" \
-d '{
"model": "YOUR_MODEL",
"max_tokens": 1024,
"system": "Return exactly three taglines, one per line, each under 8 words.",
"messages": [{"role": "user", "content": "Taglines for a budgeting app."}]
}'
Gemini generateContent, on a model where GenerationConfig sampling fields still apply:
{
"contents": [{ "role": "user", "parts": [{ "text": "Write three taglines for a budgeting app." }] }],
"generationConfig": {
"temperature": 1.2,
"seed": 42
}
}
A Reproducible Settings Experiment (Protocol)
This is a protocol for you to run. It is not a set of results, and we are not reporting numbers from it.
1. Fix everything except the setting under test.
Record the provider, exact model ID, API version, date, full prompt (system and user), max_tokens, and any reasoning or effort setting.
2. Confirm the parameter is accepted. Send one request at a clearly non-default value. If you get an error, the model doesn't support it. If you get a success, compare against the default in the next steps, because some APIs silently ignore unsupported settings.
3. Choose a small grid. For example: default, one lower value, one higher value for temperature, with top-p left at its default. Test top-p separately if you need it.
4. Use real inputs with checkable outcomes. Pick 10-30 inputs from your actual workload. Define pass/fail checks you can automate: tests pass, JSON validates, required facts present, length within limits.
5. Run each input several times per setting. At least 5 runs per input per setting, so you can see variation rather than one lucky sample.
6. Record per run:
date, model_id, api_version, setting, input_id, run_number,
passed_checks (true/false), output_length, latency_ms,
system_fingerprint (OpenAI, if present), output_text
7. Compare. For each setting: pass rate, how often runs of the same input disagree, and whether outputs at different settings actually differ. If the settings produce indistinguishable results, the parameter may not be in effect, or it doesn't matter for this task.
8. Write down the limits. Results apply to that model, prompt and date. Re-run the protocol when any of them change.
Common Mistakes
- Copying a value from a guide or another model. Defaults and ranges differ between providers, and a value tuned on one model doesn't transfer.
- Setting temperature to 0 and assuming reproducibility. No provider we checked guarantees identical outputs.
- Changing temperature and top-p together, then not knowing which one mattered.
- Not noticing a silently ignored parameter. Check docs for your exact model and compare outputs.
- Using sampling to fix a prompt problem. If outputs are wrong or off-format, improve the instructions, examples or validation first.
Frequently Asked Questions
Should I adjust temperature or top-p first?
If your model supports them, adjust one and leave the other at its default; OpenAI recommends altering one but not both. Many people start with temperature because its effect is easier to reason about.
What happens if I don't set them?
The API uses its defaults. For OpenAI's references the default for both is 1; Anthropic's migration guide says requests sample with defaults including a temperature of 1.0; Gemini defaults vary by model (checked 2026-11-05).
Do these settings affect cost?
Not directly; you pay for tokens. Indirectly, more varied outputs can be longer or need more retries, so measure length and retry rates in your experiment.
Are there other sampling parameters?
Some APIs expose others, such as top-k, frequency and presence penalties, stop sequences and seeds. Support varies by provider and model, so check the API reference for the specific model you call.
My provider removed temperature. How do I get creative output now?
Ask for several distinct options in one response, vary the framing of the prompt, or run several requests and choose the best with a rubric. For consistency, use explicit format rules, examples and structured output.
Related reading: chain-of-thought prompting and reasoning models, system prompts vs user prompts, and how to write better AI prompts. For prompt templates you can test with this protocol, browse the prompt library.
Related Articles
Chain-of-Thought Prompting in 2026: Task Decomposition, Reasoning Models and Verifiable Answers
What chain-of-thought prompting is, what the original research showed, how current reasoning models change it, and practical patterns for decomposing tasks and getting answers you can verify.
Role-Playing Prompts: Define Perspective, Task and Boundaries
When assigning an AI a role helps and when it doesn't, reusable role templates, and an illustrative with-and-without-role comparison you can run on your own tasks.
How to Evaluate AI Prompts: A Repeatable Regression Workflow
A step-by-step method for evaluating AI prompts: build a test set, write a rubric, combine deterministic and model-graded checks, record model settings, read failures and iterate without regressions.