What You Need to Know
Claude sits on an autoregressive language model: it writes text one token at a time. A token is a unit of the model's vocabulary. The context window is all the text the model can reference while it writes, including what it writes. Sampling is how the model picks each next token; temperature sets how widely. Model options change how far it reasons, how hard it works and how fast tokens arrive.
Take a supermarket that answers shoppers in an online chat. Each request carries the store's policy pack, a catalogue extract, the chat so far and the new question. Shoppers ask about opening hours, stock and refunds.
Next-Token Generation, and the Three Things That Follow
Anthropic's glossary says models like this are pretrained "to predict the next word, given the previous context of text in the document". At inference the model emits one token at a time. Each token is conditioned on the whole sequence so far, including the tokens it has just produced. Three consequences follow.
Generation is serial, so response time scales with how many tokens come out. Input length affects the prefill and therefore time to first token. Output length affects the long tail. A long policy pack delays the first word a shopper sees, and a long reply delays the last.
There is no lookahead and no revision. Once a token is emitted it is part of the record. The model cannot go back and restructure an answer it started badly. So an output contract stated up front beats a correction added afterwards. A worked example placed before the task beats an instruction to fix the format if it drifts. If the supermarket wants each refund reply to open with the amount, it shows that shape first.
Each token conditions the next, so an early wrong turn compounds rather than self-corrects. The model is not sampling independently at each position. It is continuing what it has already written.
Thinking is the same mechanism applied before the visible answer. Reasoning tokens are generated first. They are billed as output tokens and count toward max_tokens alongside the response text.
Tokens Are Measured, Never Estimated
Tokens are not units of human text. They "can correspond to words, subwords, characters, or even bytes (in the case of Unicode)". Code, JSON, tables, identifiers and non-English text all tokenise differently from English prose, so a rule of thumb calibrated on paragraphs misprices a workload of log lines. The supermarket's catalogue extract, full of product codes, will not price like its policy prose.
The documentation set carries two different rules of thumb. The glossary says roughly 3.5 characters per token. The pricing FAQ says roughly 4 characters or 0.75 words. The disagreement is the lesson, not a fact to memorise.
Two instruments answer two different questions. Before the request, POST /v1/messages/count_tokens accepts the same structured inputs as a real message, including system prompt, tools, images and PDFs. It returns a single field:
import anthropic
client = anthropic.Anthropic()
MALT_HOUSE_STYLE_GUIDE = "You are the malt house's shift-log assistant."
steeping_log = "Batch 214: steep started 06:40, water at 14 degrees."
count = client.messages.count_tokens(
model="claude-sonnet-5-5",
system=MALT_HOUSE_STYLE_GUIDE,
messages=[{"role": "user", "content": steeping_log}],
)
print(count.input_tokens) # {"input_tokens": 14} on the wireimport Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
const MALT_HOUSE_STYLE_GUIDE = "You are the malt house's shift-log assistant.";
const steepingLog = "Batch 214: steep started 06:40, water at 14 degrees.";
const count = await client.messages.countTokens({
model: "claude-sonnet-5-5",
system: MALT_HOUSE_STYLE_GUIDE,
messages: [{ role: "user", content: steepingLog }]
});
console.log(count.input_tokens);Counting is free. Token counting and message creation "have separate and independent rate limits", so counting costs neither money nor Messages-API headroom. Its answer is explicitly "an estimate", and it does not use caching logic. After the request, the usage object on the response is the ground truth you bill against.
The third point catches more migrations than the other two. Token counts are tied to a tokenizer, and tokenizers change between model generations. Dated current state (August 2026): "Claude 4.7 and later models and Claude Mythos Preview use a newer tokenizer. The same input text produces approximately 30 percent more tokens than on earlier models". The count endpoint "returns the count under the tokenizer of the model you pass". So a count measured against last year's model is wrong for this year's, for both the cost model and the context-window headroom. Count against the model you will call, and recount whenever you change models.
The Context Window Is One Budget, Shared
The window is not an input allowance. It "refers to all the text a language model can reference when generating a response, including the response itself". Everything competes for the same space: "the system prompt, every message in messages (including tool results, images, and documents), and your tool definitions". And: "The output Claude generates for the turn, including its extended thinking, counts too". For the supermarket, the policy pack, catalogue extract, history and reply share one budget.
Two corollaries are routinely got backwards. First, caching creates no headroom: "Cached prompt prefixes still occupy the context window: prompt caching changes what you pay for those tokens, not whether they count". Second, thinking is not free space: its tokens are drawn from max_tokens and billed as output. Bigger is also not automatically better: "As token count grows, accuracy and recall degrade, a phenomenon known as context rot".
Overflow has two behaviours, split by whether the input alone is too big.
| Situation | Behaviour | Where it surfaces |
|---|---|---|
| Input alone exceeds the window | 400 invalid_request_error ("prompt is too long"), on every model | Before any generation |
Input plus max_tokens exceeds the window, Claude 4.5 and newer | Request accepted; generation stops with stop_reason: "model_context_window_exceeded" | Mid-generation |
Input plus max_tokens exceeds the window, earlier models | Validation error instead | Before any generation |
Both branches are arithmetic against a budget, with budget fixes: send less, retrieve fewer and better passages, split the job, or move to a model with a larger window. Neither is a prompt fault, and a more capable tier fixes neither. The counting endpoint above is how you stay inside the budget. A long supermarket chat that fails before any reply needs a shorter history, not a stronger model.
Sampling, Non-Determinism, and the Dial That Is Now Gone
The model does not always pick the single most likely next token. It samples from a distribution, and temperature widens or narrows that distribution. The glossary says: "Lower temperatures result in more conservative and deterministic outputs that stick to the most probable phrasing and answers". The word deterministic there is comparative. The entry's next paragraph says so. "Even with temperature set to 0, the results will not be fully deterministic and identical inputs may produce different outputs across API calls". The entry adds: "This applies both to Anthropic's first-party inference service and to inference through third-party cloud providers".
Temperature zero buys consistency, not reproducibility. No setting buys byte-identical output. Two shoppers asking the same question can get differently worded replies. Never build a component whose correctness requires two identical calls to return identical bytes. Constrain the shape instead, with a worked example and an explicit output contract. Validate the response at the boundary. Store an artefact you need to be stable rather than regenerating it and comparing. The supermarket stores its allergen statement once.
Current-state note (August 2026)
The sampling dial is now rejected. The API parameter deprecations table lists temperature, top_p and top_k as "Deprecated (Claude Opus 4.7 and later)". They return "a 400 error when set to a non-default value on Claude 4.7 and later models". The recommended replacement is "Omit and use prompting to guide model behavior". On older models the restriction applies only while thinking is on. The documentation set is not internally consistent: the Reducing latency page still suggests experimenting with temperature and has not been updated. Treat the deprecations table and the Thinking page as the authority. Keyed answers follow the exam guide where it speaks. Runnable code stays current-correct, which is why nothing on this page sets a sampling parameter.
Model Options: Which Lever for Which Problem
Four options move a request along the same reasoning, latency and cost axis. They are not interchangeable.
Extended thinking is the original manual form: thinking turned on with an explicit token budget. It is the older interface: the legacy Claude Haiku 4.5 still uses it, and the newest models reject it.
Adaptive thinking replaces it with a delegation. Setting thinking: {type: "adaptive"} lets Claude "decide when and how deeply to think based on the request". As of 14 October 2026, on Claude Opus 5.5, Opus 5, Sonnet 5.5, Sonnet 5, Haiku 5.5, Fable 5.1, Fable 5 and the Mythos models, "thinking is already on and needs no configuration". Reach for it when a hard problem is being answered shallowly, such as a refund dispute that gets a one-line reply.
As of September 2026 the thinking configuration also takes a display field, which defaults to "omitted" on those models. Thinking blocks then arrive with an empty thinking field, still billed and passed back as before. Opt in with display: "summarized" and you get a readable summary, never the raw chain of thought. To see the reasoning, read the thinking blocks rather than asking for it in the answer. On Claude Fable 5.1, Opus 5.5, Opus 5, Sonnet 5.5 and Fable 5, a request that tries to pull the internal reasoning into the response text can be refused. The refusal carries stop_details.category: "reasoning_extraction", and that category is billed even when the refusal arrives before any output.
Effort is the dial you turn most often, and it is the workhorse:
kiln_note_prompt = "Summarise this kiln note for the day book: burners cycled twice overnight."
response = client.messages.create(
model="claude-opus-5-5",
max_tokens=8192,
messages=[{"role": "user", "content": kiln_note_prompt}],
output_config={"effort": "low"},
)const kilnNotePrompt = "Summarise this kiln note for the day book: burners cycled twice overnight.";
const response = await client.messages.create({
model: "claude-opus-5-5",
max_tokens: 8192,
messages: [{ role: "user", content: kilnNotePrompt }],
output_config: { effort: "low" }
});Levels run low, medium, high, xhigh, max, and the default depends on the model. As of 14 October 2026, "Most Claude models default to high effort", while "Claude Opus 5.5 and Claude Haiku 5.5 default to medium". "Setting effort to the model's default ("medium" on Claude Opus 5.5 and Claude Haiku 5.5, "high" on other models) produces exactly the same behavior as omitting the effort parameter entirely". Omit it on Claude Opus 5.5 and the request runs one level lower than it did on Claude Opus 5.
Two properties make effort the first lever to try. It "applies to every output token", so "it works whether or not thinking is enabled". It covers tool calls and their arguments too. So "Lower effort also means fewer and terser tool calls", not merely shorter prose. It is "a behavioral signal, not a strict token budget".
Fast mode is the only one of the four that does not trade quality. It "runs the same model with a faster inference configuration. There is no change to intelligence or capabilities". It delivers a documented multiple of the standard output rate at premium pricing, behind the fast-mode-2026-02-01 beta header with speed: "fast". Its gain is in output tokens per second, "not time to first token (TTFT)". So it shows on long streamed answers and barely registers on short ones. Switching between fast and standard speed invalidates the prompt cache. As of September 2026 it is a research preview limited to Claude Opus 5.5, Claude Opus 5 and Claude Opus 4.8 on the Claude API. The current throughput multiplier sits on the domain quick reference.
The selection rule is three sentences long. A hard problem answered shallowly wants more reasoning. A routine problem that costs too much wants less effort. An answer that is already correct but arrives too slowly for a person watching wants faster token delivery. That means streaming first and fast mode where it exists, not a different model. So the supermarket uses thinking for refund disputes, lower effort for opening hours, and streaming for slow correct replies.
Zero-Shot, Single-Shot, Multi-Shot
Zero-shot is an instruction with no demonstration. Single-shot adds one worked input-output pair. Multi-shot adds several. The current documentation calls the same family "few-shot or multishot prompting". It states the durable claim: "Examples are one of the most reliable ways to steer Claude's output format, tone, and structure. A few well-crafted examples... improve accuracy and consistency".
An example demonstrates a format and a decision boundary at once, in the same representation the model will generate in. A description of a format is a second-order instruction the model has to translate first. Two real outputs shown side by side beat a sentence describing what an output should look like. So the supermarket shows two past refund replies.
Examples should be "Relevant: Mirror your actual use case closely". They should be "Diverse: Cover edge cases and vary enough that Claude doesn't pick up unintended patterns". And they should be "Structured: Wrap examples in <example> tags... so Claude can distinguish them from instructions". The documentation adds: "Include 3-5 examples for best results". Diversity is the test candidates underrate. A set of examples that all share an incidental property teaches that property. If every example reply confirms an item is in stock, the model learns that replies never report a shortage.
Reach for examples when the failure is one of form or of boundary: inconsistent structure, unclear classification edges, or drifting tone. Do not reach for them when the failure is one of budget (a request that will not fit) or of fact (something the model cannot know). Examples fix the supermarket's drifting reply layout. They cannot supply a price that is in none of its inputs. Examples cost input tokens on every call, which is why they interact with 5.4. A stable example block at the front of a prompt is the kind of prefix prompt caching exists for.
In the exam
Domain 5 is named for model selection, but that is its smallest sub-skill. Two-thirds of the marks sit in the fundamentals underneath it: how the model produces text, and what the layer beneath your call is doing. This lesson owns the first half. Most of it is a property of the model rather than of a release, so what you learn about the mechanism will not go stale. Don't rely on a tokens-per-word ratio.
The exam keys all three consequences of next-token generation. Under a latency constraint, a candidate who confuses input length with output length reaches for the wrong lever. The guide names the four model options together. The durable knowledge is which one addresses which complaint, as in the supermarket's three cases. Writing and iterating the prompts themselves is Domain 6.
Dated Facts
Where a fact is dated, this lesson says so. Every parameter name, level list and model list under Model Options is dated and lives on the domain quick reference.
Exam Traps
Reading more consistent as deterministic, and accepting an option that promises identical output for identical input.
Documentation states the opposite: even at temperature 0 the results are not fully deterministic and identical inputs may produce different outputs across API calls. Lower temperature narrows the distribution; it does not remove sampling. What stabilises output is a demonstrated format, a constrained output contract and validation at the boundary.
Confusing the two context-window overflow behaviours, or accepting the option that says the model silently truncates the oldest messages.
Input alone too large is a 400 invalid_request_error that arrives before generation. Input plus max_tokens too large on a current model is an accepted request that stops with stop_reason model_context_window_exceeded. Rolling first-in-first-out truncation is chat-interface behaviour, not API behaviour.
Sizing a prompt from a tokens-per-word ratio, or carrying a token count across a model migration.
Tokens are sub-word units whose density varies with language, punctuation and code, and the docs themselves carry two different rules of thumb. Tokenizers also change between model generations, so the same text is not the same token count on every model, and the counting endpoint returns the count under the tokenizer of the model you pass.
Mixing up which lever solves which problem, and answering a latency constraint with a smarter model.
Effort changes how much work the model does across the whole response including tool calls; adaptive thinking changes whether and how deeply it reasons; fast mode changes only how fast tokens come out, with no change to intelligence or capabilities; streaming changes only when the user sees them. A stem that states a latency bar on an answer that is already correct is not asking for more capability.
Practice Scenario
A maltings turns each barley batch's steeping and germination log into a two-line kiln note that the plant's batch-record system parses. Three complaints land in one meeting. The notes come back worded differently between runs on byte-identical logs, and the parser tolerates only one wording. A handful of unusually long logs from the new floor now fail outright with an error before any text is produced. And the process engineer has proposed setting temperature to zero so that the output becomes deterministic. Which assessment is correct?
Build Exercise
Measure the Budget, Then Break It Two Ways
What you'll learn
- How to measure tokens before and after a request, and why the two numbers differ
- How a tokenizer change invalidates a cost model across a migration
- How the two context-window overflow behaviours differ in symptom and in fix
- How to stabilise output shape without depending on byte-identical responses
- Take one prompt you already send and count it properly: call the token counting endpoint with the same system prompt, tools and messages you use in production, and record input_tokens. Then send the real request and compare that number against the usage object on the response
Why: Seeing the estimate and the billed count side by side is the fastest way to stop treating either as the other.
You should see: Two close but not identical numbers, with the response usage as the one you bill against.
- Count the same prompt twice, once against your current model and once against a model from a different tokenizer generation, and write both numbers down beside what each would do to your monthly cost estimate
Why: This is the measurement a migration silently skips, and the one that turns a cost model into fiction.
You should see: A materially larger count on the newer tokenizer for the same text.
- Break the budget from the input side: grow the input until the request alone exceeds the window, and record the exact status, error type and message, plus whether any tokens were generated
Why: Meeting the validation failure deliberately is how you stop misreading it as a quality problem later.
You should see: A 400 invalid_request_error, and no generated output at all.
- Now break it from the output side: keep the input comfortably inside the window but set max_tokens so that input plus max_tokens exceeds it, and record whether the request is accepted and what stop_reason comes back
Why: The two failures share a cause and differ in every observable, which is exactly the discrimination items are written on.
You should see: On a current model, an accepted request that stops with stop_reason model_context_window_exceeded.
- Run the same prompt twenty times with settings unchanged and diff the responses pairwise, counting how many are byte-identical. Then add one worked example of the exact output you want, repeat the twenty runs, and count how many now parse cleanly against your contract
Why: Proving to yourself that consistency and reproducibility are different properties is worth more than reading the sentence that says so.
You should see: Few or no byte-identical pairs in either run, and a large jump in the proportion that parse.
- Write one paragraph each on what stabilised and what did not, which failure was a budget fault and which was a format fault, and what you would have to change in the calling code if the model you use were retired next quarter
Why: Naming the fault class is the skill the exam actually measures, and the retirement question is the bridge into 5.3.
You should see: Three short paragraphs, each naming a mechanism rather than a symptom.
Sources
- Glossary — Claude Docs, tokens, latency, TTFT, temperature and the non-determinism statement
- Context windows — Claude Docs, the shared budget, cached prefixes, thinking tokens and both overflow behaviours
- Token counting — Claude Docs, the endpoint, its estimate status, its rate limits and the tokenizer change
- Thinking — Claude Docs, adaptive thinking, the display setting and the sampling-parameter restriction by model
- Refusals and fallback — Claude Docs, the refusal categories including reasoning_extraction, and which ones are billed
- Effort — Claude Docs, the levels, the per-model default and what effort affects
- Fast mode (research preview) — Claude Docs, speed, the beta header, OTPS versus TTFT and cache invalidation
- Model deprecations — Claude Docs, the API parameter deprecations table
- Prompting best practices — Claude Docs, examples as a steering technique and the relevance, diversity and structure tests
- Claude Certified Developer Foundations Exam Guide — Domain 5, LLM Fundamentals — Anthropic