Four services send the exact same system prompt with caching enabled. One cuts its prompt bill by 85%. The other three end up paying more than if they had left caching off. The difference comes down to the time gaps between requests, and two counters in your gateway logs will tell you which side of the line your traffic is on.
When Caching Costs More
In most of systems engineering, turning on a cache is a safe default. If you put Redis in front of Postgres or a CDN in front of an origin server and nobody hits it, you waste a little memory and a few microseconds of lookup latency, but your origin bill doesn't go up by 25%. Prompt caching works differently: the provider keeps the prefix's key-value (KV) cache in memory and charges extra to write it, while discounting subsequent reads. When those reads don't show up in time, caching makes your requests more expensive.
Consider how that plays out across four services at the same company. Each one prepends the same 20,000-token policy manual to its requests, calls the same model on the same price sheet, and runs with Anthropic's default five-minute cache enabled. Over the course of a day, each service makes about 24 calls. The only difference is when those calls arrive:
| Service | Arrival Pattern | Prompt Cost vs. No Cache |
|---|---|---|
| Report job | Scheduled every 30 minutes through the workday | +25% |
| Help tool | Employee questions arriving at random | +16% |
| Agent loop | Once a day, 24 sequential calls 10s apart | −85% |
| Fan-out | Once a day, 24 sub-agents launched at once | +25% |
Every service sends the same prompt to the same model about 24 times a day, around 480,000 shared prefix tokens. Yet three of the four lose money with caching turned on.
The Break-Even Math
When an LLM bill spikes, the first thing engineers check is token volume. Here, volume is essentially the same across all four services. The difference comes from the pricing structure.
Under Anthropic's standard pricing for the five-minute ephemeral cache, writing a prompt prefix to the cache costs times the base input price , while reading a cached prefix back costs times the base input price. Every cache write carries a 25% upfront surcharge in exchange for a 90% discount on subsequent reads.
It takes surprisingly few cache hits for that tradeoff to pay off. Let be the total tokens written to the cache and be the total tokens read from the cache over a given period. Without caching, all tokens are billed at the base price . With caching on, your net savings is:
Caching breaks even when , which depends entirely on the read-to-write ratio :
You don't even need one cache hit per write to come out ahead. One cache read for every 3.6 writes is enough to cover the 25% write surcharge. Expressed as a standard cache hit rate , the break-even threshold is:
If slightly more than a fifth of your requests hit the cache, you save money. To see why three of our four services miss that mark, we have to look at the clock.
Cache Lifetimes and Inter-Arrival Gaps
An entry in Anthropic's five-minute cache lives for minutes from the start of the request that created it, and every subsequent cache hit resets that five-minute timer. If five minutes pass without a request, the entry is evicted, and the next caller has to rebuild the KV state and pay the 1.25x write price again.
Because every hit refreshes the TTL, the cache behaves as a renewal process. Line up a service's requests in chronological order at timestamps and look at the inter-arrival gaps . Ignoring the cold start on the very first request, call is a cache hit if and only if minutes, and a cache miss (a write) if minutes. The read-to-write ratio is simply the ratio of short gaps to long gaps:
The 0.28 break-even ratio translates into a simple timing rule: the five-minute cache saves money only when more than 22% of the gaps between consecutive calls are under five minutes.
Here is how the first three services behave against that five-minute window:
- Report job: Runs on a cron schedule every 30 minutes. Every daytime gap is minutes, and the overnight gap is longer. Each cache entry expires 25 minutes before the next job starts. It gets zero reads, pays the 25% write surcharge 24 times a day, and increases its bill by 25%.
- Help tool: Takes questions from employees at random times, averaging roughly one request per hour. Only 7.6% of its inter-arrival gaps fall under five minutes, well below the 22% threshold. It gets an occasional 90% discount, but the write fees dominate, leaving it 16% more expensive than no caching at all.
- Agent loop: Runs once a day and executes 24 sequential tool-use steps spaced 10 seconds apart. It has one overnight gap followed by 23 ten-second gaps. It pays the 1.25x write price once on step 1, reads at 0.10x on steps 2 through 24, and cuts its daily prompt bill by 85%.
The fourth service, however, breaks the gap rule. The fan-out job fires all 24 sub-agent calls within a 500-millisecond window. Ninety-six percent of its gaps are under half a second, well inside the five-minute TTL. By our gap-counting equation, it should match the agent loop's 85% savings. Instead, it loses the full 25%, performing just as badly as the 30-minute cron job.
The Concurrent Fan-Out Trap
Anthropic's prompt caching documentation notes an important detail about concurrent requests: a cache entry only becomes available after the first response starts.
Consider what that means for a fan-out. On a miss, the docs say, the model processes the full prompt and caches the prefix once the response starts. Until that first request finishes processing the 20,000-token prefix and starts its response, there is no cache entry for other callers to read. When an orchestrator dispatches 24 sub-agents in parallel, all 24 requests arrive before any single request reaches time-to-first-token (TTFT). Every sub-agent sees a cold cache, computes the exact same 20,000-token prefill in parallel, and pays the 1.25x write surcharge.
The fix takes a few lines of synchronization code and costs a single TTFT round trip. If the orchestrator dispatches sub-agent #1, waits until its first streamed token arrives, and then fans out the remaining 23 sub-agents, those 23 calls hit the newly written cache entry. That one barrier turns a 25% surcharge into an 85% discount.
We tested both versions against the live API using five calls on a 20,000-token prefix. When launched together, all five requests wrote to the cache in each of three runs. With the barrier in place, all four followers read from the cache every time, after a wait of 1.4 to 2.0 seconds for the first token.
When the 2x One-Hour Cache Is Cheaper
Anthropic also offers a one-hour prompt cache, priced at (double the base input price to write) and the same to read.
If you are already losing money on a 1.25x write surcharge, switching to a 2.0x write surcharge sounds counterproductive. Plugging into the savings formula shows that the one-hour cache requires a much higher read-to-write ratio to break even:
That corresponds to a hit rate of , meaning more than 53% of your inter-arrival gaps must be under an hour.
Despite the higher threshold, switching our four workloads to the one-hour cache changes the outcome:
- Report job (30-minute gaps): Hits the cache on every call after the morning cold start. Because every hit refreshes the one-hour timer, a single 2.0x write at 8:00 AM carries the job through all 23 subsequent runs, flipping its bill from +25% to −82%.
- Help tool (~60-minute average random gaps): Sees 63% of its gaps fall under the one-hour mark, clearing the 53% hurdle and turning a 16% loss into a 20% saving.
- Agent loop: Drops slightly from −85% to −82%, since it pays 2.0x instead of 1.25x on its single daily write without needing the longer TTL.
- Fan-out (unfixed): 24 parallel writes at 2.0x doubles its daily prompt bill (+100%).
We can generalize the random-arrival case with renewal math. Suppose requests arrive as a Poisson process with mean inter-arrival gap (rate ). The inter-arrival times are exponentially distributed, so the probability that any gap falls within a cache lifetime is . Because each miss starts a renewal cycle followed by a geometric run of hits, the long-run number of reads per write is:
From this, we can write the expected effective price per prefix token directly as a function of the cache lifetime and write multiplier :
Setting (cheaper than no cache) and comparing against yields three thresholds for random traffic:
- The 5-minute cache breaks even () only when calls arrive at least every minutes on average.
- The 1-hour cache breaks even () when calls arrive at least every minutes on average.
- The 1-hour cache is strictly cheaper than the 5-minute cache () whenever the mean gap is under minutes.
Because 80 minutes is less than 110 minutes, the five-minute cache has no window where it wins on random traffic. If Poisson arrivals are frequent enough for caching to pay off at all, the one-hour cache saves more. The five-minute cache only wins on tightly clustered bursts like the agent loop, where calls arrive seconds apart and then go quiet for hours.
Web cache researchers worked out the same renewal math more than twenty years ago. In Che, Tung, and Wang's 2002 analysis of LRU caches, an object stays cached as long as another request arrives within a "characteristic time," and the hit rate follows from the inter-arrival gaps. What changed with LLMs is the 25% to 100% fee on every miss.
What Real Traffic Looks Like: 233 Claude Code Sessions
The four services above are synthetic examples. To see how real traffic behaves, we replayed Anthropic's cache rules over SemiAnalysis's public trace of 233 Claude Code sessions: 60,996 model requests, each with its real start timestamp and the 64-token prefix blocks of its prompt.
Real agent sessions look like the agent loop, not the report job. The median gap between a session's consecutive calls to the same model is 11 seconds, and 97.5% of gaps are under five minutes. Caching saves money in all 233 sessions under either TTL, cutting input costs by 84% with the five-minute cache and 86% with the one-hour cache.
Even so, the one-hour cache isn't automatically the better deal. It comes out cheaper in 115 sessions and more expensive in 118 because of a factor our four synthetic services didn't have: an agent's context grows on every turn, and each turn writes its new tail to the cache. Those first writes of new context make up 30% of all tokens written under the five-minute cache, and the one-hour cache charges 2x for them instead of 1.25x.
What the one-hour cache saves is the other 69% of writes: existing context that expired during pauses longer than five minutes, while the developer stepped away or a slow tool ran, and had to be written again. The one-hour cache cuts those rewrites from 486 million tokens down to 71 million. Which TTL wins depends on how often a session pauses for more than five minutes, which you can measure directly in your logs. Claude Code handles this split by default: the main conversation uses the one-hour cache on a subscription and five minutes with an API key, sub-agents use five minutes, and the promptCacheTtl setting lets you override it.
The concurrent fan-out problem shows up in the trace as well. Across the dataset, Claude Code launched two to seven sub-agents in parallel 45 times. Every sibling request started within a second of the first, and two-thirds started within 0.2 seconds. That is before the first request's response could plausibly have started: our live test measured 1.4 to 2.0 seconds to the first token on a 20,000-token prompt. All 90 sibling calls wrote their shared prefix of roughly 30,000 tokens instead of reading it from the cache. Fan-outs are rare enough in this dataset that the total is small, but it is the same race, and waiting for one first token fixes it. Claude Code already does this for its workflow fan-outs: it holds all but the first agent for up to five seconds, so the rest can read the prefix the first one cached.
Auditing Your Own Logs
You don't need to model your arrival times to see which side of 0.28 or 1.11 your services fall on. Anthropic returns cache_read_input_tokens () and cache_creation_input_tokens () on every response, and gateways like LiteLLM log both.
If you use LiteLLM, you can query both totals per API key straight from its Postgres database. LiteLLM stores them inside each spend-log row's metadata JSON rather than in dedicated columns:
SQL: cache reads and writes per API key, last seven days
SELECT api_key,
sum((metadata #>> '{additional_usage_values,cache_read_input_tokens}')::bigint) AS cache_read,
sum((metadata #>> '{additional_usage_values,cache_creation_input_tokens}')::bigint) AS cache_write,
count(*) FILTER (WHERE metadata #> '{additional_usage_values,cache_read_input_tokens}' IS NULL)
AS rows_missing_detail
FROM "LiteLLM_SpendLogs"
WHERE "startTime" >= now() - interval '7 days'
GROUP BY api_key;
Divide cache_read by cache_write and compare the result against 0.28 (for the five-minute cache) or 1.11 (for the one-hour cache). Keep the rows_missing_detail column: sum ignores rows where cache metadata is missing, so a key that doesn't log those fields would otherwise look like it had zero cache reads. These JSON paths match LiteLLM 1.104.0; verify them against your deployed version.
fleetdiff runs the same check from LiteLLM spend logs or a read-only database connection, counts missing metadata separately, and compares two time windows grouped by key, team, user, or session. Here is the report job on a five-minute cache day versus a one-hour cache day from the sample file:
# Install: go install github.com/llm-measurement/fleetdiff/cmd/fleetdiff@v0.14.1
# (or use the verified installer in the fleetdiff README)
fleetdiff investigate --litellm-spend scheduled-job.csv \
--before-period 2026-11-02 --after-period 2026-11-03 --group-by key
Cache reuse rose: cache-read share 0% -> 93.5% (uncached input -460,000).
...
Cache reads: 0 of 492,000 input tokens -> 460,000 of 492,000 (all requests report cache detail).
...
Cache writes: 480,000 of 492,000 input tokens -> 20,000 of 492,000 (all requests report cache detail).
...
Recorded spend (USD, analyzed calls): 1.944 -> 0.402.
Dividing reads by writes gives on November 2 (below 0.28, losing money) and on November 3 (above 1.11, cutting recorded spend from \$1.944 to \$0.402).
To check your own services, compare the last two weeks grouped by key, team, user, or session. The cache check guide includes commands for a read-only LiteLLM database login or a CSV export. If a service's ratio drops after a deploy, inspect the top of the prompt before blaming traffic timing: caching requires an exact prefix match, so injecting a timestamp or request ID near the top of a system prompt forces a cache write on every call.
Notes on the Numbers
- Synthetic workloads: The four services are illustrative. Their costs come from simulating Anthropic's published cache rules and pricing as of November 5, 2026, across the shared 20,000-token prefix only. The scripts and sample data reproduce every figure.
- Trace replay: The real-session numbers replay those same cache rules, with each call caching its full prompt, across SemiAnalysis's sample of heavy Claude Code sessions (each with at least 20 requests). They describe interactive coding-agent traffic, not every LLM workload, and they are simulated costs, not what those sessions were billed.
- Live API checks: We verified the two mechanics the story depends on against the live Anthropic API: cache hits refresh the TTL on both the one-hour and five-minute caches, and requests launched together all pay for separate cache writes.
- Other pricing tiers: The break-even ratios above assume cache reads cost 0.1x the base input price. For models that price reads at 0.05x or 0.025x, the break-even ratios drop slightly to 0.26 (five-minute) and 1.03–1.05 (one-hour), and the one-hour cache still dominates on random Poisson traffic.
- Spend logs vs. invoices: fleetdiff reports the tokens and spend your gateway recorded. Those aren't your provider invoice.