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

Claude prompt caching and the cost of a coffee break

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.

A breakpoint covers everything up to the markA handbook assistant with one explicit breakpoint
Request order
toolsTool definitionsKeep names, schemas and order stable.
systemInstructions and handbookMark the last shared block with cache_control.
messagesCurrent questionThis comes after the mark and takes the ordinary input rate.

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.

Python
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())
Anthropic’s documented prewarm request and response, abridged

"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

Same four callsWhat happens to the handbookHandbook costSession total
Caching offFour ordinary inputs$0.160$0.176
Five-minute cache, calls a minute apartWrite, read, read, read$0.056$0.072
Five-minute cache, eight-minute gap before call threeWrite, read, write, read$0.104$0.120
One-hour cache from the start, same gapWrite, read, read, read$0.086$0.102

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.

Text
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

  1. 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.
  2. 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.
  3. 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" inside cache_control for the longer window. If mixing lifetimes, place hour-long blocks before five-minute blocks.
  4. 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.

Published
Category
Build

Related Articles

DeepSeek Harness: What It Does and How to Start

DeepSeek Harness: What It Does and How to Start

Start DeepSeek’s coding agent in a terminal or desktop app. See which models it runs, what leaves your machine and how to switch off session-log uploads.BuildDec 6
SiteDrop AI: What It Is, What It Costs and How to Start

SiteDrop AI: What It Is, What It Costs and How to Start

Which SiteDrop did you see? Compare the two addresses, see how a shop listing becomes a website, and find out who keeps the files and domain.BuildDec 6
Tinsel Alpha: What It Is and How to Use It in a Coding Agent

Tinsel Alpha: What It Is and How to Use It in a Coding Agent

See where Tinsel Alpha fits in a coding agent, how to call it through Vercel AI Gateway, and which client code to keep off the stealth preview.BuildDec 6
Gemini Implicit Caching

Gemini Implicit Caching

Put shared input first, read cached tokens on each Gemini 4 response, and see how durable storage differs for projects with approved zero data retention.BuildDec 5
Claude Terraform Provider

Claude Terraform Provider

Create one Claude workspace per client, review agent changes before applying them, and see which resources AWS, Google Cloud and Bedrock support.BuildDec 5
Codex CLI Cloud

Codex CLI Cloud

Start and reopen Codex cloud chats from the terminal, choose a project environment, and review local and cloud tasks in the Agent Command Center.BuildDec 5
GPT-Live API: Build a Voice App With WebRTC, a Sideband and Delegation

GPT-Live API: Build a Voice App With WebRTC, a Sideband and Delegation

Build a voice app on the GPT-Live API: open a WebRTC session, attach a sideband, delegate to a backend, keep state, test it and price each call.BuildDec 5
AI SDK 7.1 for TypeScript agents: what to adopt first

AI SDK 7.1 for TypeScript agents: what to adopt first

Which AI SDK 7.1 features belong in your agent? Start with tool ordering and steering, check your 7.0 patch, then choose batch, audio or durable execution.BuildDec 5
Newsletter

One letter, every Sunday.Working systems, not hot takes.

Weekly. No spam. Unsubscribe anytime.