Dev tools

Prompt Caching Explained: Pay Less for Repeated Context

Prompt caching explained: how LLM providers reuse repeated prompt prefixes, Claude, OpenAI and Gemini rules compared, savings and how to get cache hits.

By OmniAI Editorial · Nov 20, 2026 · 11 min read

Prompt caching lets an AI model provider reuse the work it already did on the beginning of your prompt when the next request starts with exactly the same content. Instead of processing a long system prompt, tool definitions, a document or a conversation history from scratch every time, the provider stores the model's internal state for that prefix and charges you a fraction of the normal input price when it's reused, often around 10% of the usual rate, while also cutting time to first token. It works only when the start of the prompt is byte-for-byte identical, so the main skill is ordering your prompt with stable content first and changing content last.

This guide explains how prompt caching works, the KV cache behind it, how prompt caching on Claude, OpenAI and Gemini differs (with a comparison table from each provider's documentation), a worked cost example, how to get reliable cache hits, and the mistakes that silently break caching.

What Is Prompt Caching?

Many AI applications send the same large block of text with every request:

  • a long system prompt with instructions and examples,
  • tool definitions for an agent,
  • a document, codebase or knowledge base the user asks questions about,
  • the conversation history in a chat, which grows each turn.

Without caching, the model reprocesses all of that on every call, and you pay full input price each time. With prompt caching, the provider recognizes that a request begins with a prefix it processed recently, skips the repeated work and bills those tokens at a discounted "cache read" rate.

Prompt caching doesn't change the model's output. The response is the same as without caching; only cost and speed differ.

How It Works: The KV Cache

To understand prompt caching, it helps to know about the KV cache. When a transformer model reads a prompt, each layer computes "key" and "value" vectors for every token, which later tokens use through attention. During a single response, the model keeps these keys and values in memory so it doesn't recompute them for every new token; that's the KV cache.

Prompt caching extends the idea across requests: the provider saves the keys and values for a prompt prefix after one request, and if the next request starts with the same tokens, it loads them instead of recomputing. Because each token's keys and values depend on all the tokens before it, the cached part must be an exact prefix: change one character early in the prompt and everything after it has to be recomputed.

So prompt caching vs KV caching: the KV cache is the model-internal mechanism used during one generation; prompt caching is the provider feature that stores and reuses KV cache data between your requests and bills you less for it.

Two rows drawn in ink, each a long grey bar followed by a light bar of a different length, with a dotted ink line at the boundary and an orange dot on it.
Only an identical prefix can be reused; everything after the first change is reprocessed.

Prompt Caching vs Context Caching vs Response Caching

These terms cause confusion:

  • Prompt caching (Anthropic and OpenAI's term): reusing processed prompt prefixes between requests.
  • Context caching (Google's term for Gemini): the same idea, with implicit (automatic) and, on some models, explicit cache objects that you create and manage with a time-to-live.
  • Response caching or semantic caching: storing whole answers in your own application and returning them when the same (or a similar) question is asked again, without calling the model at all. This is something you build yourself, and it saves the full cost of a call, but only for repeated questions.

Prompt Caching on Claude, OpenAI and Gemini

Here's how prompt caching works with each major provider, compiled from their official documentation. Details vary by model and change often, so check the current docs for the model you use.

Anthropic (Claude)OpenAI (newest models)Google (Gemini)
How to turn it onAutomatic caching with one top-level cache_control field, or explicit breakpoints on content blocksAutomatic; newest models also support explicit breakpointsImplicit caching is automatic on Gemini 2.5 and newer; explicit cache objects on some older models
Minimum cacheable prefix512 tokens on the newest Claude models; 1,024–4,096 on some older ones1,024 tokens2,048–4,096 tokens depending on the model
Cache lifetime5 minutes by default; 1 hour option30 minutes by default; 12 hours option on the newest models (older models use other retention settings)Implicit: short-lived, managed by Google; explicit: you set a time-to-live
Price of a cache read0.1× the base input price0.1× uncached input on the newest models (older models have model-specific rates)Discounted rate for cached tokens (varies by model)
Price of writing to the cache1.25× base input (5-minute) or 2× (1-hour)1.25× (30-minute) or 2.5× (12-hour) on the newest models; no write charge on older modelsNo write surcharge for implicit caching; storage fees for explicit caches
ControlsUp to 4 breakpoints; 20-block lookbackprompt_cache_key for routing and separate accountingExplicit cache objects with TTL where supported
SharingIsolated per organization (and per workspace on some platforms)Shared only within an organizationManaged by Google

Prompt Caching on Claude

Prompt caching on Claude gives you the most direct control. You can:

  • Use automatic caching: add a single cache_control field at the top level of the request, and the API places the cache breakpoint on the last cacheable block, moving it forward as a conversation grows.
  • Use explicit breakpoints: put cache_control on specific blocks (tools, system prompt, documents, messages), with up to four breakpoints, so sections that change at different speeds are cached separately.

Key rules from Anthropic's documentation:

  • The cache covers the full prefix in order: tools, then system, then messages, up to the breakpoint.
  • The default lifetime is 5 minutes, refreshed each time the cache is used; a 1-hour lifetime costs more to write. The lifetime counts from the start of a request, so a response that streams for four minutes leaves only about a minute for the next request to hit the 5-minute cache.
  • Cache hits require 100% identical content, including images, and changes to settings such as tool choice or thinking configuration can break the cache.
  • The API looks back up to 20 blocks from a breakpoint for an earlier cache entry; very long conversations may need an extra breakpoint.
  • Usage fields in the response show how many tokens were written to and read from the cache, so you can measure hit rates.

Tools built on Claude, such as Claude Code, rely heavily on caching because agents resend long contexts on every step. Our guide to Claude pricing covers the base prices that the multipliers apply to.

Prompt Caching on OpenAI

Prompt caching on OpenAI is automatic: prompts of 1,024 tokens or more are eligible, and the API reports cached tokens in the usage data. According to OpenAI's documentation and cookbook:

  • Cache hits need an exact, repeated prefix, so static content should come first.
  • An optional `prompt_cache_key` parameter helps route requests that share a prefix to the same cache, improving hit rates, and on the newest models it also separates cache accounting.
  • On the newest models, OpenAI adds explicit breakpoints and a ttl setting (30 minutes by default or 12 hours in the Responses API), with cache reads at 0.1× the uncached input price and a write charge. Earlier models use automatic caching with no write charge and model-specific cached-input prices.
  • OpenAI says caching can reduce time-to-first-token latency by up to 80% and input costs by up to 90%.

Context Caching on Gemini

Google calls it context caching. Implicit caching is on by default for Gemini 2.5 and newer models: if your request repeats a prefix the system has seen recently, you get the discount automatically. Google advises putting large, common content at the start of the prompt and sending similar requests close together. On some older models you can create explicit caches with a set time-to-live, paying a storage fee while the cache exists, which suits very large documents reused many times; Google's documentation notes that explicit caching isn't supported on its newest Gemini 4 models, which use implicit caching.

A tall light bar and a short grey bar with an orange cap drawn in ink on an ink baseline, with an ink arrow pointing from the tall bar down to the short one.
Cached reads cost a fraction of normal input, so repeated context gets much cheaper.

A Worked Example: What Caching Saves

A support assistant sends a 20,000-token prefix (system prompt, tool definitions and help-centre articles) plus a short 500-token question on every request, at an input price of $3 per million tokens. It handles 10,000 requests a day, and with steady traffic most requests hit the cache.

Without cachingWith caching (95% hit rate, Claude-style pricing)
Prefix tokens per day200 million at $3/M = $600190 million cache reads at $0.30/M = $57, plus 10 million cache writes at $3.75/M = $37.50
Question tokens per day5 million at $3/M = $155 million at $3/M = $15
Daily input cost$615About $110

Input costs fall by roughly 80% in this illustrative example, and responses start faster because the model skips most of the prompt processing. Output tokens are billed normally either way. Real savings depend on hit rate, prefix size and each provider's prices.

Prompt Caching for AI Agents

Agents benefit from prompt caching more than almost any other workload. An agent loop calls the model many times for one task, and each call resends the system prompt, all tool definitions and the growing history of previous steps. Without caching, the cost of each step grows with the length of the history; with caching, most of that history is billed at the cache-read rate. Coding agents in particular send large amounts of repeated context, which is why agent frameworks and coding tools are designed around stable prefixes. If you build agents, keep tool definitions fixed for the whole task, append new steps at the end of the history rather than rewriting earlier messages, and watch cache hit rates as closely as you watch total token use.

How to Get More Cache Hits

  1. Put stable content first: tools and system instructions, then reference documents, then the conversation, then the new user message last.
  2. Keep the prefix byte-for-byte identical: no timestamps, request IDs, random examples or reordered tool lists near the top.
  3. Make the prefix long enough to pass the provider's minimum.
  4. Send related requests close together so the cache doesn't expire; use longer lifetimes for workloads with gaps.
  5. Use routing keys or breakpoints where the provider offers them.
  6. Don't change settings mid-conversation, such as tools or reasoning settings, which can invalidate the cache.
  7. Measure: log cached versus uncached input tokens from the usage fields, and track your hit rate over time.

When Prompt Caching Doesn't Help

  • Short prompts below the minimum length.
  • Prompts that are different every time, such as one-off document summaries.
  • Infrequent traffic, where caches expire between requests.
  • Output-heavy workloads, since caching only discounts input.

For those, other cost levers matter more: smaller models, batch processing and trimming prompts. Our guide on how to reduce LLM costs covers them, and our LLM API pricing comparison shows where cached-input prices fit among providers.

Common Mistakes

  • Putting dynamic content at the top, such as the current date or user name in the first line of the system prompt.
  • Changing tool definitions or their order between requests.
  • Assuming caching is on for a provider where it needs explicit configuration.
  • Ignoring write costs: on providers that charge for cache writes, a cache that's written but rarely read can cost more than no caching.
  • Not measuring hit rates, so broken caching goes unnoticed.

FAQ

What is prompt caching?

Prompt caching is a feature of LLM APIs that stores the processed state of a repeated prompt prefix, such as a long system prompt or document, and reuses it on later requests, charging a discounted rate and reducing latency.

How does prompt caching work?

The provider saves the model's key and value vectors (the KV cache) for a prompt prefix. When a new request starts with exactly the same tokens, it loads them instead of recomputing, so only the new part of the prompt is processed at full cost.

How much does prompt caching save?

Cached input tokens typically cost about 10% of the normal input price on major providers, though rates vary by provider and model, and some charge extra for writing to the cache. Savings depend on how much of your prompt repeats and how often.

What is the difference between prompt caching and context caching?

They're the same idea under different names. Anthropic and OpenAI call it prompt caching; Google calls it context caching, with implicit (automatic) caching and, on some models, explicit caches you create with a time-to-live.

Does prompt caching change the model's answers?

No. Responses are the same as without caching. Prompt caching only affects cost and how quickly the response starts.

All articles

Read next

Language

EnglishEnglish · en TürkçeTurkish · tr DeutschGerman · de العربيةArabic · ar

Account

Enter your email. We’ll send you a sign-in link and a 6-digit code. No password needed.

Sign in

Theme

Language

Show our email address

To keep spam out of our inbox, please confirm your own email first. We will send you a 6-digit code.

We send codes only to these providers: gmail.com, googlemail.com, outlook.com, hotmail.com, live.com, msn.com, proton.me, protonmail.com, pm.me, icloud.com, me.com, mac.com, yahoo.com, aol.com, gmx.de, gmx.net, web.de, t-online.de, yandex.com, omniai.blog