AI Guides · 9 min read

What Is Temperature in AI? How It Changes Model Output

Temperature is a sampling setting that changes how randomly a model picks the next token. Official API ranges differ, and 0 is not fully reproducible.

A matte-black unnumbered control knob on a brushed-steel surface, lit by warm amber on one side and cooler blue on the other, with no text or logos

What is temperature in AI? In large language model APIs, temperature is a sampling parameter that scales how randomly the model picks the next token from its probability distribution. Lower values concentrate choices on higher-probability tokens, while higher values spread probability across more options, though supported ranges and defaults vary by provider as of November 2026.

How Does LLM Temperature Work?

LLM temperature controls next-token randomness after a language model calculates probabilities across its candidate vocabulary. When a model generates text, it predicts one token at a time. At each generation step, the model assigns a probability to possible next tokens, and the sampler uses temperature to decide how strongly to favor the top candidates.

Lowering temperature makes next-token selection more concentrated on higher-probability tokens, which keeps responses more focused. Raising temperature spreads probability more widely across lower-ranked tokens, which makes outputs more varied.

Because temperature operates at sampling time in the inference API, providers define different bounds, defaults, and deprecation rules. Before passing sampling parameters in production, check both the vendor’s current reference and model support when choosing an AI model.

Temperature vs Top-P and Top-K Sampling

Temperature, top-p, and top-k are separate sampling controls that narrow candidate tokens and shape randomness in distinct stages. While temperature scales how sharply or smoothly the sampler chooses among allowed tokens, top_p and top_k restrict which tokens stay in the candidate pool.

How Top-P (Nucleus Sampling) Filters Candidates

Top-p sampling, also called nucleus sampling, limits the candidate pool to the smallest set of tokens whose cumulative probability reaches the top_p threshold. In OpenAI’s official API documentation, top_p defaults to 1 across a range from 0 to 1, and 0.1 means “only the tokens comprising the top 10% probability mass are considered.”

Google Cloud’s parameter guide gives a concrete example of top-P filtering. If tokens A, B, and C have probabilities 0.3, 0.2, and 0.1 and top-P is 0.5, the model selects either A or B as the next token by using temperature and excludes C.

How Top-K Sampling Works With Top-P and Temperature

Top-k sampling restricts the candidate set to the k most probable tokens at each step. According to Google Cloud’s official documentation, “A top-K of 1 means the next selected token is the most probable among all tokens in the model’s vocabulary (also called greedy decoding), while a top-K of 3 means that the next token is selected from among the three most probable tokens by using temperature.”

When all three controls apply together, Google Cloud documents a clear step-by-step order:

  1. The top-K tokens with the highest probabilities are sampled at that token step.
  2. Those candidates are further filtered based on top-P.
  3. The final token is selected from the remaining pool using temperature sampling.

Provider APIs expose these three parameters differently. OpenAI’s Chat Completions and Responses references define temperature and top_p without presenting a general top_k request parameter, and OpenAI advises: “We generally recommend altering this or top_p but not both.” Google’s Gemini API reference similarly notes that models running with nucleus sampling alone do not allow setting top_k, indicated by an empty top_k attribute.

What Are the Official Temperature Limits at OpenAI, Anthropic, and Google?

OpenAI, Anthropic, and Google enforce different official rules for temperature ranges, default values, and unsupported models as of November 25, 2026. The table below summarizes each provider’s active API documentation.

Provider & Surface Temperature Range Official Default Top-P / Top-K Support Newer Model Limits (as of Nov 2026)
OpenAI Chat Completions & Responses 0 to 2 1 top_p (0 to 1, default 1); no general top_k field Support can differ by model, particularly newer reasoning models
Anthropic Messages & Batches Removed from current docs 1.0 when omitted top_p and top_k also removed 400 error on Claude 4.7+, Claude Mythos Preview, and API version 2026-10-21
Google Gemini API (generateContent) 0.0 to 2.0 Varies by model (getModel) topP and topK vary by model (getModel) Silently ignored on Gemini 3.6 Flash and newer models
Google Cloud (Gemini Enterprise Agent Platform) 0.0 to 2.0 1.0 (also recommended starting value) topP and topK documented Custom values unsupported and ignored on Gemini 3.6 Flash and newer

OpenAI Chat Completions and Responses APIs

OpenAI defines temperature and top_p identically across the Chat Completions API and the Responses API as of November 25, 2026. Both temperature and top_p are optional numbers or null, each defaulting to 1. OpenAI accepts temperature values from 0 to 2 and states: “Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or top_p but not both.”

OpenAI also warns on the Chat Completions page that “Parameter support can differ depending on the model used to generate the response, particularly for newer reasoning models.” The page directs callers to the OpenAI reasoning guide for unsupported parameters. Because that guide focuses on reasoning effort and mode controls without publishing a model-by-model temperature support table, check the current official API reference for the exact model ID you call.

Anthropic Messages API and the 2026-10-21 Removal

Anthropic’s current Using the Messages API guide, latest major SDKs, and CLI have removed temperature, top_p, and top_k as request parameters as of November 25, 2026. Anthropic’s official note states: “The temperature, top_p, and top_k sampling parameters are not supported on Claude 4.7 and later models and Claude Mythos Preview, or on any model starting with API version 2026-10-21. Setting them to a non-default value returns a 400 error, and starting with 2026-10-21 any value does. Omit them from request payloads and use prompting to guide the model’s behavior instead.”

Anthropic’s 2026-10-21 migration guide explains how the removal affects Messages and Message Batch requests:

  • Sending temperature, top_p, or top_k on API version 2026-10-21 returns a 400 error, even at the parameter’s default value.
  • Omitting those parameters samples at their defaults, including a temperature of 1.0, matching a 2023-06-01 request that leaves them out.
  • Models that already accepted only defaults, such as Claude 4.7 and later models, sample as before.
  • Models that previously accepted other values, such as Claude Sonnet 4.6, lose the effect of a lowered temperature under 2026-10-21, and no other setting replaces it. Requests that depend on non-default values must either drop the parameter or stay on 2023-06-01.

Google Gemini API vs. Google Cloud Documentation

Google publishes separate official references for the Gemini API and Google Cloud’s Gemini Enterprise Agent Platform, and their descriptions of default values differ slightly as of November 25, 2026.

In the Gemini API generateContent reference, temperature is an optional number from 0.0 to 2.0 whose default varies by model via the Model.temperature attribute returned from getModel. The same per-model default behavior applies to topP (Model.top_p) and topK. That reference explicitly warns that temperature, topP, and topK are no longer supported and are silently ignored on Gemini 3.6 Flash and newer models.

On Google Cloud’s Adjust parameter values page, Google states that Gemini models support temperature values between 0.0 and 2.0, lists a default temperature of 1.0, and notes that “1.0 is the recommended starting value for temperature.” Google Cloud’s inference documentation echoes the Gemini API deprecation rule: custom values for temperature, topP, and topK are unsupported on Gemini 3.6 Flash and later models, are ignored if set, and should be removed from requests.

Is Temperature 0 Deterministic in Practice?

Setting temperature to 0 does not guarantee identical, reproducible outputs across AI APIs. While developers often reach for temperature = 0 to lock responses down, official documentation at all three providers stops short of promising exact repeatability.

OpenAI describes lower values such as 0.2 as making output “more focused and deterministic,” without claiming that 0 produces bit-identical repeats. Anthropic addresses this assumption directly in the Claude Opus 5.5 migration guide: “If you were using temperature = 0 for determinism, note that it never guaranteed identical outputs on prior models.” Prompting is Anthropic’s recommended way to guide behavior on Claude Opus 5.5.

Google Cloud’s parameter guide gives a similar warning. At a temperature of 0, “the highest probability tokens are always selected. In this case, responses for a given prompt are mostly deterministic, but a small amount of variation is still possible.” On models that still accept temperature, 0 reduces randomness toward high-probability tokens, while exact output stability still requires validation in your application layer.

How Should Developers Use Sampling Controls Today?

Developers building with LLM APIs should verify model-level sampling support before including temperature, top_p, or top_k in shared request templates. As newer models drop or ignore these fields, sending legacy defaults can either fail validation or mislead debugging.

  1. Check model and API version compatibility first: Omit temperature, top_p, and top_k on Claude 4.7 and later models, Claude Mythos Preview, Anthropic API version 2026-10-21, and Gemini 3.6 Flash and newer models, and verify OpenAI reasoning models against the current API reference.
  2. Tune one sampling parameter at a time: When working with supported OpenAI endpoints, follow OpenAI’s guidance to adjust temperature or top_p individually.
  3. Inspect official defaults instead of assuming: Use getModel in the Gemini API to read Model.temperature, Model.top_p, and top_k, or review Google Cloud’s 1.0 starting guidance when working on that platform.
  4. Move behavioral guidance into prompts: Where sampling controls are removed or silently ignored, rely on explicit prompt instructions to steer tone, structure, and consistency.

FAQ

These frequently asked questions summarize how LLM temperature, top-p, top-k, and determinism behave across major AI APIs as of November 2026.

What does setting temperature to 0 do in an AI API?

Setting temperature to 0 concentrates sampling on the highest-probability tokens on models that still accept the parameter. Google Cloud explains that responses at 0 are “mostly deterministic, but a small amount of variation is still possible.” OpenAI calls lower settings “more focused and deterministic,” and Anthropic warns that temperature = 0 never guaranteed identical outputs on prior models.

Should I change temperature or top-p?

On OpenAI’s Chat Completions and Responses APIs, OpenAI explicitly states: “We generally recommend altering this or top_p but not both.” Because temperature scales randomness across candidate probabilities while top_p trims the candidate pool by cumulative probability mass, changing both together makes output behavior harder to isolate. Pick one control when calling models that support both.

Why does Anthropic return a 400 error for temperature?

Anthropic removed temperature, top_p, and top_k from its latest SDKs, CLI, and Messages API reference. On Claude 4.7 and later models and Claude Mythos Preview, non-default values return a 400 error. Starting with API version 2026-10-21, sending any value for those three parameters returns a 400 error, so callers should omit them and use prompting.

Does Google Gemini still use temperature, topP, and topK?

Gemini models accept temperature values from 0.0 to 2.0 on earlier models, with defaults varying by model via getModel in the Gemini API and documented as 1.0 on Google Cloud. However, on Gemini 3.6 Flash and newer models, temperature, topP, and topK are unsupported, silently ignored if sent, and should be removed from requests.

What is the difference between top-p and top-k sampling?

top_p (nucleus sampling) keeps the smallest set of tokens whose cumulative probability reaches the chosen threshold, such as 0.1 for the top 10% probability mass. top_k keeps a fixed count of the k most probable tokens, where top_k of 1 equals greedy decoding. Google’s documented pipeline applies top_k, then top_p, then temperature.

Sources

All parameter ranges, defaults, and deprecation rules in this article come from the official vendor documentation below, verified November 25, 2026.

Written by

Chunyu Cai

Chunyu Cai is the CEO of Lotook, LLC and an entrepreneur who writes about AI models, agents, and how they change everyday work. Chunyu holds a master's degree from Imperial College London.