CCDVF-D5.2 · Model Selection & Optimization16.8% of CCD-F5 min read

LLM Fundamentals: Tokens, Sampling & Non-Determinism.

Claude is autoregressive: it predicts one token at a time from a probability distribution conditioned on everything before it, then appends that token and repeats. Even at temperature: 0, Anthropic states results "will not be fully deterministic and identical inputs may produce different outputs across API calls," true for first-party and third-party inference alike.

Loading your plan…
Mental modelAssuming temperature: 0 produces deterministic, reproducible output, Anthropic's docs state this is false even at 0, across first-party and third-party inference alike.
LLM Fundamentals: Tokens, Sampling & Non-Determinism, hero illustration featuring Loop mascot in a warm gallery scene.
Share
On this page
01 · Summary

TLDR

Claude is autoregressive: it predicts one token at a time from a probability distribution conditioned on everything before it, then appends that token and repeats. Even at temperature: 0, Anthropic states results "will not be fully deterministic and identical inputs may produce different outputs across API calls," true for first-party and third-party inference alike.

~3.5
Avg characters per token
CCDVF-D5
Exam domain
16.8%
Domain weight
6
Models rejecting temp/top_p/top_k
2-5
Multishot example sweet spot
02 · Definition

What it is

Every Claude call rests on the same next-token loop: an autoregressive model predicts one token at a time, sampling from a probability distribution over the vocabulary conditioned on everything before it, appends that token, and repeats. Tokens are the smallest units the model processes; for Claude, one token is "approximately 3.5 English characters," though this varies by language, so /v1/messages/count_tokens should be used to budget usage rather than assuming a fixed character-to-token ratio.

The context window is "all the text a language model can reference when generating a response, including the response itself," a working-memory buffer, not the training corpus. Everything in a request counts toward it: system prompt, every message (including tool results, images, documents), tool definitions, plus all generated output including extended-thinking tokens. Current models (Opus 4.8/4.7/4.6, Sonnet 5/4.6, Fable 5) default to a 1M-token window at standard pricing; Sonnet 4.5 caps at 200K. More context is not automatically better: accuracy and recall can degrade as tokens grow, a documented phenomenon Anthropic calls "context rot."

Sampling and non-determinism sit on top of the same loop. temperature controls output randomness, higher increases variation, lower pushes toward the most probable tokens. The load-bearing fact for the exam: even at `temperature: 0`, output is not guaranteed reproducible, a property of the sampling process itself, not a configuration mistake.

03 · Mechanics

How it works

Next-token generation is the mechanism everything else sits on. Nothing about tokens, context windows, or sampling changes this: the model always produces one token, appends it to the sequence, and conditions the next prediction on the updated sequence. Thinking tokens, tool-call arguments, and plain text are all generated through this same loop, just with different downstream handling.

Token counting is measured, not estimated. Use /v1/messages/count_tokens on representative inputs before sending a request, rather than dividing character count by a fixed ratio, since the ~3.5 chars/token figure varies by language and content. Context-window overflow is enforced server-side: if the input alone exceeds the window, the API returns a 400 error before generation starts; if input_tokens + max_tokens exceeds the window, generation can stop mid-response instead.

Sampling parameters are being phased out on the newest models, not just theoretically unreliable. On all six models that reject them - Claude Fable 5, Claude Mythos 5, Claude Mythos Preview, Claude Opus 4.8, Claude Opus 4.7, and Claude Sonnet 5 - non-default temperature, top_p, and top_k values are rejected outright with an HTTP 400, on every request to those models, regardless of whether thinking is active. The replacement lever is output_config.effort (low/medium/high[default]/xhigh/max) combined with thinking: {type: "adaptive"}, which lets Claude decide whether and how much to think per request. This is a model-selection and cost-tuning decision in its own right; see Model Selection & Tradeoffs for the full tier/pricing/migration picture, this page stays focused on the tokens-and-sampling mechanics underneath it.

Fundamental prompting techniques sit on the same spectrum, differentiated by example count. Zero-shot supplies no examples and leaves output format to the model's judgment. Anthropic's documented technique is "few-shot or multishot prompting," wrapping "a few well-crafted examples" in <example> tags, which "improve accuracy and consistency." Single-shot (one example) is the standard midpoint between the two. This page covers the spectrum at the fundamentals level; the deep multishot technique, including the exact <sample_input>/<ideal_output> XML pattern and measured accuracy gains, lives in Prompt Engineering Techniques.

LLM Fundamentals: Tokens, Sampling & Non-Determinism mechanics, painterly diagram featuring Loop mascot.
Exam trap

Assuming temperature: 0 produces deterministic, reproducible output, Anthropic's docs state this is false even at 0, across first-party and third-party inference alike. A second trap on this same page: assuming manual thinking: {type: "enabled", budget_tokens: N} is still the recommended way to control thinking depth; on the newest models it is deprecated or rejected outright in favor of adaptive thinking plus effort.

04 · In production

Where you'll see it

Audit logging system

Instead of assuming temperature: 0 gives replayable outputs for compliance review, the system logs the actual generated output at call time, since replay isn't guaranteed even at zero temperature.

Multilingual classification pipeline

Calls /v1/messages/count_tokens per input language before sizing max_tokens, instead of a single fixed characters-per-token heuristic that would misestimate non-English inputs.

05 · Compare

Side-by-side

↔ scroll to compare
TechniqueExamples in promptBest forTradeoff
Zero-shot0Simple, well-understood tasks with an obvious output shapeFormat and edge-case handling left entirely to the model's judgment
Single-shot1Establishing one concrete pattern or format quicklyOne example rarely covers every edge case or failure mode
Multi-shot (few-shot)2-5, wrapped in <example> tagsConsistent format/tone across ambiguous or edge-case-heavy tasksMore prompt tokens per call; only pays off when examples target observed failures
06 · When to use

Decision tree

01

Does this workload require exact, reproducible output across repeated calls (e.g. for compliance replay)?

YesDesign for it explicitly, log actual outputs, validate against a schema, don't rely on temperature: 0; Anthropic states it does not guarantee determinism, on any inference path.
NoStandard sampling behavior is fine as-is.
02

Is the target model one of the six that reject non-default sampling params (Fable 5, Mythos 5, Mythos Preview, Opus 4.8, Opus 4.7, Sonnet 5)?

YesNon-default temperature/top_p/top_k will be rejected with a 400; use output_config.effort and adaptive thinking instead.
NoSampling parameters are still accepted, though output remains non-deterministic regardless.
03

Is the task's correct output format ambiguous, or does it have known edge cases Claude has failed on before?

YesAdd 2-5 multishot <example> pairs targeting exactly those observed failures.
NoZero-shot is likely sufficient; added examples would just cost tokens for no accuracy gain.
04

Do you need to budget max_tokens or estimate cost before sending a request?

YesCall /v1/messages/count_tokens on representative inputs rather than estimating from a fixed character ratio.
NoNo pre-flight token count needed for this call.
07 · On the exam

Question patterns

LLM Fundamentals: Tokens, Sampling & Non-Determinism exam trap, painterly cautionary scene featuring Loop mascot.

6 V2 questions wired to this concept. Tap an answer to check it instantly - you'll see whether it's right and why - then expand the full breakdown for the mental model and all four rationales.

Question 1 of 6 · D2Choose the best answer

An engineering team wants their CI/CD pipeline to use Claude for an automated pre-merge code review that must complete and post a result before a pull request can be merged, typically within a few minutes. Should they use the Batch API?

08 · FAQ

Frequently asked

Showing 2 of 2 questions

Help someone pass

Share this concept.

One share is one less person stuck on the same question.

Last reviewed: ·Refresh cadence: monthly