Prompt caching explained: cut repeat input costs by 90% or more

Prompt caching explained: cut repeat input costs by 90% or more

Prompt caching lets an LLM provider reuse the work it already did on the start of your prompt, so repeated system prompts, documents and conversation history cost a fraction of the normal input price and start answering sooner. This guide explains how it works at Anthropic, OpenAI and Google, what it saves, what breaks it and how to structure prompts to hit it.

In shortTL;DR
  • Prompt caching reuses the processed prefix of a prompt; the match is exact from the first token, so one changed character invalidates everything after it.
  • On most Claude and GPT-5.6+ models a cache read costs 0.1x the input price and a short-lived cache write costs 1.25x, so the cache pays for itself on the first reuse.
  • Put stable content first (tools, system prompt, documents, examples) and variable content last (the user's question, timestamps, IDs).
  • Check the usage fields on every response: if cache reads stay at zero, something in your prefix changes between requests or the prefix is below the minimum length.
  • Caching never changes the answer: the model still generates fresh output, only the input processing is reused.

What is prompt caching?

Prompt caching is an API feature that stores the model's processed state for the beginning of a prompt and reuses it when a later request starts with exactly the same content. You pay a reduced rate for the reused input tokens, and the model starts answering sooner because it skips recomputing them.

LLM APIs are stateless. Every chat turn, every agent step and every request against the same 40-page manual sends the full context again: tool definitions, system prompt, documents, the conversation so far. Without caching, the provider reprocesses all of it each time and bills you for every token. Our explainer on AI tokens shows how fast that adds up.

With caching, the provider keeps the internal representation of that repeated prefix (often called the KV cache) for a few minutes or hours. Three points cover what people most often get wrong:

  • What is stored is the model's computed state for your input, not a saved answer. The model still generates a fresh response every time, and Anthropic and OpenAI both say caching does not change the output.
  • What is saved is input cost and time to first token. Output tokens cost the same.
  • What it is not is semantic caching. A semantic cache in your app returns a stored answer for a similar question. Prompt caching only reuses identical input.

How does prompt caching work?

Prompt caching works on prefixes: the provider hashes your prompt from the first token up to a cache point and looks for a recent entry with the same hash. If it finds one, it reads that part from cache and processes only what comes after it.

The rule that drives everything else is that the match is exact and starts at the top. Anthropic's docs say cache hits need "100% identical prompt segments" up to the breakpoint. Change one character near the start and every token after it is a miss, even if the rest is identical.

Requests have a fixed order. On the Claude API it is tools, then system, then messages. OpenAI routes requests using a hash of the initial tokens, including tool definitions. So a prompt laid out like this caches well:

cache-friendly prompt layout
1. Tool definitions          (rarely change)2. System prompt             (rarely changes)3. Reference documents       (change per project or per day)4. Few-shot examples         (rarely change)5. Conversation history      (grows by appending)6. The new user message      (changes every request)

And a prompt with Current time: 14:32:07 on line one of the system prompt never caches at all, because the first block differs on every request.

Each cache entry also has a lifetime. Claude's default is 5 minutes, refreshed for free every time the entry is read, so an active chat or agent loop keeps its cache warm. After a gap longer than the lifetime, the next request pays full price to rebuild it.

Warehouse aisle with labeled boxes stacked on high shelves
A cache stores work already done, so the next request can pick it off the shelf instead of rebuilding it.

How much does prompt caching save?

On most current models a cache read costs one tenth of the normal input price, and some newer models charge less than that. The cost you add is a write premium on the first request that creates the entry.

0.1xcache read price on most Claude models
1.25xprice of a 5-minute cache write
512minimum cacheable tokens on Opus 5.5, Sonnet 5.5, Haiku 5.5
5 mindefault cache lifetime, refreshed on each hit
Source: Anthropic, Prompt caching docs (November 2026)

A worked example with Claude Sonnet 5.5, using Anthropic's published prices as of November 2026: base input $2 per million tokens, a 5-minute cache write $2.50, a cache read $0.10 (Sonnet 5.5 reads at 0.05x).

Say a support bot sends a 50,000-token prefix (instructions plus a product manual) with 100 questions inside the cache lifetime:

Without cachingWith caching
First request50K tokens at $2/M = $0.1050K written at $2.50/M = $0.125
Next 99 requests4.95M tokens at $2/M = $9.904.95M read at $0.10/M = $0.495
Total for the prefix$10.00about $0.62

That is about 94% less on the repeated part. The user questions and the output are billed normally in both cases.

When does caching pay off?

The break-even point depends on the cache lifetime you choose:

  • Short lifetime (Claude 5 minutes, OpenAI 30 minutes, 1.25x write): two uses already cost less than two uncached requests (about 1.35x vs 2x on a 0.1x model). Cache anything you reuse even once.
  • Long lifetime (Claude 1 hour at 2x, OpenAI 12 hours at 2.5x): you need at least three uses before it wins. Use it when requests arrive more than 5 or 30 minutes apart but still repeat, such as a user who comes back after lunch.
  • One-off prompts: never cache. You pay the write premium and get nothing back.

For the wider picture of cutting spend (model choice, batching, shorter contexts), see our guide to reducing LLM API costs.

Prompt caching at Anthropic, OpenAI and Google compared

All three providers cache prefixes, but they differ in how you switch it on, the minimum size, the lifetime and the price of writes. The table reflects the official docs as of November 2026; check the linked pages before you budget.

Anthropic (Claude API)OpenAI (GPT-5.6 and later)Google (Gemini API)
How to turn it oncache_control at the top level (automatic) or on up to 4 blocksImplicit mode places a breakpoint for you, or set explicit breakpointsImplicit caching on by default for Gemini 2.5 and newer; explicit caches on Gemini 3 and 2.5
Minimum prefix512 tokens on most Claude 5 models (Sonnet 5: 1,024), up to 4,096 on older ones1,024 tokens4,096 on current models, 2,048 on Gemini 2.5
Lifetime5 min default or 1 h30 min default or 12 hExplicit: 1 h default, any TTL you set
Write price1.25x (5 min), 2x (1 h)1.25x (30 min), 2.5x (12 h)Explicit: storage billed per token per hour
Read price0.1x on most models, 0.05x on Opus 5.5 and Sonnet 5.5, 0.025x on Fable 5.10.1x on most models, 0.05x on GPT-6.1 Sol and TerraAbout 0.1x of input on current models
Usage fieldcache_read_input_tokens, cache_creation_input_tokensusage.input_tokens_details.cached_tokens, cache_write_tokensCache hits reported in usage_metadata

A few details that matter in practice:

  • Anthropic caches only when you ask. Automatic caching (a top-level cache_control) moves the breakpoint forward as a conversation grows. Explicit breakpoints let you cache tools, system prompt and documents separately. Prompts below the minimum are processed without caching and without an error. Cache reads don't count against your rate limits.
  • OpenAI models before GPT-5.6 cache automatically with no write charge, with an in-memory lifetime of about 5 to 10 minutes of inactivity or an extended 24h option set through prompt_cache_retention. GPT-5.6 and later add write pricing, explicit breakpoints and a prompt_cache_options.ttl of "30m" or "12h". A stable prompt_cache_key helps related requests land on the same cache on older models, and OpenAI suggests about 15 requests per minute per key. Cached tokens still count toward tokens-per-minute limits.
  • Google implicit caching has no guaranteed saving; explicit caching (a named cachedContents object you create and reference) guarantees the discount but bills storage for as long as the cache lives. Gemini 4 Argon supports implicit caching only. Gemini prices on several models change on 1 December 2026 and 1 January 2027, so read the pricing page for current numbers.

How do I structure prompts to hit the cache?

Put everything that stays the same at the top, everything that changes at the bottom, and place the cache point at the end of the last block that is identical across requests. Then confirm it with the usage fields.

  1. Order by stability. Tools, system prompt, reference documents and examples first; history next; the new message last. This is the same discipline as good context engineering.
  2. Remove volatile values from the prefix. Dates, times, request IDs, user names and random example order belong after the cache point or in the user message. Write the system prompt so it holds no per-request data.
  3. Serialize deterministically. Sort tool lists and JSON keys the same way every time. A tool list built from an unordered set can reorder itself and silently miss.
  4. Append, don't rewrite. Add new turns to the end of the conversation. Editing or summarizing earlier turns creates a new prefix.
  5. Place the breakpoint on the last stable block. Anthropic warns that putting it on a block with a timestamp or the incoming user message means the hash never matches and every request pays for a write.
  6. Warm the cache before fan-out. A Claude cache entry is available only once the first response starts, so send one request and wait before firing parallel calls that share the prefix. Anthropic also supports pre-warming with max_tokens: 0, and OpenAI has prompt_cache_options.prewarm on GPT-5.6 and later.
  7. Check the numbers on the first two requests, as described in the next sections.

A minimal Claude request with an explicit breakpoint on a long system prompt:

cache_system_prompt.py
import anthropicclient = anthropic.Anthropic()MANUAL = open("product-manual.md").read()  # long, stable reference textresponse = client.messages.create(    model="claude-sonnet-5-5",    max_tokens=1024,    system=[        {"type": "text", "text": "You answer support questions using the manual below."},        {            "type": "text",            "text": MANUAL,            "cache_control": {"type": "ephemeral"},  # add "ttl": "1h" for the 1-hour cache        },    ],    messages=[{"role": "user", "content": "How do I reset my password?"}],)u = response.usageprint("written:", u.cache_creation_input_tokens, "read:", u.cache_read_input_tokens, "uncached:", u.input_tokens)

Run it twice within five minutes. The first call should show a large written number, the second a large read number. Our Claude API tutorial covers the rest of the request format.

What breaks the prompt cache?

Anything that changes the prefix before the cache point breaks it, and the provider rebuilds the cache on the next request at write prices. On the Claude API, a change at one level invalidates that level and every level after it.

ChangeWhat it invalidates (Claude API)
Editing tool names, descriptions or parametersTools, system and messages: everything
Turning web search or citations on or off, or changing speed modeSystem and messages
Changing tool_choiceMessages
Adding or removing imagesMessages
Changing thinking settings or effortMessages (on some models also tools and system)
Switching modelsEverything: each model has its own cache
A gap longer than the cache lifetimeEverything: the entry expired

The silent killers are the ones you don't see when you read the prompt:

  • A timestamp or "today is" line in the system prompt.
  • Tool definitions loaded from a plugin system that adds or reorders tools between requests.
  • A prompt template that shuffles few-shot examples.
  • An SDK or proxy that rewrites the request, for example by converting a block-form system prompt to a plain string and dropping the cache markers.
  • Parallel requests sent before the first one created the cache entry.
Warning

Caching fails quietly. No provider returns an error when your prompt misses or falls below the minimum length; you only see it in the usage fields and the bill.

How do I check that prompt caching is working?

Read the cached-token counts on every response and track the ratio of cache reads to cache writes. A high ratio means the cache works; writes on every turn mean something in your prefix changes.

  • Claude API: cache_read_input_tokens (read from cache), cache_creation_input_tokens (written), input_tokens (after the last breakpoint, uncached). If both cache fields are 0, the prompt was not cached, usually because it was under the minimum length.
  • OpenAI Responses API: usage.input_tokens_details.cached_tokens for reads, plus cache_write_tokens on GPT-5.6 and later.
  • Gemini: cache hits show in the response's usage_metadata.

Log these per request next to cost and latency, and alert when the hit rate drops after a deploy: a changed prompt template is the usual cause. Our guide to LLM observability shows how to wire that up.

How do coding agents like Claude Code use prompt caching?

Coding agents depend on prompt caching more than any other workload, because every step resends a long system prompt, tool list and growing transcript. Claude Code manages caching automatically and orders each request so the system prompt and tools come first, then project context such as CLAUDE.md, then the conversation.

What the Claude Code caching docs say, as of November 2026:

  • On a Claude subscription within plan usage, the main conversation gets the 1-hour cache; with an API key or a cloud provider it gets 5 minutes. Set promptCacheTtl (or CLAUDE_CODE_PROMPT_CACHE_TTL) to 1h or 5m to choose yourself.
  • Switching models with /model makes the next request reread the whole conversation uncached. Pick the model at the start of a session.
  • Editing CLAUDE.md mid-session doesn't break the cache, but the edit also doesn't apply until /clear, /compact or a restart.
  • /compact replaces the history, so the conversation layer is rebuilt; run it between tasks, not mid-task. /rewind returns to a prefix that is already cached.
  • /usage shows a Prompt cache (main) line with the session's hit ratio and, in recent versions, the likely cause of the last miss.

This is a big part of why usage limits and API bills vary so much between sessions of the same length; see Claude Code usage limits. If you run agents for hours on an always-on box, Orkio Insights shows real spend against API-equivalent usage per project and model, which makes a caching regression visible the day it happens.

Prompt caching checklist

Use this before you ship any feature that sends the same context more than once:

  1. List the parts of your prompt that repeat across requests and move them to the top in a fixed order.
  2. Move every per-request value (time, IDs, user data) below the cache point.
  3. Turn caching on: cache_control for Claude, the right prompt_cache_options for GPT-5.6 and later, or an explicit cache for Gemini when you need a guaranteed discount.
  4. Check that the cached prefix is above the model's minimum length.
  5. Pick the lifetime by traffic pattern: short for bursts, long only when the same prefix returns after longer gaps at least three times.
  6. Send two identical requests and confirm a write on the first and a read on the second.
  7. Log cache reads and writes in production and alert on a falling hit rate.

Frequently asked questions

Does prompt caching change the model's answers?

No. Anthropic and OpenAI both state that caching does not affect the output tokens the model generates. Only the processing of the repeated input is reused, so a cached and an uncached request with the same prompt behave the same way.

Is prompt caching the same as semantic caching?

No. Prompt caching reuses the provider's internal processing of an identical prefix and still calls the model for a new answer. Semantic caching is something you build in your own application: it stores finished answers and returns one when a new question looks similar enough, which skips the model call but can return a wrong answer.

How long does a prompt cache last?

It depends on the provider. As of November 2026, Claude caches last 5 minutes by default or 1 hour at a higher write price, refreshed on every hit. OpenAI's GPT-5.6 and later default to 30 minutes with a 12-hour option, and Gemini's explicit caches default to 1 hour unless you set another TTL.

Can other customers read my cached prompts?

No. Anthropic and OpenAI both state that caches are never shared across organizations, and Anthropic also isolates them per workspace on its own API. Anthropic says cached data is held in memory only, not stored at rest, and deleted soon after the cache lifetime ends.

Can I clear the prompt cache manually?

No major provider offers a manual clear as of November 2026. Entries expire on their own after the cache lifetime passes without a hit, and Gemini explicit caches can be deleted because you create them as named objects.

Why are my cache read tokens always zero?

The usual causes are a prompt below the provider's minimum cacheable length, a value that changes on every request inside the prefix (a timestamp, a request ID, reordered tools), or a cache that expired between requests. Compare two consecutive requests byte for byte up to the breakpoint to find the difference.

SOURCES

  1. Anthropic docs: Prompt caching
  2. OpenAI API docs: Prompt caching
  3. Gemini API docs: Context caching
  4. Gemini API pricing
  5. Claude Code docs: How Claude Code uses prompt caching
  • #prompt caching
  • #llm api
  • #cost
  • #claude api
  • #openai
Orkio team

The team building Orkio. We write about putting AI to work: coding agents that run overnight, always-on boxes and pull requests ready by morning.

Keep reading

All posts

07:06 · YOU MERGED #128

Go to sleep. Wake up to pull requests.

Start for $19 a month
© 2026 Orkio · Hosted in Europe TürkçeStatus