Guide

Prompt Caching Explained: How to Cut Your AI API Bill

Every major AI API now lets you pay less for tokens you've already sent once before. It's called prompt caching, and for any app that resends a system prompt, a long document, or conversation history on every call, it's often the single biggest lever on the bill — bigger than switching models.

What prompt caching actually does

Most AI apps send more than the user's new message on every request. A chatbot resends the whole conversation so far. A document assistant resends the PDF it's answering questions about. A coding agent resends the same long system prompt and tool definitions on every turn. Without caching, the provider reprocesses all of that repeated text from scratch, at full price, every single time — even though nothing in it changed.

Prompt caching stores the model's internal representation of a chunk of text the first time it's processed, then reuses that stored representation on later calls that start with the exact same text. The provider still has to read the new part of your prompt normally, but the repeated prefix is served from cache at a steep discount. The catch is the match has to be exact and start from the beginning: change one word in your system prompt, or move the document to a different position in the message, and the cache misses.

How the three big providers implement it

The mechanics differ enough between providers that a strategy tuned for one can silently stop working on another.

ProviderHow it's triggeredCached-token discountTypical cache lifetime
OpenAIAutomatic — no code change needed once a prompt exceeds the minimum length~50–90%, depending on model generationRoughly 5–10 minutes idle by default; some newer models hold a cache up to 24 hours
Anthropic (Claude)Manual — you mark a cache breakpoint in the request90% off on a cache hit; a small premium on the call that first writes the cache5 minutes by default, or 1 hour on request (at a higher write cost)
Google (Gemini)Automatic ("implicit") on 2.5+ models, or manual ("explicit") for guaranteed reuse75–90% off, depending on model and whether explicit caching is usedImplicit: minutes, opportunistic; explicit: set by you, billed for storage time

OpenAI's version requires the least effort: send a prompt over the minimum size (1,024 tokens for most models) with an identical prefix to a recent call, and the discount applies automatically — there's nothing to configure. Anthropic's is the opposite: you have to explicitly mark where the cacheable portion ends, and the very first call that writes the cache costs slightly more than normal, not less, because the provider is doing extra work to store it. That premium only pays off if a later call actually reuses the cache before it expires. Google splits the difference — implicit caching needs no code changes on Gemini 2.5 and newer, while explicit caching gives you a guaranteed, longer-lived cache in exchange for a small storage fee and some setup.

The minimum-length trap

All three providers require the cacheable prefix to clear a minimum token count before caching kicks in at all — commonly in the 1,024–2,048 token range, and higher still for some newer or smaller models. A short system prompt, a two-paragraph set of instructions, or a brief bit of conversation history simply won't qualify, no matter how many times you resend it. This is the most common reason a team tries prompt caching, sees no change in their bill, and concludes it doesn't work: their reused content was never long enough to be cached in the first place. If you want to benefit from caching, it's sometimes worth deliberately front-loading a request with a longer, stable block of instructions or reference material rather than keeping everything terse.

When caching actually pays off

Caching only helps when the same prefix is sent more than once within the cache's lifetime, so the math depends entirely on your traffic pattern:

The other variable is time. A cache that expires after five idle minutes is only useful for traffic dense enough to keep hitting it — a busy production endpoint benefits far more than a script that runs once an hour. That's the practical reason Anthropic's 1-hour cache and OpenAI's longer retention on newer models exist: they trade a higher write cost, or provider discretion, for a wider window in which a hit is likely.

Estimating the real saving

The headline "90% off" numbers describe only the cached portion of a request, not the whole bill. A request with a 4,000-token cached system prompt and a 50-token new question saves close to 90% overall, because almost everything sent was cacheable. A request with the same system prompt but a 3,000-token new question — a long user message or a big chunk of new context — saves far less in percentage terms, because most of the tokens in that call were never eligible for the discount. The saving scales with how much of each request is genuinely repeated, not with the discount rate alone.

To see this in dollar terms for your own usage, run your token counts and monthly request volume through the AI API Cost Calculator, or check how a specific block of text tokenizes with the AI Token Calculator before deciding what's worth caching. If you're comparing models that support caching differently, the AI Model Cheat Sheet lists cached and uncached input prices side by side, and AI Pricing tracks each provider's own published rates as they change.

Frequently asked questions

Do I have to change my code to use prompt caching?

It depends on the provider. OpenAI's automatic caching and Google's implicit caching on Gemini 2.5+ require no code changes — the discount applies on its own once a request qualifies. Anthropic requires you to explicitly mark a cache breakpoint in the request, and Google's explicit caching mode also requires setup in exchange for a more guaranteed, longer-lived cache.

Why did my bill not go down after I tried caching?

The two most common reasons are a prompt that never reached the provider's minimum cacheable length (commonly around 1,024–2,048 tokens), or a prefix that changed slightly between calls — a different timestamp, a reordered instruction, or extra whitespace all break the exact-match requirement and force a full-price cache miss.

Is prompt caching the same thing as fine-tuning or a vector database?

No. Fine-tuning changes the model's weights and a vector database retrieves relevant text for a prompt — both are separate techniques. Prompt caching only affects how a provider bills and processes the exact same block of text when it's sent again unchanged; it doesn't change what the model knows or what gets retrieved.

Last reviewed: · Who maintains this · How it is checked

Drafted with AI assistance and reviewed before publication — not claimed to be hand-written. This is a how-to rather than a factual reference, so it carries no Sources block: attaching official-looking citations to a page that does not need them borrows authority rather than demonstrating it. Where it does state a fact, that fact is checkable, and the tools it points to are on this site. Found something wrong? Tell us — we correct the page and re-date it.