AI GLOSSARY · AI CONCEPTS
Top-p sampling
Definition
Top-p, or nucleus sampling, is a setting that limits a language model to choosing its next token from the smallest set of likely tokens whose probabilities add up to p, instead of from every possible token.
Also called: top p, top-p, nucleus sampling, top p sampling, top-p parameter.
In plain language
When a language model writes, it scores every possible next piece of text, called a token, then picks one. Top-p narrows that choice. With a lower top-p the model picks only from the most likely options, so its wording is more predictable. With a higher value it can pick from a wider spread, so the wording varies more. It is a setting mostly used through an API. Changing the sampled tokens can change both wording and factual claims; it does not verify accuracy, so a model can still be wrong at any setting. OpenAI's API reference generally recommends changing this or temperature but not both. Some newer models no longer let you set it.
Technical definition
Nucleus sampling truncates the next-token distribution. Tokens are sorted by probability and the smallest prefix whose cumulative probability reaches p is kept; the rest are dropped, the kept probabilities are renormalised, and one token is sampled. OpenAI's API reference describes top_p as an alternative to sampling with temperature, where the model considers tokens within the top_p probability mass, and says it generally recommends altering this or temperature but not both. Anthropic’s model-deprecation documentation says API version 2026-10-21 removes temperature, top_p and top_k for every model, returning a 400 error if supplied at any value. Earlier API versions reject non-default values on Claude 4.7 and later models and Claude Mythos Preview; support must be checked against both API version and model.
Worked examples in this catalogue
Catalogue examples point at a skill, guide or coding tool listed on this site, with what to run and what you see. An example marked illustrative describes the item from its own documentation; it was not executed for this page. Platform Scores are our assessment under a published method, not a safety guarantee.
Guide · Illustrative, not executed
What Is an LLM? The Facts Agent Users Need
- What you see
- The guide explains what the model can and cannot do from the point of view of someone running a coding agent.
- Why it exercises the concept
- The guide explains next-token prediction, which is the step top-p adjusts.
Skill by Skill Almanac · Illustrative, not executed
llm-cost-estimator 56/100 · Provisional, not yet measuredScored · Method v0.2 · How we score
- What to try
Give the skill a usage profile and your own price table.- What you see
- A monthly LLM cost range with cache, batch and subscription effects.
- Why it exercises the concept
- Top-p does not change the price per token, so it does not appear in the estimate. The skill shows what does: tokens in and tokens out.
Skill by Skill Almanac · Illustrative, not executed
agent-session-cost-review 58/100 · Provisional, not yet measuredScored · Method v0.2 · How we score
- What you see
- A report of where a coding-agent session spent its tokens, from the saved transcript.
- Why it exercises the concept
- A saved transcript can help inspect exported context and outputs, with usage estimates and omissions. It does not isolate prompt-versus-sampling causes; where settings are supported, controlled comparisons are needed.
Coding tool · Illustrative, not executed
Claude Code
- What to try
/model- What you see
- The /model command changes the selected model configuration; hybrid aliases or configured fallback behavior can use different models on later turns.
- Why it exercises the concept
- Switching the model is a control Claude Code documents. Anthropic's API documentation says some newer models do not accept top_p.
How it shows up when you use agents
Coding-agent users do not usually set top-p themselves. The agent product picks sampling settings for you, and a hosted API may not accept the setting at all. Anthropic’s API version 2026-10-21 rejects temperature, top_p and top_k at any value on every model. Earlier API versions have model/default-value exceptions, including non-default rejection on Claude 4.7+ and Mythos Preview. If you call a model through an API, you meet top-p as a request field.
- Where you meet it. In API requests, in a model's settings page on an open model runner, or in a config for a self-hosted LLM.
- What it changes. The spread of tokens the model samples from at each step of inference. Lower values narrow the choice.
- What it does not change. What the model knows or whether its claims are true. Wrong answers can appear at any setting.
What breaks when this is misunderstood: a team tunes top-p to fix wrong answers, when the fix is a better prompt or a check against real files. The next action is to check the vendor's reference for the model you call. Change one sampling setting at a time, as OpenAI's reference recommends for top_p and temperature.
Common confusions
- Top-p versus top-k. Top-p keeps tokens up to a probability total. Top-k instead uses a fixed candidate count; whether a provider accepts either field depends on its model and API version.
- Top-p versus temperature. Both shape randomness. OpenAI's reference describes top_p as an alternative to temperature and generally recommends altering one but not both.
- Myth: lower top-p makes the model more accurate. It makes wording more predictable. It does not add knowledge or verify claims.
- Myth: every model accepts top_p. Anthropic removes the field for every model in API version 2026-10-21; earlier API versions have model/default-value exceptions.
Related terms
Terms that mention Top-p sampling
2 terms mention this one
More in AI concepts
Sources
- Model deprecations: API parameter deprecations, Anthropic (Claude API Reference) (accessed 2026-11-24)
- Chat Completions API reference, OpenAI (API Reference) (accessed 2026-11-24)
- Model configuration: aliases and fallback behavior, Claude Code documentation (accessed 2026-11-25)
Definitions are written by Skill Almanac from these sources and were checked against them on 2026-11-25. Wikipedia is never the only source.
Review record
Last verified
Drafted by Claude (original draft); OpenAI Codex (bounded factual repairs); sources and example targets checked by Independent automated source review (OpenAI Codex); not human peer review on 2026-11-25. Last verified .
Change log (5)
- : Independent automated factual/example review completed. Cached US query estimate aligned to receipt; no traffic promise. Final technical gate recorded separately; publication disabled.
- : First version.
- : Verifier pass: applied defect-list corrections (unsourced claims dropped or reworded to source wording).
- : Bounded source repairs: Added exact sampling-field API-version/value boundary and current primary citation; removed transcript causal proof and qualified model selection. Pending independent re-review.
- : Automated review completed; approved for the staged public release. Search indexing is controlled by the release configuration.