Providers charge a fraction of the normal price for input they've seen before. One changing line near the top of your request can forfeit that discount without raising a single error.
- Prompt caches match from the first token forward, so an edit early in a request discards everything that follows it
- Claude's minimum cacheable prompt ranges from 512 to 4,096 tokens depending on the model, and shorter prompts skip caching with no error
- ProjectDiscovery's weekly cache hit rate jumped from 7.6% to 73.7% after it moved changing context to the end of its prompt
- Claude's cache lifetime counts from the start of a request, so slow responses eat into the time left for the next call
- A study of 120 caching defects in open-source agent software found that 108 of them failed silently
- Sending parallel requests before the first response begins can leave all of them paying for a cold cache
A 20,000-token system prompt sent 1,000 times to Claude Sonnet 5.5 costs $40 at the normal input rate. With a five-minute cache and steady traffic, the same input costs about $2.05. Now put a to-the-second timestamp on the first line and leave caching switched on. The bill goes to $50, because every request pays to write a cache entry that nobody will ever read. So if you're asking why is my prompt cache hit rate low, begin at the top of your request and read downward.
Those sums use Anthropic's published prices per million tokens: $2 for ordinary input, $2.50 for a five-minute cache write and $0.10 for a cache read. Output is billed the same either way. Nothing crashes and the answers read fine. You just pay more than you should, and you lose the faster responses a warm cache gives you.
Before a model writes anything back, it has to process every token you sent. A prompt cache holds on to that processed state for a while, so a later request that begins the same way can skip the work. Matching runs from the first token forward and stops at the first difference. Anthropic's documentation says a hit requires 100 percent identical segments, and OpenAI's says the entire rendered prefix has to match. Change one character on line one and the thousands of untouched tokens behind it get processed all over again.
Order counts too. Claude builds the prefix from your tool definitions, then the system prompt, then the messages, so rewording one tool description invalidates all three layers.
How Does AI Agent Memory Work Across Sessions, and Why It Keeps Failing How does AI agent memory work across sessions? It doesn't, not really: what looks like memory is a context window, a vector database, and a summarizer passing notes to each other between calls. This guide breaks down each piece, where it fails, and how companies like Letta, Mem0, and OpenAI are patching around the gaps. - how AI agents remember information between conversations - why AI agent memory systems fail in production
Switching it on varies. OpenAI caches by default on supported models, and Google enables what it calls implicit caching on Gemini 2.5 and newer. Claude waits to be asked. You add a cache_control marker to a content block, or set it once at the top level of the request and let the API move the breakpoint forward as a conversation grows. Skip both and you'll never see a hit.
Cached input tokens showing zero #
Read the usage object before you touch the prompt. Claude reports cache_read_input_tokens and cache_creation_input_tokens, while plain input_tokens counts only what comes after your last breakpoint. Add all three for total input, then divide reads by that total to get a hit rate weighted by tokens. OpenAI's Responses API puts cached_tokens inside input_tokens_details, joined by cache_write_tokens on GPT-5.6 and later. Chat Completions code looks under prompt_tokens_details. On Gemini, check for cachedContentTokenCount in generateContent responses, or total_cached_tokens in the Interactions API.
The pattern of zeros narrows things down. When both Claude cache fields read zero, you've either set no marker or your prompt is too short. A short prompt is processed normally and returns no warning. The floor is 512 tokens on Sonnet 5.5, Opus 5.5 and Haiku 5.5, 1,024 on Sonnet 5 and Sonnet 4.6, and 4,096 on Haiku 4.5 and Opus 4.6. Move a 2,000-token classifier from Sonnet 5.5 to the older Haiku 4.5 and its caching simply stops.
OpenAI requires 1,024 visible input tokens on GPT-5.6 and later. Its guide says the threshold on earlier models varies with request settings, and their cached counts round down to a multiple of 128. Google's table asks for 4,096 tokens on Gemini 4 models and Gemini 3.8 Flash, and 2,048 on Gemini 2.5 Pro and Flash.
Writes with no reads mean you're creating entries and never finding them. Suspect a changing prefix, an expired entry or a badly placed breakpoint. The first request on a new prefix will often look this way, so judge the second.
Sometimes the fault is in your own code. Ying Zhang and six co-authors posted a study to arXiv in October covering 120 caching defects that had been fixed in 10 popular open-source agent systems, and found that 108 failed silently. In 23 cases, the software miscounted cache usage. Another 37 came from code that used the model's name to decide how to handle caching, so retest yours whenever you upgrade.
Why is my prompt cache hit rate low when the prompt looks unchanged? #
The text you wrote and the bytes you send aren't always identical. The clock is a classic culprit. Yichao "Peak" Ji of the agent company Manus called the cache hit rate "the single most important metric for a production-stage AI agent" in a July 2025 post, and named a timestamp at the start of the system prompt as a common mistake, especially one precise to the second. A request ID or a user's name in that position does the same damage.
How to handle LLM API rate limits in production before retries burn your quota A 400,000 tokens-per-minute cap, minus 20% held back as headroom, leaves 320,000 to plan against. Splitting that into lanes puts 96,000 on user-facing calls, and a background step costing 18,000 tokens supports only about twelve steps a minute. - how to handle LLM API rate limits - prevent retries from burning API quota
ProjectDiscovery ran into a bigger version on Neo, its autonomous security testing platform. According to an April 2026 write-up by the company and Parth Malhotra, working memory, relevant skills and runtime context sat inside the stretch of prompt that was supposed to be cached. "Working memory changes on nearly every step. This was silently killing our cache hits," the post says. The team moved the changing material into a user message at the tail, swapped per-user template variables for fixed placeholders, and set the date once per task with no time of day. The weekly hit rate jumped from 7.6% in the week of 9 February to 73.7% the next week. It reached 85% in late March, and the company put its overall cost saving at 59%.
Check your tool list next. If it's assembled from a plugin registry, an unordered set or several discovery calls that finish at random, its order can shift between requests. Thariq Shihipar of Anthropic named shuffled tool order as one thing that broke caching in Claude Code, along with a detailed timestamp in the static system prompt and changes to a tool's parameters. Sort tools by name, and don't let a description pull in anything live.
JSON can catch you out without a visible change. Manus warned that many languages and libraries don't guarantee stable key order, and Anthropic's docs single out Swift and Go for randomizing keys in tool_use blocks. In Python, passing sort_keys=True to json.dumps fixes the order for objects you serialize yourself. In any language, capture the outgoing bodies of two calls that should share a prefix and compare them byte by byte.
Request settings can break a match even when every word is the same. On Claude, adding or removing an image anywhere, or changing tool_choice, invalidates the cached messages but leaves tools and system prompt intact. Toggling web search, citations or speed mode takes the system prompt down as well, and the effect of thinking and effort settings depends on the model. OpenAI's list includes parallel_tool_calls, the structured output schema, reasoning effort, verbosity and context compaction. Changing models mid-conversation starts cold, so a router that hands turn six to a cheaper model can end up costing you more than staying put.
Prompt caching not working in production #
Your test script passes because it fires two identical requests a few seconds apart. Real users take their time.
Claude's default entry lasts five minutes and is refreshed at no charge whenever it's used. Anthropic measures that lifetime "from the start of the request that writes or reads the cache entry, not from the end of its response." An agent step that spends four minutes generating leaves one minute for the next call. A support chat where customers reply after seven minutes will keep missing.
The one-hour option covers that gap at a higher write price, twice the base input rate. On Sonnet 5.5, writing once and reusing once costs 2.05 times the base price of that prefix, against 2 times without caching, so you need a second read to come out ahead. The five-minute write pays for itself on the first. You can also hold a prefix warm by sending a request with max_tokens set to 0, which loads the cache and generates nothing.
OpenAI's retention depends on the model generation. GPT-5.6 and later keep entries for at least 30 minutes by default, with a 12-hour option on the Responses API that raises the write price from 1.25 times input to 2.5 times. On older models, in-memory entries usually survive five to 10 idle minutes and never more than an hour. Extended 24-hour retention is the default there for organizations without Zero Data Retention.
Batch jobs hit a different wall. A Claude cache entry "only becomes available after the first response starts," the docs say. Fire 50 questions about the same contract at once and you can pay the write premium 50 times. Send one, wait until it begins to answer, then release the other 49.
On OpenAI models older than GPT-5.6, busy traffic can spill past a single machine. Requests are routed using load, a hash of the opening tokens and an optional prompt_cache_key, and OpenAI suggests aiming for about 15 requests per minute on each key. Spread heavier volume over several keys that stay fixed for each group of users. No key guarantees a hit.
Separate accounts mean separate caches. Claude never shares them between organizations, and its own API also walls them off by workspace. Failing over to another cloud starts you cold too. ProjectDiscovery sends its traffic to Anthropic directly and keeps Bedrock and Vertex for outages.
How to structure prompts for prompt caching #
Arrange everything by how often it changes. Tools and instructions shared by every user go first. Material shared by one project or customer follows, then details fixed for a session, then the conversation, with the newest input at the very end. Shihipar describes Claude Code in much those terms: static system prompt and tools, the CLAUDE.md project file, session context, and finally the messages.
When a fact changes mid-session, add a message and leave the system prompt alone. Claude Code passes along updates such as the time in a tagged reminder inside the next user message or tool result. Keep the history append-only, as Manus advises.
Don't strip tools out to enforce an agent mode. Claude Code's plan mode keeps every definition in place, makes entering and leaving the mode tools of their own, and explains the rules in a message. Manus chose another route and masks token logits, which blocks certain actions while the definitions stay untouched. Summarizing a long history needs the same care: Claude Code makes that call with the same system prompt and tools, appending the summary request as a new message so it can read the existing cache.
Claude gives you up to four breakpoints. Put one on the last block that stays identical between requests, never on the block holding a timestamp or the new question. The API writes entries only at breakpoints and looks back no more than 20 blocks for one written earlier. A long agent turn can leap past that window, so add a marker partway. ProjectDiscovery spaced its extra ones every 18 blocks. If you mix lifetimes, the one-hour entries must come first. On GPT-5.6 and later, requests that share instructions but end differently should carry an explicit breakpoint where the shared text stops.
A debugging checklist for a low hit rate #
Start with two requests that ought to share a prefix. Confirm the shared part clears your model's minimum and, on Claude, that it carries a breakpoint. Send the first, wait for the response to begin, send the second and read the usage fields.
If the second shows no read, compare the raw bodies. Look for times and IDs, then tool order and JSON key order, then the model and settings. Claude's cache diagnostics can do some of this for you: send a `diagnostics` object with `previous_message_id` set to null on the first turn, then pass each response's ID with the next. The reply can name `model_changed`, `system_changed`, `tools_changed` or `messages_changed`, pointing to the earliest divergence.
If your pair hits but production doesn't, set the gaps between real requests against the cache lifetime. Then look for parallel bursts, scattered keys, split workspaces and fallback providers.
Once it's fixed, chart the token-weighted rate by route, model and session length. Short sessions have fewer chances to reuse anything. ProjectDiscovery's single-step tasks averaged 35.5%, while tasks of 20 steps or more averaged 74%, so a blended figure can fall simply because your traffic changed shape. Shihipar wrote that the Claude Code team runs alerts on its hit rate and declares SEVs, or formal incidents, when the number drops too low. Set your own alert, so the timestamp someone adds for logging shows up the same day instead of on the monthly invoice.
Also read: Why Is LLM Output Different at Temperature 0, and Can You Stop It? • AI support agent cost per resolved ticket runs 2 to 4 times the sticker • How to calculate inference cost per user before your free tier burns cash
This article is posted in AI News, check it out for more related stories.
Join the discussion #
Open in the community → Almost there. Sign in and your reply posts straight away.