You added cache_control to your requests, deployed, and the bill looks the same. That is the typical failure mode of Claude prompt caching: when a request misses the cache, nothing errors. You just pay full price. This post treats it as a performance investigation: measure first, find the bottleneck, fix it, measure again.

All behavior below comes from Anthropic's prompt caching docs. I give no benchmark numbers of my own; the harness prints yours.

Symptom: caching is on but the bill did not move

The API reports caching only through the usage object on each response. Three fields matter:

  • cache_creation_input_tokens: tokens written to the cache by this request.
  • cache_read_input_tokens: tokens served from the cache.
  • input_tokens: tokens after the last breakpoint, which are not cached.

Total input is the sum of the three. Per the docs, if both cache fields are 0, the prompt was not cached, most often because it is below the minimum length, and no error is returned. Pricing explains why this matters: on the default 5-minute TTL a cache write costs 1.25x base input, and a read costs 0.1x for most models (0.05x for Opus 5.5 and Sonnet 5.5). A prompt that writes on every request is actually more expensive than no caching.

A harness to measure Claude prompt caching

Send the same request twice and print the usage. The first call should write, the second should read.

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic();

export async function probe(system: string, question: string) {
  const started = performance.now();
  const res = await client.messages.create({
    model: "claude-sonnet-5-5",
    max_tokens: 200,
    cache_control: { type: "ephemeral" },
    system,
    messages: [{ role: "user", content: question }],
  });
  const u = res.usage;
  const total =
    u.input_tokens +
    (u.cache_creation_input_tokens ?? 0) +
    (u.cache_read_input_tokens ?? 0);
  return {
    ms: Math.round(performance.now() - started),
    total,
    written: u.cache_creation_input_tokens ?? 0,
    read: u.cache_read_input_tokens ?? 0,
    hitRate: total ? (u.cache_read_input_tokens ?? 0) / total : 0,
  };
}

export async function twice(system: string) {
  console.table([
    await probe(system, "Summarize the rules in one sentence."),
    await probe(system, "List the rules as bullets."),
  ]);
}

The top-level cache_control field is the automatic mode: the breakpoint moves to the last cacheable block as the conversation grows. Explicit breakpoints on content blocks (up to 4 per request) give more control. Note that automatic caching is not available on Amazon Bedrock, which returns a 400 for it.

Baseline run: reading the three input fields

Run twice() against your real system prompt, loaded from the same source your app uses. Healthy output looks like this: row one has a large written and zero read; row two has zero written, a large read, and a hit rate near 1 for the static portion. Note the latency column too, but treat a single run as noise and repeat it several times before drawing conclusions.

If row two shows read: 0, you have a miss. The next three sections are the causes I would check, in order of how cheap they are to test.

Bottleneck 1: the prompt is under the minimum

Minimum cacheable length depends on the model, per the docs:

Minimum tokensModels
512Opus 5.5, Opus 5, Sonnet 5.5, Haiku 5.5, and the Fable 5.x and Mythos 5.x models
1,024Sonnet 5, Sonnet 4.6, Sonnet 4.5, Opus 4.8, Opus 4.1, Opus 4, Sonnet 4
2,048Opus 4.7, Mythos Preview
4,096Opus 4.6, Opus 4.5, Haiku 4.5

This table changes with releases, so verify it on the docs page. A common surprise is switching to a cheaper model for cost reasons and landing in a higher threshold tier. If total in your probe is below your model's minimum, no amount of breakpoint tuning helps; you need a longer static prefix or a different model.

Bottleneck 2: volatile content in the cached prefix

The prefix order is tools, then system, then messages, and a change at one level invalidates it and everything after. Any byte that differs inside the prefix is a miss. The classic offender is a timestamp or request ID in the system prompt:

// Bad: the prefix differs on every request
const system = `Today is ${new Date().toISOString()}.\n${RULES}`;

Reproduce it with the harness: pass this string to twice() and the second row will show no reads. Other documented invalidators include changing tool_choice, adding or removing images, toggling web search or citations, and changing thinking configuration on some models.

Bottleneck 3: the 20-block lookback and unstable ordering

Two subtler causes appear in long agent loops. First, the docs say cache writes happen only at a breakpoint, and on each request the system walks backward at most 20 block positions looking for an earlier write. If a growing conversation pushes your breakpoint 20 or more blocks past the last write, the lookup misses. The fix is a second breakpoint nearer that position so a write exists there.

Second, serialization: key ordering in tool_use JSON matters, and some languages randomize it. If you build tool definitions or tool inputs from objects whose key order varies, sort keys before sending. In Node.js, object key order is insertion order, so a stable build path keeps it stable, but data from sets or merged maps may not be.

Fix and re-measure

Move volatile data out of the prefix and into the user message, after the breakpoint:

const system = RULES; // identical bytes every request

await twice(system);

// dynamic data goes last, in the message, not in the prefix
const question = `Today is ${new Date().toISOString()}. Summarize the rules.`;

Re-run the harness. You should now see read populated on the second row. Compute savings from your own numbers rather than a quoted percentage: multiply read tokens by 0.1 (or 0.05, depending on model) of the base input price, and written tokens by 1.25, then compare with total tokens at the base price. Latency should improve too, but only trust a median over many runs.

Choosing a 5-minute or 1-hour TTL

The default 5-minute lifetime refreshes for free on each hit, so a busy endpoint stays warm. If traffic is sparse and requests arrive more than five minutes apart, entries expire between calls and every request pays the 1.25x write. A 1-hour TTL (cache_control: { type: "ephemeral", ttl: "1h" }) costs 2x on write. As a rule of thumb from those multipliers, the longer TTL pays off only if it turns enough would-be writes into reads. Also note the lifetime is measured from the start of the request, and when you mix TTLs, 1-hour entries must come before 5-minute ones.

Keep measuring in production

Misses are silent, so log the usage fields on every call and alert when hit rate drops after a deploy. If you already propagate request context, AsyncLocalStorage is a convenient place to attach the numbers to a request ID. If you run agents through tools, the MCP server guide is relevant because tool definitions are the first thing in the cached prefix; keep them stable.

Next steps: run the probe against your real prompt, fix whichever of the three bottlenecks it reveals, and add the hit-rate log line before you touch anything else.