Certopolis

Claude Certified Architect – Foundations

Claude prompt caching: cache_control, TTL and pricing

Prompt caching lets Claude reuse the processed prefix of a request instead of reading it again. Mark the end of the stable part with cache_control: {"type": "ephemeral"}, and later requests that start with exactly the same content read it from the cache at a fraction of the input price.

How it works

The cached prefix is built from tools, then system, then messages, up to and including the block that carries cache_control. Put stable content first and anything that changes per request after the breakpoint. Matching is exact, so one changed byte before the breakpoint means a miss.

You can use automatic caching, a single top-level cache_control field that moves the breakpoint forward as a conversation grows, or explicit breakpoints on individual blocks. A request can have up to 4 breakpoints. For each one, the API looks back at most 20 positions for an entry an earlier request wrote.

Prompts shorter than the model minimum are processed without caching and with no error. The minimum is 512 tokens on Claude Opus 5 and Opus 5.5, 1,024 on Sonnet 5 and Sonnet 4.6, and 4,096 on Haiku 4.5.

Lifetime and price

The default lifetime is 5 minutes. Add "ttl": "1h" for one hour. Each hit resets the timer at no extra cost. A 5-minute write costs 1.25x the base input price, a 1-hour write costs 2x, and a read costs 0.1x on most models. On Opus 5.5 and Sonnet 5.5 a read costs 0.05x.

A cache entry becomes readable only after the first response starts. If you send 20 requests with the same prefix at the same moment, all 20 write and none read. Send one first, wait for it to start responding, then send the rest.

Reading the usage fields

cache_read_input_tokens is what came from the cache, cache_creation_input_tokens is what was written, and input_tokens is only the tokens after the last breakpoint. Total input is the sum of all three. A request with 18,000 read, 2,000 written and 350 uncached consumed 20,350 input tokens.

Where the exam catches people

  • Believing input_tokens is the whole prompt: with caching it counts only the tokens after the last breakpoint.
  • Believing parallel requests share a fresh entry: the entry is readable only once the first response has started.
  • Believing a short prompt that never caches is an error: below the model minimum the request simply runs uncached.
  • Believing the order is system, tools, messages: the prefix is tools, then system, then messages.

Written from Anthropic's documentation

Try 3 questions on this

Pick an answer to see why each option is right or wrong.

  1. Your team logs usage.input_tokens from every response and treats it as the total input size of the request. Against a 200,000-token cached document plus a short question, the logged figure is about 50 tokens, and your team's context-growth dashboard reads near zero. Which approach should you take to compute total input tokens from the usage object?

    Right. In the game that’s Renown for your Context Management and Reliability building.

    Not that one: A is right. In the game your Context Management and Reliability building would lose a little Renown, and this question would come back later.

  2. You batch 30,000 requests that all share a 60,000-token reference corpus, marked with a default cache_control breakpoint. The batch takes about forty minutes to work through, and the observed cache hit rate is far lower than expected. What change would most effectively improve the hit rate?

    Right. In the game that’s Renown for your Context Management and Reliability building.

    Not that one: D is right. In the game your Context Management and Reliability building would lose a little Renown, and this question would come back later.

  3. You design the prompt layout for a multi-tenant assistant on Claude Opus 5 (claude-opus-5). Each request carries a frozen 8,000-token instruction set, a per-tenant style guide that changes weekly, and the user's question. Your design must maximize prompt-cache reuse across tenants. Which approach should you take to order these segments and meet these requirements?

    Right. In the game that’s Renown for your Prompt Engineering, Structured Output and Retrieval building.

    Not that one: A is right. In the game your Prompt Engineering, Structured Output and Retrieval building would lose a little Renown, and this question would come back later.

    Show the full explanation and doc quotes

    Frozen instructions first give every tenant a shared cached prefix; the weekly style guide forms a second, per-tenant layer; the question comes last, after the final breakpoint, where it invalidates nothing.

    Written from platform.claude.com/docs/en/build-with-claude/prompt-caching