The same 20,000-token prompt sent three ways. Without caching it costs 8 cents. The first cached request writes the cache and costs 10 cents. The second request reads the cache and costs 0.4 cents, which is 20 times cheaper than no caching. Same Prompt, Second Request, 20x Cheaper $0.080 no caching $0.100 request 1: cache write $0.004 request 2: cache read Input cost of a 20,000-token prompt on Claude Opus 5.5

Send a 20,000-token prompt to Claude Opus 5.5 and the input costs 8 cents. Send the same prompt again a minute later, with caching on, and the same tokens cost 0.4 cents. The model did not get faster or cheaper. It skipped work it did one minute earlier.

This post explains what that work is, why the provider can skip it, and why it can skip it only for the start of a prompt. Then it shows how to switch caching on with Claude, OpenAI and Gemini, and what it costs. It also covers how to read the usage counters and where caching pays off. It ends with six myths. The next post in this series, One Timestamp, a 17x Input Bill, shows twelve ways teams break the cache without an error.

About the numbers. The prices are the Claude Opus 5.5 list prices on 1 December 2026, from the Anthropic prompt caching docs. Input costs $4 per million tokens and output costs $20. A 5-minute cache write costs $5, a 1-hour cache write costs $8, and a cache read costs $0.20. Other models use different prices, but the method is the same.
Part 1What the model does with your promptThe work that caching saves

Two phases: read the prompt, then write the answer

A language model answers a request in two phases.

  1. Prefill. The model reads every input token: tools, system prompt, history and the new message. For each token, in each layer, it computes two vectors called the key and the value. Together they are the key-value cache, or KV cache. The model can process the input tokens in parallel, but a long prompt still takes real compute.
  2. Decode. The model writes the answer one token at a time. Each new token looks back at the keys and values of every earlier token. The model keeps the KV cache in memory so that it does not compute those vectors again for each output token.

Inside one request, the KV cache already exists. Without prompt caching, the provider deletes it when the request ends. The next request with the same 20,000-token system prompt computes the same keys and values again from zero.

Prompt caching keeps the KV cache after the request ends. If the next request starts with the same tokens, the provider loads the saved keys and values and runs prefill only on the new tokens. The Anthropic docs say: "KV cache representations and cryptographic hashes are held in memory for the cache TTL." The OpenAI docs say the same thing in other words: "The prompt cache stores key-value (KV) tensors, not the tokens themselves."

Two requests with the same system prompt. In request 1, prefill computes keys and values for the whole 20,000-token system prompt and the new message, then saves them. In request 2, the saved keys and values for the system prompt load from the cache, and prefill runs only on the new message before decode writes the answer. Request 1: cache miss prefill: system prompt (20,000 tokens) compute keys and values for every token new msg decode: answer saved KV cache (TTL) Request 2: cache hit load: system prompt (20,000 tokens) no prefill work for these tokens new msg decode: answer

Why the cache works only for a prefix

The key and value of a token depend on the token itself and on every token before it. In each layer, a token's state mixes in information from all earlier tokens. Take token 500 in two prompts. One prompt starts "You are a support agent", and the other starts "You are a lawyer". Token 500 has different keys and values in each.

A bank statement works the same way. Each line shows a running balance, and each balance depends on every line above it. If you change line 3, the balance on line 3 and every line after it changes. Lines 1 and 2 stay the same.

Eight tokens in a row. Token 4 changes. Tokens 1 to 3 keep their saved keys and values and come from the cache. Tokens 4 to 8 depend on token 4, so they must be computed again and billed again. Token 4 changes. Every token after it changes too. t1 t2 t3 t4 (new) t5 t6 t7 t8 read from cache same tokens, same saved state computed again, billed again each one depends on t4

So the provider can reuse saved state only for an exact prefix: the tokens from the start of the prompt up to the first difference. The Anthropic docs say: "Cache hits require 100 percent identical prompt segments." A change near the end of the prompt costs little. A change near the start costs almost everything.

The order of the prompt

Because only the prefix caches, the order in which the API builds the prompt matters. On Claude: "Cache prefixes are created in the following order: tools, system, then messages." Gemini uses a similar order: tools and config, then system instructions, then the conversation.

That gives one rule for every prompt: put what changes least at the start, and what changes most at the end. The Gemini docs say: "Keep static fields at the top and volatile fields at the end."

Part 2How to turn it onClaude, OpenAI and Gemini

Claude: you mark what to cache

On Claude, you add cache_control to a content block. That block is a breakpoint. The API caches the prefix up to and including that block. You can set up to 4 breakpoints in one request.

TypeScript
import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic();

const response = await client.messages.create({
  model: "claude-opus-5-5",
  max_tokens: 16000,
  system: [
    {
      type: "text",
      text: SUPPORT_PROMPT, // 20,000 tokens, the same on every request
      cache_control: { type: "ephemeral" }, // breakpoint: cache everything up to here
    },
  ],
  messages: [{ role: "user", content: "Can I return a jacket after 40 days?" }],
});

console.log(response.usage);

For a chat, there is a simpler option. Put one cache_control field at the top level of the request. The docs say: "The system automatically applies the cache breakpoint to the last cacheable block and moves it forward as conversations grow." Each turn then reads the whole conversation before it from the cache.

TypeScript
const response = await client.messages.create({
  model: "claude-opus-5-5",
  max_tokens: 16000,
  cache_control: { type: "ephemeral" }, // automatic: the API places the breakpoint
  system: SUPPORT_PROMPT,
  messages: history,
});

The default lifetime is 5 minutes. Each cache read resets the timer at no cost. For longer gaps, use { type: "ephemeral", ttl: "1h" }.

OpenAI: on by default

The OpenAI docs say: "Prompt caching is enabled by default for supported OpenAI models." You do not mark anything. The API looks for a matching prefix on each request. On GPT-5.6 and later, the minimum is "1,024 visible input tokens". Newer models also have an explicit mode with breakpoints, and a prompt_cache_key that the docs say influences routing. The OpenAI docs warn that a matching prefix "does not guarantee that every request reuses stored KV tensors or has lower latency."

Gemini: implicit by default, explicit if you want a guarantee

The Gemini docs say: "Implicit caching is enabled by default on all Gemini 2.5 and newer models." Implicit caching has no storage fee, but it is "opportunistic and offers no guaranteed retention window or cost savings." For a guarantee, create an explicit cache with caches.create. Explicit caching works on Gemini 3 and 2.5. An explicit cache has a TTL that "defaults to 1 hour" and prorated storage billing for as long as it lives.

ClaudeOpenAIGemini
How you turn it oncache_control on a block, or one top-level fieldOn by defaultImplicit on by default. Explicit with caches.create
Match ruleExact prefixExact prefixExact prefix
Minimum prefix512 to 4,096 tokens, by model1,024 tokens on GPT-5.6+4,096 tokens on Gemini 3.x (implicit)
Lifetime5 minutes, or 1 hour, reset on each read30 minutes by default on GPT-5.6+, or 12 hoursImplicit: best effort, up to 24 hours. Explicit: 1 hour by default
Cached-token counterusage.cache_read_input_tokensusage.input_tokens_details.cached_tokensusage_metadata.cached_content_token_count
Part 3What it costsA write premium, a read discount and a timer

The price list

Caching on Claude has three prices for input tokens, plus the normal price for tokens it does not cache. On Claude Opus 5.5:

Token typePrice per millionCompared with normal input
Normal input (no cache)$4.001x
Cache write, 5-minute TTL$5.001.25x
Cache write, 1-hour TTL$8.002x
Cache read$0.200.05x
Output$20.00not affected by caching

On most other Claude models, a cache read costs 0.1x. Opus 5.5 and Sonnet 5.5 read at 0.05x. OpenAI says cached input is "discounted up to 95%". Gemini says: "Cached input tokens cost 95% less on Gemini 4 models and up to 90% less on Gemini 3 and 2.5 models."

The first request pays more than normal, because it writes the cache. Caching saves money only when later requests read what the first one wrote.

When caching pays off

Take the 20,000-token prompt again and count the cost of the cached part for a number of requests within the TTL:

RequestsNo caching5-minute TTL1-hour TTL
1$0.080$0.100 (costs more)$0.160 (costs more)
2$0.160$0.104$0.164 (costs more)
3$0.240$0.108$0.168
10$0.800$0.136$0.196
100$8.000$0.496$0.556

With the 5-minute TTL, caching pays off from the second request. With the 1-hour TTL, it pays off from the third. After that, each extra request costs 0.4 cents instead of 8 cents.

The condition is "within the TTL". If requests arrive every 10 minutes, a 5-minute entry expires between them. Every request then writes, and none reads. That traffic pays 1.25x on every request, which is more than no caching. A 1-hour TTL fixes that case. As a rule, look at the gap between requests that share a prefix. Use 5 minutes for gaps under 5 minutes. Use 1 hour for gaps between 5 and 60 minutes.

What else you get

  • Faster first token. The provider skips prefill for the cached tokens. The Anthropic docs say caching "significantly reduces processing time", and mention "improved time-to-first-token for long documents". None of the three providers gives one fixed number, because the gain depends on the prompt length.
  • More headroom on rate limits. On the Claude API, cache reads do not count against input-token rate limits on most models.
Part 4How to read the countersThe only proof that caching works

Three numbers in every response

Every Claude response has a usage object with three input counters:

  • cache_creation_input_tokens: tokens the API wrote to a new cache entry. These cost the write price.
  • cache_read_input_tokens: tokens the API read from the cache. These cost the read price.
  • input_tokens: tokens after the last breakpoint. The API did not read or write them, and they cost the normal price.

The total prompt size is the sum of all three. Here is what the support bot's first two requests look like. This example uses round numbers:

JavaScript
// Request 1, 10:00:00 — cache miss, the API writes the entry
{ "cache_creation_input_tokens": 20000, "cache_read_input_tokens": 0,     "input_tokens": 14, "output_tokens": 180 }

// Request 2, 10:01:12 — cache hit, the API reads the entry
{ "cache_creation_input_tokens": 0,     "cache_read_input_tokens": 20000, "input_tokens": 17, "output_tokens": 205 }

Watch input_tokens in this example. It is small in both requests, because it counts only the tokens after the breakpoint. A dashboard that graphs only input_tokens cannot tell a hit from a miss. Graph the hit rate instead: cache_read_input_tokens divided by the sum of all three.

Parallel requests do not share the cache at once

One detail surprises many teams. The docs say: "a cache entry only becomes available after the first response starts." If a batch job sends 50 requests with the same prefix at the same moment, none of them finds an entry. All 50 write, and all 50 pay the write price.

The fix is simple. Send one request first. When its response starts, send the other 49. They then read the entry that the first one wrote.

TypeScript
// Warm the cache with one request, then fan out.
const first = await client.messages.create(buildRequest(docs[0]));
const rest = await Promise.all(docs.slice(1).map((d) => client.messages.create(buildRequest(d))));
Part 5Where it pays offLong, repeated prefixes

Caching helps most when many requests share a long start. The Anthropic docs list these cases:

  • Conversational agents. A long system prompt, and a history that grows each turn. Each turn reads everything before it.
  • Coding assistants. Parts of a code base, or a summary of it, stay in the prompt across many questions.
  • Large documents. A contract, a manual or a book in the prompt, and many questions about it.
  • Detailed instructions and examples. The docs mention "20+ diverse examples of high-quality answers". Without caching, every request pays for all of them.
  • Agentic tool use. An agent makes a new API call for each step, and each call sends the whole history again.

Agents are the largest case. Each step adds a tool call and a tool result, and then the agent sends the whole conversation again. The input grows with every step, and the output per step stays small. The Manus team reported an average input-to-output token ratio of "around 100:1" for their agent, in Context Engineering for AI Agents: Lessons from Building Manus. When input is 100 times the output, the input price decides the bill, and caching decides the input price. The same post calls the KV-cache hit rate "the single most important metric for a production-stage AI agent".

Caching helps little in three cases:

  • Short prompts below the model's minimum size. They do not cache at all.
  • Prompts that are different from the first token onward. There is no shared prefix to reuse.
  • Rare requests, with gaps longer than the TTL. Every request is a write.
Part 6MythsWhat prompt caching is not

Myth: "Prompt caching stores the answer."

Reality. It stores the processed prompt, not the response. The Anthropic docs say a request "caches its request content (not the response)". The model writes a new answer every time. A cache that returns a stored answer for a similar question is a different technique, often called a semantic cache. You build that one yourself, and it can return a stale or wrong answer. Prompt caching cannot.

Myth: "Caching changes or lowers the quality of the output."

Reality. The Anthropic docs say: "Prompt caching has no effect on output token generation. The response you receive is identical to what you would get if prompt caching were not used."

Myth: "Caching makes the whole bill smaller."

Reality. It changes only the price of input tokens. Output tokens cost the same. A workload with short prompts and long answers saves little. An agent with a 100:1 input-to-output ratio saves a lot.

Myth: "Once cached, always cached."

Reality. An entry lives for its TTL, and on Claude each read resets the timer. Gemini's implicit cache is best effort, with no guaranteed retention. The provider keeps the entry in memory, not in a database, and it expires when traffic stops.

Myth: "Requests sent at the same time all get the discount."

Reality. The entry exists only after the first response starts. Requests sent before that all miss and all write. Warm the cache with one request first.

Myth: "Another company with the same prompt could read my cache."

Reality. The Anthropic docs say: "Different organizations never share caches, even if they use identical prompts." On the Claude API, workspaces in the same organization also have separate caches.

What to remember

  • Prompt caching saves the keys and values that the model computes for your prompt, and reuses them on the next request.
  • It works only for an exact prefix, because each token's state depends on every token before it.
  • Put what changes least at the start of the prompt and what changes most at the end.
  • The first request pays more. Caching saves money from the second or third request within the TTL.
  • The usage counters are the only proof. Graph the hit rate, not input_tokens.

All of this works only while the prefix stays the same. In production, small changes break it with no error: a timestamp, a JSON key order, a tool list or a feature flag. The next post, One Timestamp, a 17x Input Bill, lists twelve of them and the fix for each.

Sources