Skip to main content
Claude AI

Claude Prompt Caching Not Hitting? Place cache_control Breakpoints Correctly and Prove Hits with Usage Fields

Find out why Claude prompt caching misses, where to place cache_control breakpoints, and how to confirm hits and estimate savings from the usage fields.

10 min
Temps de lecture
1,934
Mots
Publié
Engr Mejba Ahmed

Écrit par

Engr Mejba Ahmed

Partager l'article

Claude Prompt Caching Not Hitting? Place cache_control Breakpoints Correctly and Prove Hits with Usage Fields

If your Claude prompt caching setup shows almost no cache reads, the cause is usually where the breakpoint sits, not whether caching is turned on. Claude caches a hash of everything up to a marked block. If anything at or before that block changes between requests, the hash changes and the request pays for a new write instead of a read. Most fixes come down to three steps: move the breakpoint, keep the prefix byte-identical, and confirm the result in the usage fields.

For background, see Claude Prompt Caching: 90% Cheaper, Same Quality.

Why Your Claude Prompt Cache Isn't Hitting: The Prefix Hash

According to the prompt caching documentation, caching covers the full prefix in a fixed order: tools, then system, then messages, up to and including the block marked with cache_control. Three rules decide whether that prefix hits.

Writes happen only at the breakpoint. Marking a block with cache_control writes exactly one cache entry, a hash of the prefix ending at that block. No entries are written at earlier positions. The hash is cumulative, so changing any block at or before the breakpoint produces a different hash on the next request.

Reads look backward for prior writes. On each request, the system computes the hash at your breakpoint. If no entry matches, it walks back one block at a time and checks whether an earlier request wrote an entry at that position. It looks for entries that already exist. It does not detect content that happens to be stable.

The lookback is 20 blocks. At most 20 positions are checked per breakpoint, counting the breakpoint itself. On the Claude API, a run of consecutive tool_use blocks counts as one position, and so does a run of consecutive tool_result blocks. In a growing conversation, a breakpoint on the final block works as long as each turn adds fewer than 20 blocks. If a turn adds more, the previous entry falls outside the window. A second breakpoint placed closer to that entry starts a second lookback window.

The documentation describes a common mistake that produces zero hits. The prompt has a large static system context (blocks 1 to 5), followed by a block containing a timestamp and the user message (block 6). With cache_control on block 6, every request hashes a new timestamp. The lookback walks through blocks 5 to 1 but finds nothing, because no request ever wrote an entry there. You pay for a cache write on every request and never get a read. Automatic caching fails the same way in this structure, because it places the breakpoint on the last cacheable block, which is the one that changes. The fix is an explicit breakpoint on the last block that stays the same.

# Broken: breakpoint on the block that changes every request
broken_messages = [{
    "role": "user",
    "content": [{
        "type": "text",
        "text": f"Now: {now_iso}\nUser {user_id}: {question}",
        "cache_control": {"type": "ephemeral"},
    }],
}]

# Fixed: breakpoint on the last static block, volatile data after it
system = [
    {"type": "text", "text": ROLE_INSTRUCTIONS},
    {
        "type": "text",
        "text": POLICY_DOCUMENT,  # large and identical on every request
        "cache_control": {"type": "ephemeral"},
    },
]
messages = [{
    "role": "user",
    "content": f"Now: {now_iso}\nUser {user_id}: {question}",  # no marker
}]

A safe default is to put anything per-request after the breakpoint. That includes dates, user IDs, retrieval results and the incoming question. Tool definitions come first in the prefix, so a tool list that varies by user or feature flag invalidates everything after it.

Two rows of stacked blocks compared side by side. The static blocks match, but a timestamp block on top differs, so the hash at the breakpoint no longer matches.

Silent Misses: Minimum Length, TTL, Concurrency and Parameter Drift

Some misses produce no error at all. The prompt caching documentation lists several causes. They map onto this checklist:

Symptom Cause Fix
Both cache fields are 0, no error Prefix is below the model's minimum cacheable length Check your model's tier (below) and expand the cached content if you are just short
Hits stop after long responses TTL is measured from the start of the request, not the end of the response Account for generation time, or use the 1-hour TTL
Parallel requests all write, none read An entry becomes available only after the first response starts Send one request, wait for its response to start, then fan out
Hits stop after a config change tool_choice, image usage, thinking configuration or output_config.effort differ between calls Keep these consistent per route
Random misses from Go or Swift services Key order in tool_use blocks is randomized during JSON conversion Serialize with stable key ordering
Same prompt, different teams, no shared hits Caches are isolated per workspace on the Claude API, Claude Platform on AWS and Microsoft Foundry Route traffic that shares a prefix through one workspace

Minimum lengths are per model. On the Claude API, Claude Platform on AWS, Claude Models on Google Cloud (Google managed) and Microsoft Foundry, the documented minimums are:

  • 512 tokens for Claude Fable 5.2, Mythos 5.2, Fable 5.1, Mythos 5.1, Opus 5.5, Opus 5, Sonnet 5.5, Fable 5, Mythos 5 and Haiku 5.5.
  • 1,024 tokens for Claude Sonnet 5, Opus 4.8, Sonnet 4.6, Sonnet 4.5, Opus 4.1, Opus 4 and Sonnet 4.
  • 2,048 tokens for Claude Mythos Preview and Opus 4.7.
  • 4,096 tokens for Claude Opus 4.6, Opus 4.5 and Haiku 4.5.

Not every 5.x model is in the 512 tier. Claude Sonnet 5 needs 1,024 tokens, so a 700-token system prompt that caches on Sonnet 5.5 will silently skip caching on Sonnet 5. Amazon Bedrock documents its own minimums, failure behavior and usage-field names, so check the Bedrock prompt caching documentation if you deploy there.

The TTL window shrinks while you stream. The default lifetime is 5 minutes, and each use refreshes it at no extra cost. The clock starts when the request begins. The documentation's example: if a response takes 4 minutes to stream, the follow-up request must start within about 1 minute of that response completing. The 1-hour TTL ("cache_control": {"type": "ephemeral", "ttl": "1h"}) avoids this, but its writes cost 2x the base input price instead of 1.25x. It pays off only when the gaps between requests regularly exceed 5 minutes.

Thinking adds another model-specific variable. Depending on the model, earlier thinking blocks either stay in the cached prefix or are removed when a non-tool-result user turn arrives. Check the thinking section of the caching docs for your model rather than assuming one behavior.

Prove Hits from the Usage Fields (and Ask the API Why It Missed)

Every response reports three fields in usage (or in the message_start event when streaming), as described in the prompt caching documentation:

  • cache_creation_input_tokens: tokens written to the cache by this request
  • cache_read_input_tokens: tokens read from the cache
  • input_tokens: tokens after the last breakpoint only, not your full input

Total input is cache_read_input_tokens + cache_creation_input_tokens + input_tokens. If both cache fields are 0, the request was not cached. A dashboard that charts only input_tokens will make caching look far more effective than it is, because that field excludes everything before the breakpoint.

This classifier turns the fields into a status you can log per feature:

def classify_cache(usage):
    read = usage.cache_read_input_tokens or 0
    created = usage.cache_creation_input_tokens or 0
    uncached = usage.input_tokens or 0
    total = read + created + uncached

    if read > 0 and created == 0:
        status = "hit"
    elif read > 0 and created > 0:
        status = "partial"    # read an earlier entry, wrote a longer one
    elif created > 0:
        status = "write"      # paid 1.25x or 2x, no read yet
    else:
        status = "uncached"   # below minimum or no breakpoint

    read_ratio = read / total if total else 0.0
    return status, read_ratio

status, ratio = classify_cache(response.usage)
log.info("cache", route=route_name, status=status, read_ratio=round(ratio, 3))

A practical alert is a read ratio that stays near 0 on a route with a large static prefix. A stream of write statuses with no hit points to a volatile breakpoint. A stream of uncached points to the minimum-length tier.

To find out why a specific request missed, the Messages API accepts diagnostics.previous_message_id. Set it to the msg_... id of this client's previous response. The server compares that request's prompt fingerprint with the current one and returns diagnostics.cache_miss_reason when the cached prefix could not be reused. Pass null on the first turn to opt in without a prior message. A null value for cache_miss_reason in the response means the comparison was still pending when the response was serialized, so log it and do not treat it as a hit.

If your Claude calls run in background workers, logging these fields belongs in the job itself. For related setup, see Why Laravel Queue Workers Kill Long Claude Calls: Aligning HTTP Timeouts, Job Timeout and retry_after.

A bar divided into three colored segments representing cache read, cache write and uncached input tokens, with a status gauge classifying the request.

Estimate Savings with the Documented Multipliers

The pricing page gives the multipliers relative to base input price:

  • 5-minute cache write: 1.25x
  • 1-hour cache write: 2x
  • Cache read: 0.1x on most models, 0.05x on Claude Opus 5.5 and Sonnet 5.5, and 0.025x on Fable 5.2, Mythos 5.2, Fable 5.1 and Mythos 5.1

It also states the break-even: caching saves money after one cache read with the 5-minute duration and after two reads with the 1-hour duration.

Per request, cost is:

cost = write_tokens × write_mult × base
     + read_tokens × read_mult × base
     + input_tokens × base

The following is worked arithmetic from list prices, not a measurement. Claude Sonnet 5.5 has a base input price of $2 per million tokens. A 10,000-token prefix costs $0.02 uncached, $0.025 to write with the 5-minute TTL, and $0.001 to read at 0.05x. If one request writes and nine read within the TTL, the prefix costs $0.025 + 9 × $0.001 = $0.034. Sending it uncached ten times costs $0.20. If those same ten requests keep missing because of a timestamped breakpoint, you pay $0.25. That is more than not caching at all, which is why verifying hits matters as much as enabling caching.

These multipliers stack with the Batch API discount, long context pricing and data residency. On a model priced by prompt length, such as Claude Haiku 5.5, cache reads and writes count toward the request's prompt length, so include them when you work out which price tier applies.

For a wider view of cost levers, see Reduce Claude API Costs: A Per-Feature Audit with Batches, Model Routing and Caching.

FAQ

Why are both cache fields 0? The documentation says this most likely means the prefix is below the model's minimum cacheable length. Check your model's tier: Claude Sonnet 5 needs 1,024 tokens even though Sonnet 5.5 needs 512. Also confirm that a breakpoint is actually set.

Should I use automatic caching or explicit breakpoints? The docs recommend starting with automatic caching for multi-turn conversations. Use an explicit breakpoint when a per-request block follows your static content, because automatic caching would place the breakpoint on that changing block.

Do extra breakpoints cost more? No. Breakpoints themselves add no cost. You pay for what is written, read and left uncached.

Why do my parallel requests all miss? A cache entry becomes available only after the first response starts. Wait for that response before sending the rest.

Do different organizations share caches for identical prompts? No. Caches never cross organizations, and on the Claude API they are also isolated per workspace.

Run a One-Day Cache Audit on Your Busiest Route

  1. Pick the route with the largest static prefix (tools plus system prompt plus reference documents).
  2. Confirm the prefix meets your model's minimum: 512, 1,024, 2,048 or 4,096 tokens depending on the model.
  3. Move timestamps, user IDs and retrieval results after the breakpoint, and keep tool_choice, thinking and effort settings fixed for that route.
  4. Log the three usage fields, the classifier status and cache_miss_reason for 24 hours.
  5. Compute the read ratio and plug the token counts into the cost formula. If you see mostly write statuses, move the breakpoint. If you see mostly uncached, expand the prefix or check the tier.

If you'd rather have a team handle this, see Custom AI Web App & SaaS MVP — Next.js, OpenAI & Claude.

Coffee cup

Vous avez apprécié cet article ?

Votre soutien m'aide à créer davantage de contenu technique approfondi, d'outils open source et de ressources gratuites pour la communauté des développeurs.

Sujets connexes

Engr Mejba Ahmed

Engr Mejba Ahmed

Engr. Mejba Ahmed builds AI-powered applications and secure cloud systems for businesses worldwide. With 8+ years shipping production software in Laravel, Python, and AWS, he's helped companies automate workflows, reduce infrastructure costs, and scale without security headaches. He writes about practical AI integration, cloud architecture, and developer productivity.

Articles connexes

Tout parcourir

Comments

Leave a Comment

Share a question or add to the discussion.

Comments are moderated before appearing.

Learning Resources

Expand Your Knowledge

Accelerate your growth with structured courses, verified certificates, interactive flashcards, and production-ready AI agent skills.

Sample Certificate of Completion

Sample certificate — complete any course to earn yours

Engr Mejba Ahmed

Engr Mejba Ahmed

AI assistant · trained on my work

👋

Hey there!

Quick Actions

WhatsApp Direct line to me

Chat on WhatsApp

+880 1723 741224 · Replies within the hour on working days

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

mejba.13@gmail.com

✓ Details sent! I'll get back to you shortly.

Powered by Claude

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support