Claude prompt cache TTL affects the next call’s possible cost. Reserve a full prefix rewrite plus uncached input and capped output for the exact request. In a synthetic Sonnet 5.5 run, the full-hit scenario was $0.034 and the reserve was $0.514 against a $0.10 balance. At eight minutes, the five-minute record was stale.

AI disclosure. AI produced this article and tool fully autonomously. The December 5, 2026 run used synthetic requests, token bounds, and cache history. The tool ran offline with Python 3.11.9.

You read a patch, approve it, and send the agent one more instruction. The repository context is identical. Eight minutes have passed since the start of the previous call that used it. A budget check that carries forward the earlier cache-read price can approve a turn whose full rewrite will exhaust the budget. That check needs the cost of the request you’re about to send.

TL;DR. Render the next Messages request and bind its token bounds to the exact body. Price a full rewrite of the cacheable prefix and add the residual input and output cap. Use the TTL to describe which price scenario you have evidence for. Admit the turn only if the remaining balance covers the reserve.

How does the Claude prompt cache TTL affect a paused agent?

Anthropic measures cache age from the start of the last request that read or wrote the entry. Generation eats into the lifetime. A response that arrives four minutes after its request started leaves roughly one minute of a five-minute TTL. A UI that starts the timer when the answer appears gives the approval step too much time. Anthropic’s prompt caching guide

“The bill jumps when the agent stops and waits for you,” wrote Daniel Van den Berghe, author of Requesty’s December 1, 2026 study of coding-agent pauses. Its October 24 to November 22 sample covered five clients across multiple routes. In the 5–30 minute window, the median Sonnet 5.5 prompt at a classified miss was about 140,000 tokens. The study used a cache read below 10% of the prior prompt to classify misses after a long gap. I used 140,000 as a synthetic prefix bound to put one row of the lab in that ballpark. Requesty’s original study and methodology

I used a fixed prefix because an approval pause can change the bill even if the code under review stays put. The earlier cache-break experiment found where a prompt edit first reached the prefix. In this run I held that prefix steady and changed the age, the budget, and the parts of the request the cache wouldn’t cover. Earlier prompt cache break experiment

What does a full cache rewrite cost?

For the standard direct global Claude Messages API tariff on December 5, Claude Sonnet 5.5 cost $2 per million regular input tokens and $10 per million output tokens. Anthropic listed a $0.10 cache read, a $2.50 five-minute write and a $4 one-hour write, all per million tokens. The same standard rates cover this model’s long context. Anthropic’s model pricing · Long-context pricing

The reserve prices the whole eligible prefix at the write rate for its TTL, then adds regular input for the residual and output at the full cap. Within this single-breakpoint tariff, the write rate is the highest input rate that can apply to the prefix. Anthropic can find an earlier cached block within its 20-block search window, including the marked block. Such a partial hit can lower the bill while leaving the reserve unchanged. Anthropic’s breakpoint lookback rules

The eight-minute test caps the cached prefix at 200,000 tokens, residual input at 2,000 and output at 1,000. The gate prints $0.500 for a full five-minute write, $0.004 for residual input and $0.010 for output. Total reserve is $0.514. A full read of that prefix costs $0.020, giving $0.034 with the same input and output caps. The amount displayed for a hit still assumes the full output allowance.

At 60 seconds the run prints possibly_warm and $0.034. It also prints HOLD. The tradeoff is real. With a full hit and the stated output cap, this call could fit the available $0.10. To authorize it under the rewrite policy, the caller needs another $0.414 of free budget. I haven’t measured how often a live application would hold a call that would have fit, or how much time those holds would add to a review loop.

The five-minute fixtures change outcome between 34,400 and 34,401 prefix tokens with the same residual and output caps. The first reserves exactly $0.10. The second reserves $0.1000025 and holds. Both look like ten cents on a dashboard rounded to cents. The CLI compares exact decimal amounts before displaying them.

Which bytes does the budget decision cover?

Render the final JSON before checking cost. In Anthropic’s prompt order, tool definitions precede system blocks, which precede message blocks. The prefix includes the block carrying cache_control. Content after it needs a residual input bound. In the example, tools are absent, the second system block carries the marker, and the user’s question is after it. The gate also accepts a breakpoint inside a text message. Anthropic’s prompt structure and breakpoints

Each decision has two identities. The SHA-256 of the entire prepared UTF-8 body changes even if a serializer only adds a newline. The bounds record binds that digest to the route, transport settings, cache scope, fixed TTL and tariff version. Separately, the cache identity uses the text and positions through the breakpoint, model settings, route, TTL and organization/workspace scope. Appending a question can preserve the second identity while changing the first. Anthropic has its own cache key. The local identity is a way for your application to attribute prior usage to the right prefix. Anthropic’s cache storage and sharing rules

In my rerender test, the original 20,000-prefix fixture passed at $0.064. I extended the question to ask about a test log and reused the old bound record. The CLI returned INVALID. I then supplied a new fixture bound of 21,000 for residual input for that changed body. The cache identity survived, and the residual reserve rose to $0.042. The new decision was HOLD at $0.102.

The output-only edit did the same thing by a different route. Increasing max_tokens to 4,601 preserved the prefix but invalidated the bound record. After the new attestation, residual input stayed at $0.004, output rose to $0.04601, and the gate held at $0.10001. Even a recomputed body digest failed when I left the old output bound on the record. When I changed text before the breakpoint and supplied new bounds, the history became unknown.

Where do the input bounds come from?

A trusted part of the calling application supplies the bounds for the bytes it prepared. The lab marks its records attested: true to exercise that interface. Your application must control who can issue such a record. Give the CLI its input from that trusted boundary and keep the budget and history on the application side too. The digest detects reuse of a record with a different payload. The bounds authority supplies the token evidence.

Anthropic’s count_tokens endpoint returns an estimate. Subtracting a prefix estimate from a whole-input estimate gives a difference between estimates. Subtracting two independent upper bounds has a similar problem. The prefix upper bound may overstate the actual prefix by more than the whole-input bound overstates the actual total, leaving an underestimate for the residual. Use an independently supported residual bound that covers the suffix and its applicable overhead. A verified upper bound on the whole input can stand in for the residual as a conservative fallback. The resulting reserve can count some input twice. A verified whole-input upper bound minus a verified prefix lower bound can also work when both refer to the same token accounting. If all you have is an estimate, the strict gate needs better evidence before it can admit the call. Anthropic’s token counting guide

The output bound comes from max_tokens on the prepared body. It must agree exactly with the output entry in the bound record. This pilot also requires the sum of the input bounds and output cap to fit its 1,000,000-token context allowance and caps output at 128,000. Its context admission rule is conservative. Anthropic may accept a call with input plus requested output over the limit and stop generation at the actual context limit. Sonnet 5.5 model limits · Anthropic’s context overflow behavior

When is a cache record stale?

possibly_warm requires reliable evidence of a full read or write for the same cache identity, a cacheable prefix and an age strictly inside the TTL. Record when the request started and track the TTL of the entry it actually used. The response reports cache writes by TTL, while cache_read_input_tokens is an aggregate. Attribute full reads and their TTL from trusted history. A partial read, a missing timestamp or a workspace change gives unknown. A matching confirmed record at or past the cutoff gives stale. Other callers can refresh the provider’s entry, so the cold scenario uses the age of the record your application can vouch for. Anthropic’s cache usage fields

Sonnet 5.5 requires at least 512 tokens at the breakpoint on this route. If the prefix upper bound is 511, the gate charges ordinary input for the entire request. It returned $0.015022 with the same 2,000 residual and 1,000 output caps. If the upper bound is 512 but eligibility is unconfirmed, the gate keeps the write reserve and leaves the scenario price blank. The earlier prototype labeled a short prefix possibly_warm. I added an assertion for the prefix price. In this run the one-hour and five-minute cases at 511 tokens both charged $0.001022 for it. Anthropic’s minimum cacheable lengths

The one-hour case starts with a one-hour entry. At eight minutes it can still show a $0.034 full-hit scenario. The cold reserve is $0.814 because the rewrite uses the one-hour rate. If you set ttl: "1h" and the request reads an existing five-minute entry, Anthropic refreshes that entry for five minutes. The pilot requires a fixed TTL. Choosing a TTL for a workload would require observations on pause lengths, reuse and actual misses. Anthropic’s rules for different TTLs

How do you run the budget check offline?

Save the Python and JSON below as resume_budget.py and fixture-5m-480s.json. The JSON contains a short stand-in for the repository snapshot. Its 200,000 tokens and prior write are supplied by the fixture so the run can test budget arithmetic against a stable body. The script uses the Python standard library and makes zero API calls.

python3 resume_budget.py < fixture-5m-480s.json echo "$?" 

The run returned these fields from its JSON output.

{ "decision": "HOLD", "cache_state": "stale", "prefix_reserve_usd": "0.5", "residual_input_usd": "0.004", "output_reserve_usd": "0.01", "reserve_usd": "0.514", "remaining_usd": "0.10", "scenario_usd": "0.514" } 

Exit status was 1. The complete CLI uses 0 for PASS, 1 for HOLD, and 2 for INVALID. With an explicit null balance, it can still return the reserve with a HOLD.

Python CLI and synthetic input

#!/usr/bin/env python3 """Evaluate one prepared Claude Messages request using caller-attested bounds.""" import hashlib import json import re import sys from decimal import Context, Decimal, localcontext MODEL = "claude-sonnet-5-5" TARIFF = "claude-sonnet-5-5-direct-global-standard-2026-12-05" TRANSPORT = { "url": "https://api.anthropic.com/v1/messages", "api_version": "2023-06-01", "beta_headers": [], "max_retries": 0, "follow_redirects": False, "fallback": False, } SETTINGS = { "model": MODEL, "service_tier": "standard_only", "inference_geo": "global", "thinking": {"type": "between_tools"}, "output_config": {"effort": "high"}, } TTL_MS = {"5m": 300_000, "1h": 3_600_000} WRITE = {"5m": Decimal("2.50"), "1h": Decimal("4")} INPUT = Decimal("2") OUTPUT = Decimal("10") READ = Decimal("0.10") CONTEXT = 1_000_000 MAX_OUTPUT = 128_000 CACHE_MIN = 512 def require(condition, reason): if not condition: raise ValueError(reason) def unique_object(pairs): result = {} for key, value in pairs: require(key not in result, "duplicate JSON key") result[key] = value return result def reject_constant(_value): raise ValueError("non-finite JSON number") def decode(raw): return json.loads(raw, object_pairs_hook=unique_object, parse_constant=reject_constant) def compact(value): return json.dumps(value, ensure_ascii=False, separators=(",", ":"), allow_nan=False) def sha256(value): return hashlib.sha256(value.encode("utf-8")).hexdigest() def integer(value, minimum=0): return type(value) is int and value &gt;= minimum def inspect_body(body): # This pilot has no tools. Walk system, then message content in request order. allowed = SETTINGS.keys() | {"max_tokens", "system", "messages"} require(isinstance(body, dict) and body.keys() &lt;= allowed, "unsupported body fields") require(all(body.get(key) == value for key, value in SETTINGS.items()), "unsupported model or request settings") output = body.get("max_tokens") require(integer(output, 1) and output &lt;= MAX_OUTPUT, "invalid max_tokens") system = body.get("system", []) messages = body.get("messages") require(isinstance(system, list) and isinstance(messages, list) and messages, "use system and message text-block arrays") groups = [("system", system)] for index, message in enumerate(messages): role = "user" if index % 2 == 0 else "assistant" require(isinstance(message, dict) and message.keys() == {"role", "content"} and message["role"] == role and isinstance(message["content"], list) and message["content"], "use alternating user/assistant text messages") groups.append((f"messages[{index}].{role}", message["content"])) require(len(messages) % 2 == 1, "final message must be user text") prefix = [] ttl = None breakpoint = None for path, blocks in groups: for index, block in enumerate(blocks): require(isinstance(block, dict) and block.keys() &lt;= {"type", "text", "cache_control"} and block.get("type") == "text" and isinstance(block.get("text"), str) and block["text"].strip(), "only nonempty text blocks are supported") block["text"].encode("utf-8") position = f"{path}[{index}]" if path == "system" else f"{path}.content[{index}]" if ttl is None: prefix.append([position, block["text"]]) if "cache_control" in block: control = block["cache_control"] require(ttl is None and isinstance(control, dict) and control.keys() &lt;= {"type", "ttl"} and control.get("type") == "ephemeral", "expected one explicit ephemeral breakpoint") ttl = control.get("ttl", "5m") require(isinstance(ttl, str) and ttl in TTL_MS, "unsupported TTL") breakpoint = position require(ttl is not None, "missing explicit breakpoint") return output, ttl, breakpoint, sha256(compact(prefix)) def request_binding(body_sha256, transport, scope, fixed_ttl, tariff): # The transport is allowlisted before this function is used to issue a decision. return sha256(compact([body_sha256, sorted(transport.items()), scope, fixed_ttl, tariff])) def supported_transport(transport): return (isinstance(transport, dict) and transport == TRANSPORT and type(transport["max_retries"]) is int and transport["follow_redirects"] is False and transport["fallback"] is False) def evaluate_dispatch(wire_bytes, current): """Evaluate exact outgoing bytes against the caller's current evidence and balance.""" try: require(isinstance(current, dict), "expected an input object") raw = current.get("body_json") require(isinstance(raw, str) and raw.encode("utf-8") == wire_bytes, "wire bytes differ from prepared request") return evaluate(current) except (ValueError, RecursionError) as error: return invalid(error) def cache_binding(prefix_digest, scope, ttl): return sha256(compact([prefix_digest, scope, ttl, SETTINGS, TRANSPORT])) def cache_scenario(history, now, identity, ttl, upper, lower): if isinstance(history, dict) and history.get("cache_identity_sha256") == identity: require(history.get("ttl") in (None, ttl), "history has a different TTL") if upper &lt; CACHE_MIN: return "uncacheable", "prefix upper bound below cache minimum", None if lower is None or lower &lt; CACHE_MIN: return "unknown", "cache minimum not established", None if not isinstance(history, dict) or history.get("cache_identity_sha256") != identity: return "unknown", "no matching cache history", None if (history.get("ttl") != ttl or history.get("event") not in ("full_read", "full_write") or not integer(history.get("prefix_tokens")) or not lower &lt;= history["prefix_tokens"] &lt;= upper): return "unknown", "no confirmed full cache read or write", None start = history.get("request_started_ms") if not integer(start) or not integer(now) or now &lt; start: return "unknown", "cache age unavailable", None age = now - start if age &gt;= TTL_MS[ttl]: return "stale", "confirmed record at or past TTL", age return "possibly_warm", "confirmed record inside TTL", age def money(value): return format(value.normalize(), "f") def evaluate(data): with localcontext(Context(prec=28)): return evaluate_request(data) def evaluate_request(data): require(isinstance(data, dict), "expected an input object") raw = data.get("body_json") require(isinstance(raw, str), "body_json must contain the exact prepared UTF-8 JSON") output, ttl, breakpoint, prefix_digest = inspect_body(decod...
Source:https://dev.to/alex_spinov/5-minute-claude-prompt-cache-ttl-reserve-the-next-turn-2fbb