Prompt caching not working? A checklist for Claude and OpenAI
A cache only hits when the start of the prompt is identical to a cached one, byte for byte, within its lifetime. When cached tokens stay at 0, the usual causes are 7 things: a prompt below the minimum, something that changes near the top, a tool or setting change, key order in JSON, an expired entry, the wrong breakpoint, or traffic spread too thin. How to find which, with the fields that prove it.
Tecyfy · Published · 8 min read

When prompt caching works, cached input costs a tenth of the normal price or less on Claude and on OpenAI's GPT-5.6 and later (earlier OpenAI models have their own cached rate) on Claude and on OpenAI's GPT-5.6 and later (earlier OpenAI models have their own cached rate), and long prompts start answering sooner. When it does not, nothing tells you, because a miss is not an error. The request goes through at full price. A cache hits only when the start of your prompt is identical, byte for byte, to a prompt cached recently. Every cause of a miss comes back to that rule.
First, measure it
You cannot fix what you are not logging. Each response says what happened:
| A hit | A write | Read from | |
|---|---|---|---|
| Claude | cache_read_input_tokens > 0 | cache_creation_input_tokens > 0 | usage |
| OpenAI | cached_tokens > 0 | cache_write_tokens > 0 (GPT-5.6 and later) | usage.input_tokens_details |
On Claude, these 2 numbers plus input_tokens add up to the whole input. If reads stay at 0 while writes keep appearing, you are paying to write a cache nobody reads, which costs more than no cache at all.
See where your prompt breaks
A prompt is cached as a prefix: tools, then the system prompt, then the messages. Change one block below and see how much of the cache survives:
The cache breaks at "System prompt" and everything after it is paid in full: 7,300 of 9,300 tokens. The request costs 81% of the no-cache price, against 13% when nothing changes. Move the date to the end, after the cached part.
Claude caches the prompt as a prefix in this order: tools, system prompt, messages. A cache read costs a tenth of the normal input price; the sizes here are an example.
The 7 causes, in the order to check them
1. The prompt is too short. Below the minimum, nothing is cached and there is no error. On Claude the minimum is 512 tokens on the newest models (Opus 5.5, Sonnet 5.5, Haiku 5.5), 1,024 on Sonnet 4.5 and 4.6, and 4,096 on Opus 4.5 and Haiku 4.5. On OpenAI it is 1,024 visible input tokens for GPT-5.6 and later; on earlier models it varies with the request's settings. A 900-token system prompt caches on Sonnet 5.5 and never on Haiku 4.5.
2. Something changes near the top. A date, a user's name, a request ID or a "current time" line in the system prompt makes every prompt unique from that point on. Move anything that varies to the end, after the part you want cached.
3. The tools or settings changed. Tools sit at the very start of the prefix. Add a tool for one user, reorder the list, or edit one description, and on Claude the whole cache is gone. On Claude, changing tool_choice, images or the thinking and effort settings drops the message part of the cache. On OpenAI, the tools, the output schema, the model, parallel_tool_calls and reasoning effort must all match.
4. JSON keys come out in a different order. Identical data serialised as {"a":1,"b":2} one time and {"b":2,"a":1} the next is a different prompt. Anthropic warns that Swift and Go can randomise key order. Sort keys when you build tool schemas or JSON you put in the prompt.
5. The entry expired. Claude's default cache lives 5 minutes, refreshed for free each time it is read; the 1-hour cache costs more to write. A request every 10 minutes misses the 5-minute cache every time. On OpenAI's GPT-5.6 and later you choose a minimum lifetime of 30 minutes (the default) or 12 hours; earlier models use prompt_cache_retention, with entries kept up to 24 hours on 24h; when the 12-hour cache pays works out that trade.
6. On Claude, the breakpoint is in the wrong place. Caching caches up to a cache_control breakpoint. Put it on a block that changes every turn and nothing before it gets reused; put it too far down a long conversation and the 20-block lookback may not reach the earlier cached prefix. Breakpoints go on the last block that stays the same, and you may use up to 4.
7. On OpenAI, traffic is spread too thin, or too thick. OpenAI routes by a hash of the start of the prompt. On models before GPT-5.6, use a stable prompt_cache_key to keep requests that share a prefix together; GPT-5.6 and later route automatically. Above about 15 requests a minute in total on one key, across all its prefixes, requests can overflow to other machines that have not cached it yet.
Let the API tell you why
On the Claude API you do not have to guess. Send diagnostics with the ID of the previous response, null on the first turn:
first = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=1024,
system=SYSTEM_PROMPT,
messages=messages,
diagnostics={"previous_message_id": None},
)
second = client.messages.create(
model="claude-sonnet-5-5",
max_tokens=1024,
system=SYSTEM_PROMPT,
messages=messages + more,
diagnostics={"previous_message_id": first.id},
)
if second.diagnostics is None:
print("No divergence detected.")
elif second.diagnostics.cache_miss_reason is None:
print("Comparison still pending.")
else:
print(second.diagnostics.cache_miss_reason.type)
The reason is the first point where the prompt diverged, model_changed, system_changed, tools_changed or messages_changed, or previous_message_not_found or unavailable when no comparison was made, with the number of input tokens that missed. If it says nothing diverged and cache reads are still low, the entry expired: cause 5. On OpenAI, the Prompt Cache Diagnostics tool diagnoses misses, and the Prompt Caching Dashboard shows hit rates.
After it works
Caching saves money on the bill, and on Claude it also raises how much you can send: cache reads do not count toward the input-tokens-per-minute limit on most models (see LLM API rate limits). On OpenAI, cached tokens still count toward the limit.
To see what a working cache is worth for your traffic, our prompt caching calculator prices the same prompt with no cache, the 5-minute and the 1-hour cache on each Claude model. The prompt cachingPrompt CachingLetting the API keep the processed start of a prompt for a few minutes, so later requests that begin the same way are cheaper and quicker. concept page explains the mechanism from the start.
Questions
- Why is my prompt cache not hitting?
- A cache hit needs the start of the prompt to match a cached prompt exactly, within the cache lifetime. The usual causes of a miss are a prompt shorter than the minimum, something that changes early in the prompt (a timestamp, a user name, a request ID), a change to the tools or settings, JSON keys serialised in a different order, an entry that expired, or on Claude a missing or misplaced cache_control breakpoint.
- How do I check if prompt caching is working?
- Read the usage block of each response. On Claude, cache_read_input_tokens above 0 is a hit and cache_creation_input_tokens is a write. On OpenAI, usage.input_tokens_details.cached_tokens above 0 is a hit. Log these per request and the hit rate shows at once.
- What is the minimum prompt length for caching?
- On the newest Claude models, including Opus 5.5, Sonnet 5.5 and Haiku 5.5, 512 tokens; on Sonnet 4.5, Sonnet 4.6 and Opus 4.8, 1,024; on Opus 4.5 and 4.6 and Haiku 4.5, 4,096. OpenAI caches prompts of 1,024 tokens or more on GPT-5.6 and later; on earlier models the minimum varies with request settings. A shorter prompt is processed normally with nothing cached and no error.
- Does changing the tools break the prompt cache?
- Yes on both. Tools come first in the prompt, so on Claude a change to the tool definitions invalidates the whole cache. On OpenAI, the tools, the structured output schema, the model and settings such as reasoning effort are part of the cached prefix, so changing any of them can cause a miss (on GPT-6 models, a configuration_update item changes reasoning effort without rewriting the prefix).
- What is Claude's cache diagnostics feature?
- On the Claude API, send diagnostics with previous_message_id set to the previous response's ID, or null on the first turn. If the request missed the cache, the response says why in diagnostics.cache_miss_reason: the first divergence (model_changed, system_changed, tools_changed or messages_changed), or previous_message_not_found or unavailable when no comparison was made, with the number of input tokens that missed.
Sources