{"slug": "why-is-my-prompt-cache-hit-rate-low-and-how-do-i-get-the-discount-back", "title": "Why Is My Prompt Cache Hit Rate Low and How Do I Get the Discount Back?", "summary": "A prompt cache matches tokens from the first token forward, so a single edit near the top of a request discards every cached token behind it and forfeits the discount without raising an error, according to an analysis citing Anthropic's published prices of $2 per million ordinary input tokens, $2.50 per million five-minute cache writes and $0.10 per million cache reads. The analysis reports that ProjectDiscovery's weekly cache hit rate rose from 7.6% to 73.7% after it moved changing context to the end of its prompt, and that a study of 120 caching defects in open-source agent software found 108 failed silently. A 20,000-token system prompt sent 1,000 times to Claude Sonnet 5.5 costs $40 at the normal input rate or about $2.05 with a five-minute cache, but $50 if a to-the-second timestamp on the first line forces a cache write on every request.", "body_md": "*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.*\n\n- Prompt caches match from the first token forward, so an edit early in a request discards everything that follows it\n- Claude's minimum cacheable prompt ranges from 512 to 4,096 tokens depending on the model, and shorter prompts skip caching with no error\n- ProjectDiscovery's weekly cache hit rate jumped from 7.6% to 73.7% after it moved changing context to the end of its prompt\n- Claude's cache lifetime counts from the start of a request, so slow responses eat into the time left for the next call\n- A study of 120 caching defects in open-source agent software found that 108 of them failed silently\n- Sending parallel requests before the first response begins can leave all of them paying for a cold cache\n\nA 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.\n\nThose 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.\n\nBefore 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.\n\nOrder 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.\n\n[How Does AI Agent Memory Work Across Sessions, and Why It Keeps Failing](https://startupfortune.com/how-does-ai-agent-memory-work-across-sessions-and-why-it-keeps-failing/)\n\nHow 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](https://startupfortune.com/how-does-ai-agent-memory-work-across-sessions-and-why-it-keeps-failing/) - [why AI agent memory systems fail in production](https://startupfortune.com/how-does-ai-agent-memory-work-across-sessions-and-why-it-keeps-failing/)\n\nSwitching 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.\n\n## Cached input tokens showing zero\n\nRead 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.\n\nThe 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.\n\nOpenAI 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.\n\nWrites 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.\n\nSometimes 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.\n\n## Why is my prompt cache hit rate low when the prompt looks unchanged?\n\nThe 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.\n\n[How to handle LLM API rate limits in production before retries burn your quota](https://startupfortune.com/how-to-handle-llm-api-rate-limits-in-production-before-retries-burn-your-quota/)\n\nA 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](https://startupfortune.com/how-to-handle-llm-api-rate-limits-in-production-before-retries-burn-your-quota/) - [prevent retries from burning API quota](https://startupfortune.com/how-to-handle-llm-api-rate-limits-in-production-before-retries-burn-your-quota/)\n\nProjectDiscovery 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%.\n\nCheck 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.\n\nJSON 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.\n\nRequest 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.\n\n## Prompt caching not working in production\n\nYour test script passes because it fires two identical requests a few seconds apart. Real users take their time.\n\nClaude'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.\n\nThe 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.\n\nOpenAI'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.\n\nBatch 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.\n\nOn 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.\n\nSeparate 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.\n\n## How to structure prompts for prompt caching\n\nArrange 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.\n\nWhen 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.\n\nDon'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.\n\nClaude 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.\n\n## A debugging checklist for a low hit rate\n\nStart 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.\n\nIf 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.\n\nIf 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.\n\nOnce 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.\n\n**Also read:** [Why Is LLM Output Different at Temperature 0, and Can You Stop It?](https://startupfortune.com/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](https://startupfortune.com/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](https://startupfortune.com/how-to-calculate-inference-cost-per-user-before-your-free-tier-burns-cash/)\n\n*This article is posted in [AI News](https://startupfortune.com/category/ai/), check it out for more related stories.*\n\n## Join the discussion\n\n[Open in the community →](https://startupfortune.com/community/)\n\nAlmost there. Sign in and your reply posts straight away.", "url": "https://wpnews.pro/news/why-is-my-prompt-cache-hit-rate-low-and-how-do-i-get-the-discount-back", "canonical_source": "https://startupfortune.com/why-is-my-prompt-cache-hit-rate-low-and-how-do-i-get-the-discount-back/", "published_at": "2026-11-25 22:28:27+00:00", "updated_at": "2026-11-25 22:42:27.908062+00:00", "lang": "en", "topics": ["ai-agents", "large-language-models", "ai-tools"], "entities": ["Anthropic", "Claude", "Claude Sonnet 5.5", "OpenAI", "Google", "Gemini 2.5", "ProjectDiscovery"], "also_reported_by": [], "takeaway": "Put static content such as system prompts and tool definitions first and changing context like timestamps last, since caches match from the first token forward; ProjectDiscovery raised its weekly cache hit rate from 7.6% to 73.7% by doing so.", "recommendation": {"advice": "Order prompts static-first and variable-last, and verify hits via cache_read_input_tokens before assuming caching works; ProjectDiscovery went from 7.6% to 73.7% hit rate this way.", "playbook": "llm-cost", "playbook_url": "https://wpnews.pro/playbooks/llm-cost"}, "alternates": {"html": "https://wpnews.pro/news/why-is-my-prompt-cache-hit-rate-low-and-how-do-i-get-the-discount-back", "markdown": "https://wpnews.pro/news/why-is-my-prompt-cache-hit-rate-low-and-how-do-i-get-the-discount-back.md", "text": "https://wpnews.pro/news/why-is-my-prompt-cache-hit-rate-low-and-how-do-i-get-the-discount-back.txt", "jsonld": "https://wpnews.pro/news/why-is-my-prompt-cache-hit-rate-low-and-how-do-i-get-the-discount-back.jsonld"}}