CCDVF-D5.2 · Domain 5 · Model Selection & Optimization · 16.8% of CCD-F

LLM Fundamentals: Tokens, Sampling & Non-Determinism.

5 min read·8 sections·Tier A

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. Claude glossary: Temperature

Official Anthropic docsCCDVF-D5 (16.8%)CCD-F only
LLM Fundamentals: Tokens, Sampling & Non-Determinism, hero illustration featuring Loop mascot in a warm gallery scene.
Domain CCDVF-D5Model Selection & Optimization · 16.8%
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. Claude glossary: Temperature

~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.
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

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.
A compliance team wants to log Claude's output once and treat future identical requests as "replayable" for audit purposes, using `temperature: 0` to guarantee this. Will this work?
No. Anthropic states that even at temperature: 0, "results will not be fully deterministic and identical inputs may produce different outputs across API calls," true for both first-party and third-party inference. Named distractor: "yes, as long as top_p and top_k are also left at default", leaving other sampling params at default doesn't change the underlying non-determinism guarantee.
A developer sets `temperature: 0.7` on a request to `claude-opus-4-8` and receives an HTTP 400 error. What's the cause, and what's the fix?
Opus 4.8 rejects non-default temperature/top_p/top_k outright, on every request, regardless of thinking state. The fix is to control output via output_config.effort and thinking: {type: "adaptive"} instead. Named distractor: "lower the temperature value below 0.7 until it's accepted", wrong, any non-default value is rejected on this model, not just values above some threshold.
A pipeline estimates `max_tokens` budgets by dividing each input's character count by 4, across English, Japanese, and code inputs. What's wrong with this approach?
Tokens are roughly 3.5 characters for English but vary meaningfully by language and content type; a fixed ratio is unreliable across mixed-language inputs. The correct approach is calling /v1/messages/count_tokens on the actual input. Named distractor: "the ratio is fine as long as you round up", rounding doesn't fix a ratio that's wrong by a different, unpredictable margin per language.
An extraction task with a genuinely ambiguous output format is producing inconsistent field names run to run under zero-shot prompting. What's the recommended fix per Anthropic's documented technique?
Add 2-5 multishot examples wrapped in <example> tags, chosen to cover the specific failure modes observed, not generic passing cases. Named distractor: "lower the temperature to reduce variation", temperature tuning doesn't fix an underspecified output *format*, and is being phased out as a lever on the newest models entirely.
After migrating a workload to Sonnet 5, a call using `thinking: {type: "enabled", budget_tokens: 4000}` starts returning a 400 error. What changed?
Manual extended thinking with budget_tokens is rejected on Sonnet 5; it requires thinking: {type: "adaptive"} instead, tuned via output_config.effort. Named distractor: "the budget_tokens value of 4000 is too low for this model", the parameter itself is rejected on this model generation, not the specific value supplied.
08 · FAQ

Frequently asked

Does `temperature: 0` guarantee identical outputs across calls?
No. Anthropic explicitly states this is false, even at 0, results are not fully deterministic, on both first-party and third-party inference.
Is a token the same thing as a word or a character?
No. A token is roughly 3.5 English characters on average but varies by language and content; use /v1/messages/count_tokens for an exact count rather than a fixed conversion ratio.
09 · Practice with AI

Work this with your AI

Work this concept hands-on with Claude Code, Codex, or claude.ai. Copy a prompt, paste it into your assistant, and practise in tandem. Each one keeps you active (explain it back, get drilled, or build) rather than just reading.

  • Drill it like the exam (scenario MCQs)
    Practice in the exam's scenario-MCQ format with trap awareness.
  • Explain it back (Feynman)
    Build durable, transferable understanding of a concept you can half-state.
  • Test me, adapting the difficulty
    Active recall practice on a concept you think you know.
  • Check my prerequisites first
    Before studying a concept that keeps not sticking.
  • Find the high-leverage 20%
    When a domain feels too big and you are short on time.
Self-check

Test yourself

Three diagnostic questions on this primitive. Reveal each answer when you have a guess. Want a full 60-question mock? Open the mock hub →

Q1A compliance team wants to log Claude's output once and treat future identical requests as "replayable" for audit purposes, using `temperature: 0` to guarantee this. Will this work?
No. Anthropic states that even at temperature: 0, "results will not be fully deterministic and identical inputs may produce different outputs across API calls," true for both first-party and third-party inference. Named distractor: "yes, as long as top_p and top_k are also left at default", leaving other sampling params at default doesn't change the underlying non-determinism guarantee.
Q2A developer sets `temperature: 0.7` on a request to `claude-opus-4-8` and receives an HTTP 400 error. What's the cause, and what's the fix?
Opus 4.8 rejects non-default temperature/top_p/top_k outright, on every request, regardless of thinking state. The fix is to control output via output_config.effort and thinking: {type: "adaptive"} instead. Named distractor: "lower the temperature value below 0.7 until it's accepted", wrong, any non-default value is rejected on this model, not just values above some threshold.
Q3A pipeline estimates `max_tokens` budgets by dividing each input's character count by 4, across English, Japanese, and code inputs. What's wrong with this approach?
Tokens are roughly 3.5 characters for English but vary meaningfully by language and content type; a fixed ratio is unreliable across mixed-language inputs. The correct approach is calling /v1/messages/count_tokens on the actual input. Named distractor: "the ratio is fine as long as you round up", rounding doesn't fix a ratio that's wrong by a different, unpredictable margin per language.
Last reviewed: 2026-05-04·Refresh cadence: monthly
CCDVF-D5.2 · CCDVF-D5 · Model Selection & Optimization

LLM Fundamentals: Tokens, Sampling & Non-Determinism, complete.

You've covered the full ten-section breakdown for this primitive, definition, mechanics, code, false positives, comparison, decision tree, exam patterns, and FAQ. One technical primitive down on the path to CCA-F.

More platforms →