AI Coding Agents
5 minute vs 1 hour prompt cache TTL for Claude
Choose Anthropic’s 1-hour prompt cache when an unchanged prefix will probably be reused after the 5-minute entry would have expired but before the hour is up. The longer write costs 2 times the base input price versus 1.25 times, and one avoided rewrite can cover the difference even after paying for the cache read.
Measure from the start of the last write or read
As of November 30, 2026, Anthropic’s default cache lifetime is five minutes. On a supported Claude API request, set "ttl": "1h" in the relevant cache_control object to request an hour. A cache read refreshes the entry’s lifetime without an additional refresh fee. You still pay the model’s cache-read rate for the tokens read. Reading a five-minute entry restarts its five-minute lifetime, even if the new request sets the TTL to an hour. Changing a setting on a warm call therefore gives you no evidence that an hour-long write occurred. Anthropic prompt caching
The lifetime starts when the request that writes or reads the entry starts. Include generation time when you measure gaps. An illustrative request that starts at minute zero and takes four minutes to stream leaves about one minute for the next call to start before the short entry expires. A human pause of two minutes after that response would put the next start six minutes after the previous one. Measure from the latest request that actually read or wrote the prefix being evaluated. Traffic on an unrelated prefix does not refresh it. Anthropic prompt caching
Consecutive reads can keep a short entry warm through a much longer session. The useful input to your decision is the list of gaps between reuses of the same prefix. Group requests by the part you want to reuse, such as fixed tools and a reference document. If a new tool definition, a model change or a history rewrite changes that prefix, log it as a separate event. A longer lifetime cannot restore reuse across a changed prefix.
Calculate how many rewrites the longer TTL avoids
Let B be the cost of the chosen prefix at the ordinary input rate. If the prefix has N tokens and the input price per million is P, then B = N × P / 1,000,000. Compare the two policies over an interval that starts with both entries cold and ends before both need to be rewritten. Assume the prefix and breakpoint stay fixed and that each request’s lookup finds a matching entry whenever one is still live.
The five-minute write costs 1.25 × B and the hour write costs 2 × B. The hour costs 0.75 × B extra up front. One gap longer than five minutes and shorter than an hour costs another 1.25 × B rewrite under the five-minute policy. With the hour policy that request is a read. The rate for reads stays the same across TTL choices, but the hour policy now has one additional read in place of the rewrite. Count it in the comparison. The standard Anthropic read multiplier is 0.1 with per-model exceptions, including 0.05 for Sonnet 5.5. Anthropic prompt caching
If r is the read multiplier and G is the number of extra rewrites the hour would avoid in that interval, the estimated savings from choosing the hour are B × ((1.25 − r) × G − 0.75). A positive result favors the hour. One expected qualifying gap per interval clears the hurdle at the standard read rate and for Sonnet 5.5. With Sonnet 5.5, the expected-value crossover is 0.75 / (1.25 − 0.05) = 0.625 avoided rewrites per initial write. If each interval can contain at most one qualifying gap, that corresponds to a 62.5% chance of the gap. Use an average across intervals if some have more than one.
Count another initial write whenever both policies would start cold again. A long gap after which neither policy can reuse the entry gives the hour no savings on that request. If you start a new interval with an hour write, it has to earn back that interval’s extra cost through future reuse. This makes a short cache attractive for one-off sessions, even when the system prompt is large. Prefix size changes the dollars at stake and cancels out of the crossover when all requests in the comparison reuse the same token count.
Estimate the cost of a 100,000-token Sonnet 5.5 prefix
Assume a stable 100,000-token cacheable prefix, with cold first requests and matched entries whenever the respective policy keeps them warm. ByteCosts’ committed Claude Sonnet 5.5 rates are $2 per million ordinary input tokens, $2.50 per million for five-minute writes and $0.10 per million for reads. The hour write rate is derived from 2 × $2 = $4 per million. These are prefix-only estimates. New suffix input and generated output are outside the example. ByteCosts provider pricing · Anthropic prompt caching and pricing
| Operation for the assumed prefix | Calculation | Estimated cost |
|---|---|---|
| Five-minute write | 100,000 / 1,000,000 × $2.50 | $0.25 |
| One-hour write | 100,000 / 1,000,000 × $4 | $0.40 |
| Read at either TTL | 100,000 / 1,000,000 × $0.10 | $0.01 |
Suppose requests start at minutes 0, 2, 14 and 17. The read at minute 2 refreshes the short entry, so the relevant gap leading to minute 14 is 12 minutes. The short policy writes again at 14 and reads that new entry at 17. The hour policy reads on all three calls after the initial write. For comparison, suppose the same calls instead start at minutes 0, 2, 4 and 7. Both policies read on all three follow-ups.
| Assumed request starts | Five-minute prefix estimate | One-hour prefix estimate | Lower estimated prefix cost |
|---|---|---|---|
| 0, 2, 14, 17 minutes | 2 × $0.25 + 2 × $0.01 = $0.52 | $0.40 + 3 × $0.01 = $0.43 | One hour by $0.09 |
| 0, 2, 4, 7 minutes | $0.25 + 3 × $0.01 = $0.28 | $0.40 + 3 × $0.01 = $0.43 | Five minutes by $0.15 |
Where the prefix grows on each turn, use token counts per request instead of this fixed-prefix shortcut. A stable header and a changing conversation tail may warrant different TTLs. Anthropic allows mixed TTLs with the longer-lived breakpoints first. Try an hour on fixed instructions and references that survive idle gaps, and five minutes on the part of the history you expect to reuse quickly. Review the actual billable token split because the longest matching entry and the remaining marked boundaries determine how many tokens are read or written at each rate. Anthropic prompt caching
Check which policy the client actually requests
Claude Code’s main conversation defaults to an hour only on a Claude subscription within the plan’s included usage. API key, cloud provider and usage-credit billing default to five minutes. Separate requests such as subagents and compaction normally use five minutes, with a small set of server-controlled helper exceptions on subscriptions. Set promptCacheTtl to 5m or 1h for the main conversation in Claude Code v2.1.242 or later. Claude Code prompt caching
If the observed TTL differs, check FORCE_PROMPT_CACHING_5M=1 first because it overrides both request buckets. For the main conversation, Claude Code then checks CLAUDE_CODE_PROMPT_CACHE_TTL before promptCacheTtl. For other requests it checks CLAUDE_CODE_SUBAGENT_PROMPT_CACHE_TTL before subagentPromptCacheTtl, followed by cacheTtl in the subagent’s experimental frontmatter where applicable. The subagent override requires v2.1.248 or later. Claude Code ignores 1h there when a Claude subscription draws on usage credits. ENABLE_PROMPT_CACHING_1H=1 applies after those controls and before the bucket default. Through an ANTHROPIC_BASE_URL gateway, the one-hour request requires the gateway to forward anthropic-beta unchanged. On Amazon Bedrock, one-hour availability varies by model. Claude Code prompt caching
For a quick check, Claude Code documents running claude -p "hello" --output-format json. In the result, usage.cache_creation.ephemeral_5m_input_tokens and usage.cache_creation.ephemeral_1h_input_tokens show writes by lifetime. Compare those counters on a fresh write. In v2.1.251 or later, check the Prompt cache (main) line in /usage for warmth and misses after the main conversation’s first response. For a direct API client, log the same breakdown alongside cache_read_input_tokens. The aggregate cache_creation_input_tokens is the sum of the TTL buckets, so use the split for pricing when both are present. Claude Code prompt caching · Claude Code cost and usage · Anthropic prompt caching
For GPT-5.6 and later, OpenAI’s default 30m write costs 1.25 times ordinary input. In the Responses API, use prompt_cache_options.ttl to set the request default and prompt_cache_breakpoint.ttl to override it at an explicit breakpoint. The Responses API’s 12h write costs 2.5 times ordinary input. These are minimum lifetimes for cache-read pricing. The cache-read rate for the selected model is the same across them. OpenAI describes a 30-minute read as refreshing coverage for at least 30 minutes, preserving later existing 12-hour coverage when applicable. It does not restart a 12-hour clock. For earlier models, OpenAI documents no additional cache-write charge. Use the provider’s own coverage rules and prices when evaluating longer gaps. OpenAI prompt caching
Validate the estimate against billable input
Start with a trace from the actual workload. For each request, save the start time, model, marker location, read tokens, writes by TTL and ordinary input tokens. Flag a compaction or tool catalog update when it happens. Replay the sequence of starts against both lifetimes for the stable prefix. Reuse that would occur under either lifetime drops out of the fixed-prefix cost difference. If the estimate favors an hour, run a second trace with that setting and compare the actual write and read totals at equal input rates. Count requests where the longer setting still writes a new prefix. Those calls pay the higher write rate and reduce realized savings.
For mixed TTLs on the Claude API, multiply each write bucket by its own rate, then add cache reads at the model’s read rate and ordinary input at the base rate. Divide by the number of tokens in the pricing unit when your rates are quoted per million. During server tool use, Anthropic may add its own five-minute breakpoint on the result, even when your request’s markers ask for an hour. An unexpected five-minute bucket in that situation can come from the documented server behavior. Check where the write occurred before treating it as evidence that your chosen TTL was ignored. Anthropic prompt caching · Tool use with prompt caching
Choose a TTL from your request trace
- Pick five minutes if the stable prefix usually gets reused inside five minutes or rarely gets reused before either option expires.
- Pick one hour if repeat reads commonly cross the five-minute boundary and your estimate counts enough avoided rewrites to cover the higher write cost. Use Anthropic breakpoint placement to isolate the prefix before testing.
- If the read drops after changing tools, model or history, investigate silent prompt cache busters before attributing the miss to expiry.
- For a coding agent or a different model family, confirm what the client requested and what the provider billed. Compare Claude Code prompt cache settings and OpenAI’s GPT-5.6 caching changes for the relevant path.
Sources
- Prompt caching (Anthropic, accessed 2026-11-30)
- Claude Code prompt caching (Anthropic, accessed 2026-11-30)
- Claude Code cost and usage (Anthropic, accessed 2026-11-30)
- Prompt caching (OpenAI, accessed 2026-11-30)
- Tool use with prompt caching (Anthropic, accessed 2026-11-30)
Interactive reports
- The Five-Minute Clock: A quick review keeps a prompt cache warm. A longer break can turn the next question into another setup charge. Follow the same coding session through both clocks.
- Who Pays to Remember: Give four APIs the same repeated prompt and open the bill one line at a time. The read discount is only the first entry.
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.
5 minute vs 1 hour prompt cache TTL for Claude. ByteCosts. Updated 2026-11-30. https://bytecosts.com/blog/prompt-cache-ttl-5-minutes-vs-1-hour/