ByteCosts
claude-cache-diagnostics-guide.mdx

AI Coding Agents

Claude API Cache Diagnostics: Find Why Your Cache Missed

Claude API cache diagnostics compares two requests when both opt in and the later request supplies the earlier response ID as previous_message_id. A completed comparison can report the first divergence as a cache_miss_reason such as system_changed, while usage fields show whether any tokens were actually read. As of November 30, 2026, the feature is stable on the Claude API and Claude Models on Google Cloud (Anthropic managed).

When usage.cache_read_input_tokens is zero, the API served no input tokens from cache. To check whether a prefix change caused the miss, opt in on both requests and pass the earlier response’s id as diagnostics.previous_message_id on the second request. If the comparison reports a divergence, use its reason to decide what to inspect first. The fields and availability below reflect Anthropic’s documentation as of November 30, 2026.

What the diagnostics field actually compares

For each request that includes the diagnostics object, the API stores a lightweight fingerprint keyed by the response id. Requests that omit the object store nothing. On your next request, you pass the previous response’s id back as previous_message_id; the API rebuilds the fingerprint for the new request, compares it against the stored one, and attaches a diagnostics object describing the first point of divergence.

Three properties of that fingerprint are documented and worth knowing before you rely on it:

  • It contains only cryptographic hashes and token-count estimates, never raw prompt content.
  • It is scoped to your organization and workspace, and it is not used for any other purpose.
  • It expires after a short period, so run comparisons between closely spaced requests.

The comparison is about request structure, independent of whether the cache actually hit. A matching pair of requests can still miss the cache for reasons diagnostics cannot see, such as an expired entry or a prompt below the minimum cacheable length; the usage-fields matrix below separates those cases.

How to send it: request shape

Include the diagnostics object on every turn. On the first turn, pass "previous_message_id": null to opt in with nothing to compare against. On later turns, pass the id from the previous response. The endpoint is /v1/messages and the Python SDK example uses client.beta.messages.

The illustrative Python below uses the same system instructions and source text for both requests. Supply text with sections the model can summarize. On the Claude API, the Opus 5.5 prefix through the breakpoint must contain at least 512 tokens to be cacheable.

import anthropic

client = anthropic.Anthropic()
SYSTEM = "You are an assistant analyzing a large document. <document>...</document>"  # replace with 512+ tokens of real text

# Turn 1: opt in with previous_message_id=None
r1 = client.beta.messages.create(
    model="claude-opus-5-5",
    max_tokens=1024,
    cache_control={"type": "ephemeral"},
    system=SYSTEM,
    messages=[{"role": "user", "content": "Summarize section 1."}],
    diagnostics={"previous_message_id": None},
)

# Turn 2: reference the previous response id
r2 = client.beta.messages.create(
    model="claude-opus-5-5",
    max_tokens=1024,
    cache_control={"type": "ephemeral"},
    system=SYSTEM,
    messages=[
        {"role": "user", "content": "Summarize section 1."},
        {"role": "assistant", "content": r1.content},
        {"role": "user", "content": "Now summarize section 2."},
    ],
    diagnostics={"previous_message_id": r1.id},
)

print(r2.diagnostics)
print(r2.usage)

The raw HTTP examples send anthropic-version: 2026-10-21 and a diagnostics body field. Anthropic marks the feature stable and shows no dedicated diagnostics beta header in those examples. Keep your active anthropic-beta headers consistent across the pair. Changing those headers between turns can result in unavailable.

In a streaming request, diagnostics appears on the message_start event, so you can log the verdict before the body finishes generating. In a conversation loop, carry the latest response id forward as previous_message_id on every turn, appending the assistant content back verbatim.

How to read the response

The diagnostics field on the response Message has three possible values:

ValueMeaning
nullThe request omitted diagnostics, previous_message_id was null (first turn, nothing to compare), or nothing diverged before the last breakpoint
{"cache_miss_reason": null}The comparison was still running when the response was serialized; this happens when the response starts very quickly. Treat it as inconclusive and check the next turn
{"cache_miss_reason": {...}}A reason is attached. For the *_changed types it names the first divergence point; previous_message_not_found and unavailable mean no comparison was produced

A populated reason looks like this (shape condensed from the doc’s example):

{
  "usage": {
    "input_tokens": 42,
    "cache_read_input_tokens": 0,
    "cache_creation_input_tokens": 41850,
    "output_tokens": 210
  },
  "diagnostics": {
    "cache_miss_reason": {
      "type": "system_changed",
      "cache_missed_input_tokens": 41850
    }
  }
}

The response reports the earliest divergence only. In this example, zero reads and 41,850 write tokens tell you what the cache did on the second request, while system_changed identifies the first difference to inspect. Check the top-level system prompt for per-request values such as timestamps. After moving those values out of the system prompt, send a fresh baseline and compare a follow-up against it. A later divergence can still appear in that new comparison.

The cache_miss_reason types, triaged

cache_miss_reason is a discriminated union on type. Each *_changed type maps to one layer of the tools → system → messages prefix hierarchy, plus the model that sits above all of them.

typeWhat it meansLikely causeFix
model_changedmodel differs from the previous request; the cache is per-modelA router, A/B test or fallback selected a different modelHold the model constant within a cached conversation
system_changedThe system parameter differsA timestamp, request ID or other per-request value interpolated into the system promptMake the system prompt a byte-stable constant; put the changing value in the user message you are about to send
tools_changedThe tools array differs: added, removed, reordered, or input_schema JSON serialized non-deterministicallyTool list built per turn, or map ordering changing JSON key orderSend the same tool list every turn in a fixed order with deterministically serialized schemas, for example sorted keys
messages_changedModel, system and tools match, but an earlier messages entry was altered, reordered or removed rather than appended toHistory truncated or edited; assistant turns or tool_result blocks re-serialized differently on resendTreat history as append-only; echo assistant content and tool results back verbatim
previous_message_not_foundNo stored fingerprint for the supplied previous_message_id; not evidence the request changedPrevious request omitted diagnostics, came from a different workspace, or its fingerprint expiredInclude diagnostics on every turn and keep consecutive turns close together in time
unavailableDiagnostics could not be produced; the request still ran normallymodel, system and tools match but tool_choice, thinking, context_management, output_config, output_format or the active anthropic-beta headers differ; or the divergence sits beyond the comparison horizon in a very long conversationKeep every prompt-affecting parameter constant for the cached conversation’s life; if it persists, run the manual checks under the prompt caching page’s troubleshooting section

Estimating the size and cost of a miss

The four *_changed types carry a cache_missed_input_tokens integer that estimates how many input tokens fell after the divergence point. The API derives this estimate from byte lengths before tokenization. The estimate can differ from, and occasionally exceed, usage.input_tokens, which counts regular input outside cache reads and writes.

A messages_changed reason with a large cache_missed_input_tokens value relative to the prompt suggests the change occurred early in the history. A small estimate suggests the change was late, where an earlier breakpoint may still hit. Check usage.cache_read_input_tokens to confirm reuse and usage.cache_creation_input_tokens to see how many tokens were actually written. When both TTLs are in use, use usage.cache_creation.ephemeral_5m_input_tokens and usage.cache_creation.ephemeral_1h_input_tokens to estimate the write charge at their respective rates.

Reading diagnostics next to the usage fields

diagnostics tells you whether the request changed; usage.cache_read_input_tokens tells you whether the cache hit. The doc’s matrix for turns where you passed a real previous_message_id:

Diagnostics resultCache read tokensInterpretation
nullHighThe cache hit
nullLow or zeroNo divergence was reported before the last breakpoint. Check cache age, breakpoint placement, and the minimum cacheable prefix length
*_changed typeLow or zeroThe request changed; fix the cause type names
*_changed typeHighRare: a late-prompt change where an earlier cache_control breakpoint still hit. Worth fixing, low impact

On the first turn (previous_message_id: null), diagnostics is always null. A cold baseline typically has zero reads, and an eligible breakpoint can produce a write. Apply the matrix to a follow-up with a completed comparison. An inner cache_miss_reason: null means the comparison is pending. The types previous_message_not_found and unavailable indicate that no comparison was produced.

To isolate expiry from a placement problem, use an explicit breakpoint at the end of a stable system prompt that meets the model’s minimum length. Put the changing question after it. First, confirm the baseline wrote tokens through that breakpoint. Send a follow-up within the cache lifetime with the same system content and marker. Time the gap from when the baseline request started, since generating the response uses part of that lifetime. If reads remain at zero, check whether the marker moved or the baseline write was missing before you investigate the new question. The API can only reuse an entry that an earlier request actually wrote.

Limits: scope, retention, horizon, platforms

The documented limitations decide where diagnostics can and cannot help:

  • Same workspace required. The previous request must have run in the same organization and workspace, or the result is previous_message_not_found. On the Claude API, compare the anthropic-workspace-id response header on both responses; on Claude Models on Google Cloud (Anthropic managed), compare the workspace ID in the two request URLs.
  • Limited retention. Fingerprints for previous_message_id lookup expire after a short period; keep the requests you compare close together.
  • Comparison horizon. In very long conversations where the only change is deep in the message list, the response can come back unavailable rather than a precise location.
  • Best effort. Diagnostics never blocks or fails your request; worst case is unavailable or a pending null.
  • Platform availability. As of November 30, 2026, the Messages API table lists the Claude API and Claude Models on Google Cloud (Anthropic managed). It is not available on Managed Agents, and the platform table does not list Amazon Bedrock or the Google-managed variant. The availability section states it works on every model, and the page’s supported-models list runs from the Claude 4.5 generation up through Claude Fable 5.2 and Mythos 5.2.
  • Data handling. Diagnostics is eligible for zero data retention, qualified: your prompts and Claude’s outputs are not stored, only the fingerprint of hashes and token-count estimates, and Covered Models are excluded. It is not HIPAA eligible.

A working triage procedure

  1. Add diagnostics with previous_message_id: null to your conversation’s first request, and thread each response’s id into the next request.
  2. Log cache_read_input_tokens, cache_creation_input_tokens, and input_tokens from usage. Log cache_miss_reason.type when a reason object exists, and cache_missed_input_tokens for *_changed reasons. On streams, read the fields from message_start.
  3. With a prior response ID supplied, an outer diagnostics: null and low reads call for checking cache age, breakpoint placement, and minimum length. An inner cache_miss_reason: null means the comparison was still running. Check the next turn.
  4. Fix the earliest reported divergence. Send a fresh baseline with the fix, compare a follow-up against that baseline, and verify that the cache read count recovered.
  5. If you get previous_message_not_found, verify both requests ran in the same workspace and close together in time; if you get unavailable, audit tool_choice, thinking, context_management, output_config, output_format and beta headers for drift.

What to do next

  • Map each *_changed type to its fix: the Anthropic cache invalidation rules post walks the full hierarchy table so you know what each layer costs to rewrite.
  • If unavailable keeps appearing or you need to see the exact differing bytes, a prefix diff finds what fingerprints only point at.
  • Fold the usage fields into a dashboard: measuring your prompt cache hit rate turns cache_read_input_tokens into a tracked metric.
  • For the quieter causes diagnostics cannot see, the silent cache busters roundup covers expiry, scope and serialization drift.

Sources

How this note was produced

Drafted with AI assistance from committed ByteCosts pricing snapshots and deterministic cost formulas. Figures are grounded in the linked sources (last updated 2026-11-30). Read our editorial & automation policy, inspect the methodology, or report a discrepancy.

Claude API Cache Diagnostics: Find Why Your Cache Missed. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/claude-cache-diagnostics-guide/

Sources