🎓 Claude Certification Prep

Home › CCDV-F › M05

Model Selection and Optimization

Domain 5 12% of exam 48 practice questions ~19 min read

Understand token generation mechanics to explain model behavior, select a tier on quality, latency, and cost with regression evals when you change versions, then read usage data to find the dominant cost driver and quantify the impact of prompt caching, Batch, and token budgets.

Skills measured in this domain:
  • Generation Mechanics and Model Options: tokens, context window, sampling and non-determinism, adaptive thinking, effort levels
  • Model Tier Selection and Release Planning: quality, latency, cost; regression evaluations across model releases
  • Cost Diagnosis and Optimization: prompt caching (single, layered, rolling breakpoints), batch, token budgets; quantifying the impact

Domain overview

Domain 5 makes up 12% of the CCDV-F exam (about 8 of 70 items) and covers three skills:

  1. Generation Mechanics and Model Options: using an understanding of tokens, context windows, sampling, non-determinism, adaptive thinking, and effort to predict and control behavior.
  2. Model Tier Selection and Release Planning: selecting a tier on quality, latency, and cost, and planning for behavior changes across releases with regression evals.
  3. Cost Diagnosis and Optimization: reading usage data to find the dominant cost driver, choosing the lever (caching with single, layered, or rolling breakpoints; Batch; token budgets), and quantifying the impact.

Items usually give you usage data or a symptom and ask which change is most effective without changing the model's behavior.

(Sources: CCDV-F Exam Guide, Domain 5; Claude Certification exam prep: CCDV-F Prep Course — MSO Foundations)

Generation mechanics and model options

Tokens, tokenizers, and the context window

The model splits text into tokens, computes probabilities for the next token, then samples to pick one. Billing is per token, and every response has a usage block that records exactly how many tokens were billed.

  • Tokenizers differ between models: Sonnet 5 and Opus 5 use a new tokenizer that produces about 30% more tokens for the same text. Read each model's usage; don't estimate from character counts.
  • The context window holds everything Claude sees: system prompt, tools, history, tool results, thinking. Claude Opus 5.5 and Sonnet 5.5 have a 1M-token window; older models are limited to 200K. If you exceed the limit, the API rejects the request.
  • Context rot sets in before you hit the ceiling: the longer the context, the worse the model recalls details buried deep inside it, and the higher the prefill latency.

Sampling, temperature, and non-determinism

A low temperature gives stable output; a high temperature gives varied output. Note: Claude 4.7 and later models return an error for any temperature other than 1.0. Claude Sonnet 5.5 also rejects non-default top_p/top_k. On these models, steer the output through the prompt.

The same prompt can produce different results across runs, so evals must run multiple trials:

  • pass@k: at least 1 of k attempts succeeds; use it when you have a checker that lets you retry.
  • pass^k: all k attempts succeed; use it when users need consistency. For example, 75% per attempt drops to 0.75³ ≈ 42% for 3 in a row.

(Sources: Anthropic Academy: Introduction to evals — When to use what model; Anthropic Academy: Building with the Claude API — Temperature; Anthropic Engineering: Demystifying evals for AI agents)

max_tokens, adaptive thinking, and effort

max_tokens is a ceiling the model cannot see. Lowering it does not make the model write less; it only cuts the response off with stop_reason: "max_tokens". A truncated turn is still billed. Recommendation: set 64,000 for agentic work (128,000 is the maximum) and treat a max_tokens stop as an error. To save money, use effort, a parameter the model can see.

client.messages.create(
    model="claude-opus-5-5", max_tokens=16000,
    thinking={"type": "adaptive", "display": "summarized"},
    output_config={"effort": "high"},  # low | medium | high | xhigh | max
    messages=[...])
  • With adaptive thinking, the model decides whether to think and how much. effort goes in output_config, not next to thinking. The default is high on most models and medium on Claude Opus 5.5 and Claude Haiku 5.5.
  • {"type": "enabled", "budget_tokens": N} is the legacy form. Sending it to Claude Sonnet 5.5 returns a 400 error.
  • Thinking tokens count toward max_tokens and the context window, are billed as output (the full thinking, not the summary), and count toward rate limits. On Haiku 5.5, a max_tokens that is too small can end the response before any text appears.

Exam trap

When an answer is cut off mid-sentence, "lower max_tokens so the model writes more concisely" is wrong, because the model cannot see that ceiling. The right fix: read stop_reason, raise the ceiling, and if you need it cheaper, lower effort or ask for a short format in the prompt.

Key point

Adaptive thinking plus output_config.effort is how you control reasoning depth on current models. budget_tokens is legacy. Thinking is billed as output.

(Sources: Anthropic Academy: Claude Platform 101 — What is thinking?; Claude Cookbooks: Extended Thinking; Claude Docs: Optimizing for cost and intelligence)

Model tier selection and release planning

Tiers and how to choose

Tier Positioning Use for
Haiku Fastest, cheapest High volume, simple tasks: classification, extraction, routing
Sonnet Balances intelligence, speed, and cost Most production work
Opus Most capable of the three core lines; slower and more expensive Deep reasoning, multi-step coding
Fable Tier above Opus; more expensive than Opus The hardest tasks

The "current" versions change over time. Claude Platform 101 lists Haiku 4.5, Sonnet 5, Opus 5.5, Fable 5.1. The cost-optimization docs list Haiku 5.5, Sonnet 5.5, Opus 5.5, Fable 5.2. That is exactly why you need regression evals and version pinning.

Selection process:

  1. Set an accuracy floor from the cost of one wrong answer, before you look at prices.
  2. Run the same cases and the same prompt on every model, starting with Haiku. 20–30 real examples are enough to start.
  3. Drop the models below the floor. Among the rest, pick the one with the lowest cost per completed task (run cost ÷ tasks completed), not the lowest price per token.

In production you can route by task type: Haiku classifies, Sonnet drafts, Opus handles the hard tasks.

Scenario example

Meridian sets a 90% floor, because each wrong answer costs 5 minutes of manual review and the team can only absorb 5 in 50. On 50 cases: Haiku 4.5 gets 42/50 (84%) at $0.0009/task, Sonnet 5 gets 50/50 at $0.0020, Opus 5 gets 50/50 at $0.0046. Haiku is the cheapest but falls below the floor, so they choose Sonnet 5. After the prompt is fixed, Haiku 4.5 reaches 100%. Lesson: fix the prompt before you upgrade the model, and rerun the eval whenever you change the prompt or the case set.

(Sources: Anthropic Academy: Claude Platform 101 — Choosing the right model; Anthropic Academy: Introduction to evals — When to use what model, Iterate the prompt before you upgrade the model)

Effort first, model change second

When cost is high but quality is fine, sweep effort on the current model before adding another model. Claude Opus 5.5 figures on a SWE-bench Pro subset:

Effort Solve rate Cost/task
low 87.4% $0.11
medium (default) 92.8% $0.21
high 95.3% $0.29
xhigh 96.7% $0.74
low, rerun failures at high about 97% about $0.17

Running cheap first and rerunning the failures at a higher effort matches the "everything at high" solve rate at roughly 40% lower cost. Conditions: you need a reliable failure signal, and you must accept double the latency on the failed tasks.

Regression evals and version pinning

  • Pin the version: configure a specific model ID, for example claude-opus-5-5, or a dated ID such as claude-haiku-4-5@20251001 on Vertex AI. Change it only through a PR with evals. On Claude Managed Agents you can pin a session to an agent version so you can roll back.
  • Smoke eval on every PR: pick 10 of the 50 cases, set an 88% threshold (9/10), and make it a required check.
  • Full suite when the prompt or model changes, run through Batch.
  • Live: score 1–5% of traffic every night and alert when the score drops more than 2 standard deviations below the baseline.
  • Prompt audit when migrating: newer models follow lines such as "verify twice" or "be maximally thorough" literally, which costs money without improving accuracy. Obsolete thinking settings and contradictory rules can even reduce accuracy.

Exam trap

"The new model is stronger, so just swap the model string" is wrong. Changing the model changes behavior, so you must run regression evals on the same cases and audit the prompt. Switching models mid-session also loses the cache, because caches are separate per model.

Key point

Floor first, price second. Compare on cost per completed task. Fix the prompt before upgrading the model. Lower effort before adding a model. Pin the model ID and gate merges with a smoke eval.

(Sources: Claude Docs: Optimizing for cost and intelligence; Anthropic Academy: Introduction to evals — Evals in production: CI, batch, and drift; Anthropic Academy tutorial: Set up Claude on Google Cloud (Google managed); Claude Cookbooks: Claude Managed Agents)

Diagnosing cost from usage data

With prompt caching, total input = cache_creation_input_tokens (cache writes) + cache_read_input_tokens (cache reads) + input_tokens (the part after the last breakpoint, not cached). Example: 100,000 read, 0 written, 50 input gives a total input of 100,050 tokens.

Symptom Common cause Lever
Input dominates cost, prefix repeats Caching not enabled Prompt caching
Large cache_creation on every request, cache_read ≈ 0 Breakpoint placed on changing content, or the prefix changes byte by byte Move the breakpoint to the end of the static part
Both cache fields = 0 despite cache_control Prefix below the minimum, silently skipped Group more static content or drop caching
Agent loop reads less than about 80% from cache Something is breaking the cache Check the invalidation table
Output dominates Long answers, high effort Shorter format, lower effort
Work nobody waits for runs synchronously Batch not used Batch API

Reference point: agent loops on real traffic read a median of 84% of input from cache. According to Anthropic, caching is usually the biggest lever and Batch comes second. Output costs 5 times as much as input on current models. One experiment found that a 1-line answer cost $0.49 per run and a 6-section memo cost $1.40, with the same accuracy.

(Sources: Claude Docs: Prompt caching; Claude Docs: Optimizing for cost and intelligence)

Prompt caching: breakpoints, TTL, and invalidation

How it works

The cache stores an exact byte-for-byte prefix in the order tools → system → messages, up to and including the block that has cache_control.

  • Automatic caching: set cache_control: {"type": "ephemeral"} at the request level. The breakpoint moves to the last block automatically and takes 1 of the 4 slots.
  • Explicit breakpoints: up to 4 breakpoints. Writes happen only at breakpoints. On reads, the system looks back up to 20 blocks to find an earlier write. A consecutive run of tool_use/tool_result counts as one position.

Three breakpoint patterns

  • Single: place it on the last block that stays identical across requests, i.e., the end of the static part, not on the question or a timestamp.
  • Layered: one breakpoint per rate of change. For example, breakpoint 1 after tools and system (never change) and breakpoint 2 after the per-customer document (changes a few times a day). When the document changes, layer 1 is still read.
  • Rolling: for a growing conversation, the breakpoint sits on the last block and moves forward each turn. This works when each turn adds fewer than 20 blocks. If a turn adds 20 or more blocks, add a second breakpoint.
system=[{"type": "text", "text": STATIC_RULES},
        {"type": "text", "text": customer_policy,
         "cache_control": {"type": "ephemeral"}}]   # end of the static part
messages=[{"role": "user", "content": question}]   # changing part after the breakpoint

Exam trap

A breakpoint placed after the question makes every prefix unique, so there is never a read. Extending the TTL cannot save an entry that never matches. Switching to a smaller model changes behavior. The right answer is to move or layer the breakpoints.

Minimum length and TTL

Minimum Model
512 tokens Claude Opus 5.5, Opus 5, Sonnet 5.5, Haiku 5.5, Fable 5.1/5.2
1,024 tokens Claude Sonnet 5, Opus 4.8, Sonnet 4.6, Sonnet 4.5
2,048 tokens Claude Opus 4.7
4,096 tokens Claude Haiku 4.5, Opus 4.6, Opus 4.5
  • The default TTL is 5 minutes, refreshed for free on each use, and counted from when the request starts.
  • The 1-hour TTL costs 2 times input to write (5 minutes is 1.25 times). When you mix the two, 1-hour entries must come first. Use it when roughly 1 in 20 gaps falls between 5 and 60 minutes and few gaps exceed 1 hour.
  • Alternative: keep-alive, i.e., resend the identical request with max_tokens: 0 every 4 minutes (not usable with stream, structured outputs, forced tool choice, or Batch).
  • On the Claude API, caches are isolated per workspace.

What breaks the cache

Change Impact
tools definitions Breaks everything
Toggling web search, citations, speed Breaks system and messages
tool_choice, images, thinking config, effort Breaks messages
Changing the model Separate cache, effectively lost
Timestamp ahead of the static part, JSON with reordered keys Every request becomes a full write

When you must change something mid-conversation, choose the form that preserves the cache. In Anthropic's tests, editing the system prompt cost 25–50 times as much as sending a system message mid-conversation, and changing effort at the top level cost 20–40 times as much as changing it in a message. Batch required changes at a natural break, such as the first request after compaction. Claude Code does exactly this: static content first, updates injected into messages as <system-reminder>, and no tool or model changes mid-session.

Key point

5-minute write = 1.25 times, 1-hour write = 2 times, read = 0.1 times the input price (0.05 times on Opus 5.5/Sonnet 5.5). These multipliers stack with Batch. A miss bills the whole prefix at the write price.

(Sources: Claude Docs: Prompt caching; Claude Blog: Lessons from building Claude Code: Prompt caching is everything; CCDV-F Exam Guide, Sample Question 2)

Batch, token budgets, and other levers

  • Batch API: 50% off all tokens, including cached tokens. Results arrive within 24 hours (mostly under 1 hour), but 24 hours is the expiry, not an SLA. Up to 100,000 requests or 256 MB. Results come back out of order; match them by custom_id. Only succeeded requests are billed. Cache hits within a batch are best-effort. Batch is single-shot (no tool loop) and does not stream.
  • Token budgets: max_tokens caps one response. A Claude Managed Agents session budget is a spending cap per session (it stops with stop_reason: budget_reached). The workspace spend limit is the last line of defense.
  • Cutting input: tool search with defer_loading for large tool catalogs. Upload data tables through the Files API with code execution instead of pasting them into the prompt (25/25 correct for $0.40, versus 7/25 for $5.01).

Exam trap

"Move everything to Batch to save 50%" is wrong when users are waiting or the agent needs a multi-turn tool loop.

(Sources: Claude Docs: Batch processing; Claude Docs: Optimizing for cost and intelligence)

Quantifying impact: a worked cost example

Assumptions: Claude Sonnet 5 ($/MTok: input 2, 5-minute write 2.50, read 0.20, output 10; Batch 50% off). Each request has a 20,000-token static prefix, a 500-token question, and 400 output tokens. There are 1,000 requests and the cache never expires, i.e., 1 write and 999 reads.

Option Calculation Cost
A. No caching Input 20.5M × $2 = $41.00; output 0.4M × $10 = $4.00 $45.00
B. Breakpoint after the question Each request writes 20,500 tokens: 20.5M × $2.50 = $51.25; output $4.00 $55.25
C. Breakpoint at the end of the static prefix Write 0.02M × $2.50 = $0.05; read 19.98M × $0.20 ≈ $4.00; question 0.5M × $2 = $1.00; output $4.00 ≈ $9.05
D. Batch, no caching $45.00 × 50% $22.50
E. Batch + caching as in C $9.05 × 50%, a lower bound because caching in batches is best-effort ≈ $4.52
  • In A, input is $41/$45 ≈ 91%, the dominant cost driver. C cuts about 80% while the model sees exactly the same content.
  • B costs more than no caching at all, because it pays the 1.25× write price on every request.
  • Break-even, in units of the prefix's input price: with 5 minutes, n requests cost 1.25 + 0.1(n−1) versus n, so you save from the first read (1.35 < 2). With 1 hour, 2 + 0.1(n−1) saves from the 3rd request (2.2 < 3).
  • If output dominates, caching helps little: shorten the format, lower effort, or use Batch.

Scenario example

A 40-turn agent's cost grows roughly with the square of the number of turns, because the first turn is resent 40 times. Usage shows only about 30% cache reads, and the system prompt has a "Current time" line at the top. Fix: move the status line to the end of the latest user turn (after the breakpoint) and leave earlier turns untouched. Switching to Haiku is wrong, because it changes behavior without touching the root cause.

(Sources: Claude Docs: Prompt caching; Claude Docs: Batch processing (pricing table); Claude Docs: Optimizing for cost and intelligence)

Quick summary

  • Read token counts from each model's usage. Sonnet 5 and Opus 5 produce about 30% more tokens for the same text.
  • Claude 4.7 and later reject any temperature other than 1.0, so steer output through the prompt. Non-determinism requires multiple trials: pass@k differs from pass^k.
  • max_tokens is a ceiling the model cannot see. Treat stop_reason: "max_tokens" as an error; set 64,000 for agentic work.
  • Adaptive thinking plus output_config.effort. budget_tokens is legacy. Thinking is billed as output.
  • Model selection: floor first, then cost per completed task. Start from Haiku and work up. Fix the prompt before upgrading the model.
  • Running low and rerunning failures at high is about 40% cheaper than everything at high, but needs a failure signal.
  • Version changes need a pinned model ID, a required smoke eval on PRs, a full suite via Batch, monitoring of 1–5% of traffic, and a prompt audit.
  • Cache order: tools → system → messages. Up to 4 breakpoints, writes only at breakpoints, 20-block lookback.
  • Single breakpoint at the end of the static part, layered by rate of change, rolling for long conversations.
  • Below the minimum (512 to 4,096 depending on the model), nothing is cached and no error is raised.
  • 5-minute write 1.25 times, 1-hour write 2 times, read 0.1 times. Choose 1 hour when roughly 1 in 20 gaps falls between 5 and 60 minutes.
  • Changing tools breaks every layer. tool_choice, effort, and thinking break messages. Changing the model loses the cache.
  • Batch is 50% off and stacks with caching. Out of order, matched by custom_id; don't use it when someone is waiting.
  • A misplaced breakpoint can cost more than no caching.