# Top-p sampling

> Canonical: https://skillalmanac.com/glossary/top-p | Last verified: 2026-11-25 | Index status: index-eligible

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.

## 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](/glossary/self-hosted-llm).
- **What it changes.** The spread of [tokens](/glossary/token) the model samples from at each step of [inference](/glossary/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](/glossary/prompt-engineering) 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.

## Worked examples in this catalogue

### [What Is an LLM? The Facts Agent Users Need](https://skillalmanac.com/learn/what-is-an-llm-for-agent-users)

Status: illustrative example from the item's own documentation, not executed for this page.

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.

### [llm-cost-estimator](https://skillalmanac.com/skills/skill-almanac/llm-cost-estimator)

```
Give the skill a usage profile and your own price table.
```

Status: illustrative example from the item's own documentation, not executed for this page.

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.

### [agent-session-cost-review](https://skillalmanac.com/skills/skill-almanac/agent-session-cost-review)

Status: illustrative example from the item's own documentation, not executed for this page.

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.

### [Claude Code](https://skillalmanac.com/tools/claude-code)

```
/model
```

Status: illustrative example from the item's own documentation, not executed for this page.

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.

## Related terms

- [Inference](https://skillalmanac.com/glossary/inference.md)
- [Token](https://skillalmanac.com/glossary/token.md)
- [Large language model (LLM)](https://skillalmanac.com/glossary/large-language-model.md)
- [Prompt engineering](https://skillalmanac.com/glossary/prompt-engineering.md)
- [Autoregressive model](https://skillalmanac.com/glossary/autoregressive-model.md)

## Sources

- [Model deprecations: API parameter deprecations](https://platform.claude.com/docs/en/about-claude/model-deprecations), Anthropic (Claude API Reference) (accessed 2026-11-24)
- [Chat Completions API reference](https://developers.openai.com/api/reference/resources/chat), OpenAI (API Reference) (accessed 2026-11-24)
- [Model configuration: aliases and fallback behavior](https://code.claude.com/docs/en/model-config), Claude Code documentation (accessed 2026-11-25)

Definitions are written by Skill Almanac from the sources above and checked against them on 2026-11-25. [Glossary index](https://skillalmanac.com/glossary.md).
