Claude prompt caching and the cost of a coffee break
Trace a Claude API request from cache write to read, price the same agent session with and without a pause, and calculate the hit rate from response usage.
Published

An agent sends Claude the same handbook before and after lunch. The first request after lunch can cost more even if the handbook, question and answer are identical. The response’s usage object shows whether Claude billed the handbook as a cache read or a fresh write.
Anthropic told The New Stack it chose a five-minute default because an agent at work often makes its next request soon enough to read the entry before it expires. A developer reviewing a change may need longer. The developer can take that time. The billing decision is how long the application asks Claude to hold the shared input. The New Stack’s reporting
Where to put the cache breakpoint
In the Claude Messages API, prompt caching lets Claude resume processing from an exact, previously processed beginning of a request. You still send the handbook and the question each time. Claude keeps the prefix’s attention state in memory and generates an answer for the current question. Reusing an answer to a similar question is a different design, called semantic caching. For the underlying attention state, see how the KV cache works.
As of Dec 6, 2026 · Source: Anthropic, Prompt caching
A breakpoint marks the end of the prefix. Change a tool definition and the later handbook can miss even if every word of it stayed the same. Change only the question in this layout and the handbook can still hit. On a cold request, Claude processes the input and the cache entry becomes available once the response starts. Parallel requests sent before then can each miss.
For a growing chat, put "cache_control": {"type": "ephemeral"} at the top level and the API moves the mark to the last cacheable block. A later turn can read the old conversation and write the new exchange in the same request. For a handbook shared across independent questions, put the mark on the handbook itself. You can use up to four breakpoints, including the automatic one. Each looks back at up to 20 block positions for a prefix that was actually written. If a turn routinely appends more than that, an explicit mark on the long-lived material gives Claude a place to find it.
Check the marked prefix’s size. As of December 2026, the direct Claude API minimum is 512 tokens for Opus 5.5, Sonnet 5.5 and Haiku 5.5. Examples from other model generations are 1,024 for Sonnet 4.6, 2,048 for Opus 4.7 and 4,096 for Haiku 4.5. A short marked prefix goes through at ordinary input pricing with zero tokens created or read and no error. Anthropic’s model and platform minimums
What a write looks like in the response
Anthropic’s prewarming example makes the write easy to see. It sends a real Messages API request with a full system prompt and asks for zero output tokens. Here is the Python request adapted to take your existing system prompt from a file. The file must contain enough text to clear the model’s minimum.
from pathlib import Path
import anthropic
client = anthropic.Anthropic()
system = [{
"type": "text",
"text": Path("handbook.txt").read_text(encoding="utf-8"),
"cache_control": {"type": "ephemeral"},
}]
prewarm = client.messages.create(
model="claude-opus-5-5",
max_tokens=0,
system=system,
messages=[{"role": "user", "content": "warmup"}],
)
print(prewarm.usage.model_dump_json())"cache_control": {"type": "ephemeral"}
"max_tokens": 0
"input_tokens": 8
"cache_creation_input_tokens": 5120
"cache_read_input_tokens": 0
"output_tokens": 0
Those are the counts in Anthropic’s example. Your file determines yours. On the next call, send the same system blocks, replace the warmup message with the user’s question and give Claude an output budget. A hit moves the shared prefix into cache_read_input_tokens. The current question still contributes ordinary input. A normal first question can also create the entry, so a separate warmup is optional. Anthropic’s prompt caching guide
What a coffee break adds to one agent bill
The cache clock starts when the request that writes or reuses the entry starts. A four-minute streamed response leaves about one minute of the default five-minute window. A hit refreshes the lifetime and costs the read rate, with no separate refresh fee. After the window, the service can discard the entry. The next matching request that finds it gone writes it again.
Anthropic charges 1.25× base input for a five-minute write and 2× for a one-hour write. Reads cost 0.05× on Opus 5.5 and Sonnet 5.5, 0.025× on Fable and Mythos 5.1 and 5.2, and 0.1× on the remaining models in the price table. Use your model’s row. Anthropic’s cache pricing
Consider an Opus 5.5 agent answering four questions against a fixed 10,000-token handbook. Mark only the handbook. Assume each call adds 500 uncached input tokens and generates 100 output tokens. At standard global rates, ordinary input costs $4 per million tokens and output costs $20 per million. One ordinary pass over the handbook costs $0.04. A short write therefore costs $0.05, a long write $0.08 and a hit $0.002. Anthropic’s model prices
The table assumes the short entry expired during the gap and all eligible warm reads hit. Each total includes the same $0.008 for uncached input and $0.008 for output. Start with the short-cache bill of $0.072, swap one $0.002 read for one $0.05 write, and the pause adds $0.048. Idle time itself has no line item. If the user never returns, there is no second write.
The longer lifetime costs an extra $0.03 upfront on this prefix. In the session with the gap it avoids $0.048 of rebuilding, leaving the hour cheaper by $0.018. For this fixed prefix with at most one such gap, the hour wins on average if more than 62.5% of sessions would turn that read into a write. That threshold comes from $0.03 divided by $0.048. Change the model, prefix growth or number of gaps and the decision changes too.
Read the hit rate from your usage logs
For the share of all input tokens served from cache, sum the fields across the requests you want to compare, then divide. A short request and a giant handbook should contribute in proportion to the tokens they brought.
read = sum(cache_read_input_tokens)
written = sum(cache_creation_input_tokens)
plain = sum(input_tokens)
cached share of input = read / (read + written + plain)In the warm session above that is 30,000 / 42,000, or 71.4%. Three of four requests hit, or 75%. Both numbers are correct. The first helps explain the bill. The second tells you how often a request got any reuse at all. For the gapped session the token share falls to 20,000 / 42,000, or 47.6%. Exclude output from both input calculations.
To price mixed lifetimes, split writes using usage.cache_creation.ephemeral_5m_input_tokens and ephemeral_1h_input_tokens. Together they already make up cache_creation_input_tokens. Counting the total again overstates the bill. A request can have positive reads and writes when Claude reuses one stretch and extends it.
Four habits for an agent that has to wait
- Keep the shared opening byte-for-byte stable. Build tool definitions in a consistent order. Put a request ID, a timestamp and the ticket text after the handbook. A miss on a rapid follow-up is a reason to compare the actual request bodies.
- Mark the last thing worth reusing. Keep a fixed breakpoint on a policy shared by many tickets. Use a moving breakpoint for a continuing conversation. A one-off document with no likely second reader simply costs more to write than to process once.
- Choose the lifetime before the work starts. Use five minutes for a tight tool loop. For a recurring human approval, compare the cost of the longer write with the rebuilds it would avoid. Set
"ttl": "1h"insidecache_controlfor the longer window. If mixing lifetimes, place hour-long blocks before five-minute blocks. - Log the gap alongside the three input counts. Compare request start times within the same model, workspace and prompt version. Repeated writes after long gaps point toward expiry. Repeated writes on quick follow-ups call for a prefix comparison. If creation and read are both zero, check the marker and the minimum size first.
If the problem is a conversation running out of room, look at Claude Code’s auto-compaction window. If the bill moved when you changed generation speed, check Claude fast mode pricing. For a cross-provider implementation, compare GPT-6 cache diagnostics and Gemini implicit caching before carrying Claude’s assumptions across.
Which LLM API is cheapest for your workload?
Bring your ordinary input, cache reads and output counts to the model price comparison.
- Published
- Category
- Build







