CertSafari
    Anthropic Claude Certified Architect – Professional (CCAR-P) - December 7 onwards· Lessons

    Domain 2 · Lesson 10/39

    Token budgets: auditing context composition and cache behaviour

    Context Composition and Token Economics

    17 min read
    2.17% of exam
    6 sources
    Published 18 Nov 2026
    Docs as of 18 Nov 2026

    What you will be able to do

    • Find the tokens a request consumes, block by block, and estimate them before sending with the token counting endpoint
    • Work out the daily cost of a fixed prefix across a stated call volume, uncached and cached
    • Read cache_creation_input_tokens and cache_read_input_tokens to tell expiry, prefix drift and below-minimum prompts apart
    • Spot content that cuts tokens safely (duplicates, idle tool definitions, volatile values in the cached prefix) and cuts that remove information the model needs

    Key concept

    Per-call token composition × call volume — Every request pays for everything it carries: tool definitions, system prompt, messages and output. A block that is repeated, never used or never matched in cache costs its tokens once on every call. So the savings come from finding which blocks are redundant or uncached and multiplying them by the call volume, not from trimming the reply.

    1.What a request is made of, and how to measure it

    A token budget starts with a full list of what the request contains. The context window holds the system prompt, every message (including tool results, images and documents), the tool definitions, and the output Claude generates for the turn, including its extended thinking. Teams often focus on the user's question when it is a small fraction of the request. A support assistant that sends 40,000 tokens of tool definitions and policy before a 200-token question is mostly paying for the prefix.

    More context does not mean better answers. As the token count grows, accuracy and recall degrade. The documentation calls this context rot. Removing irrelevant tokens therefore cuts cost and can also improve answers. Removing relevant ones does the opposite. Each candidate cut has to pass two tests: does it save tokens across the call volume, and does the model still have everything the task needs?

    The token counting endpoint lets you measure before you send. It accepts the same structured inputs as a message request, including system prompts, tools, images and PDFs, and returns the total input tokens. It is free to use but rate-limited per usage tier. Count the request with and without a block and you have that block's per-call cost. The count is an estimate that ignores caching: cache_control markers are accepted but have no effect, because caching only happens when a message is actually created.

    Counting the input tokens of a request before sending itpython
    client = anthropic.Anthropic()
    
    response = client.messages.count_tokens(
        model="claude-opus-5-5",
        system="You are a scientist",
        messages=[{"role": "user", "content": "Hello, Claude"}],
    )
    
    print(response.json())

    After a request is sent, its usage field shows what it actually consumed. With prompt caching, the input count is split into three fields. input_tokens is the uncached input after the last breakpoint. cache_creation_input_tokens is what this request wrote to cache. cache_read_input_tokens is what it read from cache. They are separate parts of one total, so a zero in one field is a real zero.

    Checkpoint 1 of 8· Fill the gap

    You want to find out what one block costs on every call by comparing the request with and without it, before sending anything to the model. Which method completes this sample?

    client = anthropic.Anthropic()
    
    response = client.messages. ? (
        model="claude-opus-5-5",
        system="You are a scientist",
        messages=[{"role": "user", "content": "Hello, Claude"}],
    )
    
    print(response.json())

    Sources12

    2.Pricing a prefix across a call volume

    Each kind of token has its own price, and the multipliers determine whether caching pays off. Relative to the base input price, a 5-minute cache write costs 1.25x and a 1-hour write costs 2x. Cache reads cost 0.1x on most models, 0.05x on Claude Opus 5.5 and Claude Sonnet 5.5, and 0.025x on Claude Fable 5.2. Output tokens cost five times the input price on the current models, and thinking tokens are billed as output.

    Price per million tokens on three current models
    ModelInputOutput5m cache write1h cache writeCache hits and refreshes
    Claude Opus 5.5$4$20$5$8$0.20
    Claude Sonnet 5.5$2$10$2.50$4$0.10
    Claude Haiku 5.5 (prompts up to 100,000 tokens)$0.10$0.50$0.125$0.20$0.01

    Here is a worked case on Claude Sonnet 5.5: a 40,000-token prefix sent 50,000 times a day is 2,000 million input tokens a day.

    • Uncached, at $2 per million, that costs $4,000 a day.
    • Read from cache, at $0.10 per million, it costs $200 a day, plus a write of about $0.10 each time the entry has to be created again.
    • Written on every call and never read, at $2.50 per million, it costs $5,000 a day. That is more than not caching at all.

    The third case is why caching has to be checked against usage rather than assumed. A marker on the wrong block raises the bill.

    The arithmetic also rules out a common reflex. max_tokens caps the output a request may generate, up to 128k on current models. It does not change the prompt. Lowering it can shorten or truncate replies, but every input token is still sent and billed. Output-side levers such as reasoning effort are covered in reasoning effort and context lifecycle. The prefix in a high-volume service is an input problem. For tuning that goes beyond composition, see cost and latency optimization.

    Checkpoint 2 of 8· Check yourself

    A support service on Claude Sonnet 5.5 sends the same 40,000-token prefix with a 5-minute cache_control marker. Across a day of traffic, the usage field shows cache_creation_input_tokens of about 40,000 on every call and cache_read_input_tokens of 0. What should the team conclude about the cost of the prefix?

    Sources31

    3.Reading usage to diagnose a cache that never hits

    Two usage patterns look alike at first glance but have different causes. If both cache_creation_input_tokens and cache_read_input_tokens are 0, nothing was cached, usually because the prompt is below the model's minimum cacheable length. The minimum is 512 tokens on the current generation and up to 4,096 tokens on some older models. A prompt that is too short is processed without caching and no error is returned. If writes roughly equal the prefix but reads stay at 0, the cache is being written on every call and never matched.

    No. A too-short prefix produces zero writes, and a 20,000-token prefix is far above any minimum. A write without a later read has three possible causes:

    • The entry expired. The default lifetime is five minutes. It is refreshed at no cost on each use and measured from the start of the request that wrote or read it. In bursty traffic, a gap of several minutes lets the entry lapse, and the next request writes it again.
    • The prefix changed. A cache hit needs prompt segments that are 100 percent identical. A shared helper that emits tool definitions in a different order, or with edited descriptions, changes the very first level of the prefix on every call.
    • Requests arrived in parallel. An entry becomes usable only after the first response starts, so a fan-out of simultaneous requests all write.

    The TTL does not change how reads are reported. A 5-minute entry that is matched shows up in cache_read_input_tokens just as a 1-hour entry does.

    Checkpoint 3 of 8· Check yourself

    Usage logs for an agent on Claude Sonnet 5.5 show cache_creation_input_tokens of about 30,000 and cache_read_input_tokens of 0 on every request. Requests are sent one at a time, each a few seconds after the previous response finishes. Which explanation fits this pattern?

    Checkpoint 4 of 8· Exam question

    After enabling prompt caching on a Messages API service, the usage object for most requests shows cache_creation_input_tokens roughly equal to the 20,000-token prefix and cache_read_input_tokens of 0. Traffic is bursty, with some gaps of several minutes between requests, and a shared library builds the tools array for each call. Which two causes best fit this evidence? Choose two.(Select 2)

    0 of 2 selected

    Sources3

    4.Keeping volatile values out of the cached prefix

    The cache matches a prefix in a fixed order: tools, then system, then messages, up to the block that carries cache_control. A change at any level invalidates that level and everything after it. Changing tool definitions therefore invalidates the whole cache. A system-prompt change keeps the tool cache but invalidates the system and message caches.

    Interpolating the current timestamp into the first line of the system prompt is a common mistake. Every request then has a different system block, so the hash at the breakpoint never repeats and nothing is ever read. Three fixes look reasonable but fail:

    • A longer TTL keeps an entry that no later request matches.
    • Moving the breakpoint to the final user message still hashes the timestamp.
    • Adding a second breakpoint on the same block fails because lookback only finds entries that earlier requests wrote, and writes happen only at breakpoints.

    The fix is structural. Move the timestamp into the user turn, after the cached content, and keep the breakpoint on the last block that is identical across requests. Breakpoint strategy is covered in more depth in cache breakpoints and reusable packaging.

    An explicit breakpoint on a stable system block, combined with automatic caching for the conversationjson
    {
      "model": "claude-opus-5-5",
      "max_tokens": 1024,
      "cache_control": { "type": "ephemeral" },
      "system": [
        {
          "type": "text",
          "text": "You are a helpful assistant.",
          "cache_control": { "type": "ephemeral" }
        }
      ],
      "messages": [{ "role": "user", "content": "What are the key terms?" }]
    }

    Request parameters belong in the audit too, not just text. Changing tool_choice, adding or removing images, or changing thinking parameters invalidates the messages cache. Changing output_config.effort can invalidate more, depending on the model. A service that varies these settings per call should expect fewer cache hits on the levels they affect.

    Checkpoint 5 of 8· Match them up

    An audit of a cached support service finds four kinds of change between consecutive requests. Match each change to its effect on the prompt cache.

    Tap a term, then the definition that fits it.

    Checkpoint 6 of 8· Exam question

    You run a support assistant on the Messages API. Every request sends 40,000 tokens of tool definitions and policy text, followed by the customer's question. The first line of the system prompt interpolates the current timestamp, and a cache_control breakpoint sits at the end of the system block. Usage shows cache_read_input_tokens is 0 on every call even though calls arrive every few seconds. What change should you make?

    Sources34

    5.Cutting tokens without cutting information

    Once caching is working, the remaining savings come from content the model never needed. Take a claims-triage service that sends 60 tool definitions on every call when a given ticket category uses about six. It also pastes the same compliance instructions into the system prompt and again at the top of every user message. Both are waste, but they are fixed in different ways.

    Fix idle tool definitions by deferring them. If tools are marked as deferred and the tool search tool is added, a definition loads only when a ticket needs it. Deferred tools stay out of the system-prompt prefix, and a discovered tool is appended inline in the conversation, so the cached prefix is untouched. Nothing is lost: every tool is still reachable. The design trade-offs of loading on demand are covered in progressive discovery.

    Fix duplicated instructions by stating them once. Removing the copy from each user message leaves the system prompt as the single statement of the policy. This cut is especially valuable because the copy sat in the per-request part of the prompt, after the cache breakpoint, so it was billed at full input price on every call. At 3,000 tokens × 50,000 calls a day on Claude Sonnet 5.5, that is 150 million tokens, or $300 a day, for information the model already had.

    Two cuts look similar but fail the information test. Replacing the compliance text with a one-line pointer to "standard policy" assumes the model knows your organisation's rules from training. It does not. Reducing each tool description to a one-line label removes the guidance the model uses to pick a tool. Wrong tool selection and incorrect parameters are already the most common tool-use failures. Both cuts save tokens by deleting task-relevant content, and that content is exactly what has to stay.

    Growing conversations accumulate a third kind of waste: old tool results the model has already processed. Clearing them is safe for the task, but clearing invalidates the cached prefix from that point on, so each clear needs to remove enough tokens to justify the new cache write. The mechanisms are covered in context editing and compaction.

    Checkpoint 7 of 8· Check yourself

    In the claims-triage service, each ticket category uses about six of the 60 tool definitions sent on every call. The team wants to stop paying for the idle definitions. Every tool must stay reachable, and the cached prefix must keep getting hits. Which change does that?

    Checkpoint 8 of 8· Exam question

    A claims-triage service on the Messages API handles a high daily call volume. Each request carries 60 tool definitions although a given ticket category uses about six, plus the same compliance instructions pasted into the system prompt and again at the top of every user message. The team must cut input tokens without removing any information the model needs. Choose two.(Select 2)

    0 of 2 selected

    Sources4156

    Sources

    (6)

    Every claim above is drawn from one of these pages, quoted as it was written on the date shown.

    1. 1.
      “As token count grows, accuracy and recall degrade, a phenomenon known as context rot.”
      ↩︎ What a request is made of, and how to measure it
      “the input count is split across input_tokens, cache_read_input_tokens, and cache_creation_input_tokens, and all three count toward the window”
      ↩︎ What a request is made of, and how to measure it
      “A single request to any of them can generate up to 128k output tokens (max_tokens).”
      ↩︎ Pricing a prefix across a call volume
      “defer tool definitions with the tool search tool”
      ↩︎ Cutting tokens without cutting information
      “Everything in the request counts toward the context window: the system prompt, every message in messages”
      ↩︎ Key concept
      “A single request to any of them can generate up to 128k output tokens (max_tokens).”
      ↩︎ Exam trap 1
    2. 2.
      “No, token counting provides an estimate without using caching logic.”
      ↩︎ What a request is made of, and how to measure it
    3. 3.
      “Cache hits and refreshes on Claude Opus 5.5 and Claude Sonnet 5.5 are priced at 0.05x the base input price.”
      ↩︎ Pricing a prefix across a call volume
      “Cache writes: When new content is written to the cache (25 percent more than base input tokens for 5-minute TTL)”
      ↩︎ Pricing a prefix across a call volume
      “You can specify a 1-hour TTL at 2x the base input token price”
      ↩︎ Pricing a prefix across a call volume
      “if both cache_creation_input_tokens and cache_read_input_tokens are 0, the prompt was not cached (likely because it did not meet the minimum length requirement)”
      ↩︎ Reading usage to diagnose a cache that never hits
      “By default, the cache has a 5-minute lifetime. The cache is refreshed for no additional cost each time the cached content is used.”
      ↩︎ Reading usage to diagnose a cache that never hits
      “measured from the start of the request that writes or reads the cache entry”
      ↩︎ Reading usage to diagnose a cache that never hits
      “Cache hits require 100 percent identical prompt segments”
      ↩︎ Reading usage to diagnose a cache that never hits
      “a cache entry only becomes available after the first response starts”
      ↩︎ Reading usage to diagnose a cache that never hits
      “Prompt caching covers the full prefix: tools, system, and messages (in that order), up to and including the block designated with cache_control.”
      ↩︎ Keeping volatile values out of the cached prefix
      “Place cache_control on the last block whose prefix is identical across the requests you want to share a cache.”
      ↩︎ Keeping volatile values out of the cached prefix
      “if both cache_creation_input_tokens and cache_read_input_tokens are 0, the prompt was not cached (likely because it did not meet the minimum length requirement)”
      ↩︎ Exam trap 2
      “It finds entries that prior requests already wrote, and writes occur only at breakpoints.”
      ↩︎ Exam trap 3
      “Claude Sonnet 5.5The best combination of speed and intelligence | $2 / MTok | $10 / MTok | $2.50 / MTok”
      ↩︎ Checkpoint
    4. 4.
      “a change at one level invalidates that level and everything after it”
      ↩︎ Keeping volatile values out of the cached prefix
      “Deferred tools are not included in the system-prompt prefix.”
      ↩︎ Cutting tokens without cutting information
      “The cache follows a prefix hierarchy (tools → system → messages), so a change at one level invalidates that level and everything after it”
      ↩︎ Checkpoint
      “The cache follows a prefix hierarchy (tools → system → messages), so a change at one level invalidates that level and everything after it”
      ↩︎ Checkpoint
    5. 5.
      “context is a finite resource with diminishing returns, and irrelevant content degrades model focus”
      ↩︎ Cutting tokens without cutting information
      “Invalidates cached prompt prefixes when content is cleared.”
      ↩︎ Cutting tokens without cutting information
    6. 6.
      “Claude only sees the tools it actually needs for the current task.”
      ↩︎ Cutting tokens without cutting information
      “The most common failures are wrong tool selection and incorrect parameters”
      ↩︎ Exam trap 4

    Ready to test yourself?

    Practise Anthropic Claude Certified Architect – Professional (CCAR-P) - December 7 onwards in quiz mode.

    Spotted a mistake, or was something unclear? Tell us.