Short Answer

Prompt caching lets you pay a discounted rate for input tokens the provider has recently processed for you. If your system prompt, tool definitions, or document context is large and reused across requests, caching typically cuts input token costs by 60–90% and reduces first-token latency. The trick is architecting your prompt so the reusable portion sits at the very top, then explicitly placing cache breakpoints (on Anthropic/Bedrock) or letting automatic prefix matching kick in (on OpenAI/Gemini/DeepSeek).

If you run any non-trivial LLM application in production, prompt caching is probably the single largest cost lever you have. For agentic systems with long tool definitions, RAG applications with big context windows, or coding assistants that pass the same codebase context on every turn, well-designed caching turns runaway API bills into background noise. And yet a surprising number of teams either don't use it at all or use it wrong.

This piece walks through what prompt caching actually is at the mechanical level, when it pays off, how the major providers implement it, and the specific prompt-design patterns that maximize cache hits. If you've been treating prompt caching as a nice-to-have or a "we'll get to it later" line item, this is the guide to change your mind.

What prompt caching actually is

When a transformer processes a prompt, it produces a large internal state — commonly known as the KV cache — that represents "everything the model has already thought about" as it prepares to generate the next token. That state is expensive to compute; for long prompts, it dominates both the latency and the cost of a request.

Prompt caching is a provider-side optimization: when the provider sees a request whose prefix matches a prefix it has already processed recently, it can reuse the stored KV cache instead of recomputing it from scratch. The result is (a) a much lower per-token bill for the cached portion, and (b) a much lower latency to first token, because the model doesn't have to re-ingest the beginning of the prompt.

The mental model is simple: the top of your prompt is expensive to compute the first time and nearly free after that, as long as (i) the same prefix is reused, (ii) it happens within a short time window, and (iii) the provider actually has capacity to hold the cached state. Everything below the reused prefix — the bit that changes per request — still gets processed normally.

When prompt caching pays off (and when it doesn't)

Caching provides real value when the ratio of "reused tokens" to "unique tokens per request" is high. It provides very little value when almost every request has a novel prompt.

High-leverage cases — these are where caching is a no-brainer:

Low-leverage cases — where caching might cost more than it saves:

How the major providers approach it in 2026

Every serious provider now supports some form of prompt caching, but the mechanics differ. Here's how the current landscape shakes out.

Provider How it works Notes
Anthropic (Claude) Explicit: you place cache_control markers on message blocks. Ephemeral cache with 5-min default TTL; optional 1-hour tier at higher cost. Cache reads at ~10% of standard input rate. Cache writes typically at a modest premium. Explicit control means you can precisely choose which portions of the prompt to cache.
OpenAI Automatic prefix matching. No explicit markers required. Cache is best-effort with short TTL. Cached input tokens billed at a fraction of standard input rate. Simpler to adopt; less control over what gets cached.
Google Gemini Two modes: implicit (automatic, short TTL) and explicit (context caching API with configurable TTL). Explicit context caching is well-suited for long-lived reference documents used across many requests.
Amazon Bedrock Explicit cache markers for supported models (including Claude and Nova families). Behavior largely mirrors the underlying model provider's spec.
DeepSeek Automatic prefix caching for the API. Popular for its aggressive cache-hit pricing; strong choice for high-volume applications with stable prefixes.

The pricing structure varies but the pattern is consistent: cache-hit input tokens are billed at a small fraction of standard input tokens. For long stable prefixes, this dominates the total cost calculation.

The core rule: order your prompt from most stable to least stable

The single most important design pattern is to structure every prompt so that the parts that never change go at the top, the parts that occasionally change go in the middle, and the parts that change every request go at the bottom. In agentic systems, that ordering typically looks like:

  1. System prompt (the assistant's persona, high-level guidance)
  2. Tool definitions (JSON schemas for the tools the model can call)
  3. Long stable context (documents, codebase, knowledge base)
  4. Few-shot examples (if used, and if stable)
  5. Conversation history up to the previous turn
  6. The current user message

If you invert this ordering — for example, if you put the current user query at the top for "clarity" — you've defeated caching entirely. Every request will see a different first token and hit no cache.

Concrete example: caching in the Anthropic SDK

Here's what an explicit cache breakpoint looks like on the Anthropic API. The cache_control marker tells the model "everything up to and including this block is reusable." All subsequent messages in the same conversation will match against the cached prefix.

// Node.js / TypeScript — Anthropic SDK import Anthropic from "@anthropic-ai/sdk"; const client = new Anthropic(); const response = await client.messages.create({ model: "claude-opus-4-7", max_tokens: 1024, system: [ { type: "text", text: LONG_SYSTEM_PROMPT_WITH_TOOL_DEFINITIONS, cache_control: { type: "ephemeral" } } ], messages: [ { role: "user", content: USER_QUESTION } ] });

The cost impact is easy to observe: the response object returns cache_creation_input_tokens and cache_read_input_tokens. On the first request, you'll see a nonzero cache_creation value; on subsequent requests within the TTL, you'll see cache_read take the place of standard input tokens at a fraction of the price.

For applications integrated through the Vercel AI Gateway or a similar routing layer, you can often get automatic caching benefits without changing your application code — the gateway takes care of the provider-specific mechanics.

Common pitfalls (and how to avoid them)

1. Injecting dynamic content near the top

The most common failure mode: a well-meaning developer adds "The current date is {today}" to the top of the system prompt for freshness. Because the date changes every day (or every request), the cache is invalidated. Move dynamic content to the bottom of the prompt, or use dedicated fields that the provider knows to exclude from cache matching.

2. Treating the cache as durable

Provider caches are ephemeral. The default TTL on most providers is a few minutes. If your application makes one request every ten minutes to the same endpoint, you may see no cache hits at all. Design your workload assuming a cold cache is normal; use caching for latency-sensitive high-frequency paths, not for once-a-day batch jobs.

3. Not measuring cache hit rate

Every observable API returns per-request cache statistics. Log them. Watch the ratio of cache reads to cache writes over time. If your hit rate is below 50%, something in your prompt structure is silently invalidating the cache. This is the most common source of confusion — developers deploy caching, don't measure it, and assume it's working. It often isn't.

4. Placing the breakpoint too aggressively

On providers with explicit cache markers (Anthropic, Bedrock), a common mistake is to add a breakpoint at every possible position "just in case." Each cache breakpoint has an associated write cost. Placing them thoughtfully — usually one after tool definitions, one after the long stable context — is better than sprinkling them everywhere.

5. Cache size limits

Providers cache above a minimum token threshold (usually around 1,024 tokens on Anthropic; other providers have their own floors). If your prefix is short, caching won't activate at all. Consolidate rather than splitting into many small blocks.

6. Prompt-tinkering drift

Over the course of a week, developers make small edits to the system prompt — a comma here, a word there. Each edit invalidates the cache. Treat the "stable" prefix as a versioned artifact. Update it deliberately, test the new version, and accept that each update triggers a fresh cache warmup.

Advanced patterns

Cache-friendly retrieval

In RAG systems, the naive pattern is to retrieve the top-K documents fresh on every user turn and inject them into the prompt. This makes every prompt unique and defeats caching. A cache-friendly pattern is to batch the retrieved context at the conversation level: pull the relevant documents once for the whole session, place them in the reusable prefix, and let the model reference them across turns. You'll pay for slightly more tokens per turn, but the cache-hit savings usually swamp the extra token cost.

Two-tier caching for long documents

If you have very long stable documents that dominate the prefix (say, a 100-page contract that a user is asking questions about), and the provider offers a longer-TTL cache tier (Anthropic's 1-hour cache, Gemini's explicit context cache), the math typically tips in favor of paying the higher write cost once and reading the cache many times over the session.

Segmenting by role

When you run different agents (e.g., a "researcher" and a "writer") in a pipeline, they often share substantial common context but have distinct prompts. If you can split the shared context into its own cached block and then append role-specific instructions, both agents get cache hits on the shared portion.

Warming the cache

For latency-sensitive user-facing applications, you can proactively make a "warmup" request just before an expected burst of traffic (e.g., a scheduled meeting, a batch job) so the first user-facing request already hits a warm cache. This is a niche technique but powerful for consumer chat applications with predictable spikes.

How much can you actually save?

The real savings depend heavily on your ratio of "reused prefix tokens" to "unique per-request tokens." A useful back-of-envelope:

For a real application, model your prompt structure on paper first: total tokens in the stable prefix, expected variable tokens per turn, expected turns per user session, expected sessions per minute. The math falls out almost immediately from there.

A production checklist

Before you ship prompt caching

Why this matters for hiring in AI

Prompt caching is one of the diagnostic questions that separates "has actually shipped an LLM app" from "has read a few articles." When you're interviewing AI engineers, ask them how they'd cut a $50k/mo LLM bill in half. If they don't mention caching in the first thirty seconds, they haven't built at scale. If they can explain the specific tradeoffs — write cost vs read savings, TTL selection, prefix ordering, hit-rate observability — they've done the work.

For AI engineers building this expertise: production-grade prompt caching, together with model routing, structured output design, and evaluation harnesses, is the specific bundle of skills that separates AI engineers from ML engineers in the modern job market. Companies hiring for AI infrastructure and LLMOps roles screen for exactly this kind of production judgment.

Browse LLM engineering & ML infra roles

Companies building AI-native products need engineers who understand the production reality of prompt caching, evaluation, model routing, and cost optimization. See who's hiring.

Browse AI/ML Jobs → Explore AI Skills Content →

Frequently Asked Questions

What is LLM prompt caching?+
Prompt caching is a provider-side optimization that stores the intermediate state (usually the KV cache) generated from processing part of a prompt so the same prefix doesn't have to be reprocessed on subsequent requests. When a follow-up request reuses that prefix, the provider bills you at a significantly reduced rate for the cached portion and returns the response faster.
When should I use prompt caching?+
Prompt caching is most useful when you have a large, stable prompt prefix that gets reused many times — for example, a long system prompt with tools and few-shot examples, a large document a user is chatting with, or a codebase context in a coding assistant. If your prefix is small or changes on every request, caching provides little benefit.
How much money does prompt caching save?+
The savings depend on the provider and how much of your prompt is cacheable. On Anthropic's API, cached input tokens are billed at roughly 10% of the standard input rate; on OpenAI they're around 25–50% of the standard rate depending on model and mode. For applications with a large stable prefix — long system prompts, document QA, coding assistants — real-world savings of 60–90% on input costs are common.
How long does a prompt cache last?+
Provider caches are ephemeral. Anthropic's ephemeral cache has a 5-minute default TTL, with an optional 1-hour tier at higher cost. OpenAI's automatic cache lasts a few minutes and is best-effort. Google and Amazon Bedrock offer both implicit short-lived caches and configurable explicit caches. Cache duration is not a durability guarantee — treat cache misses as normal and design accordingly.
Does prompt caching work with tools and structured output?+
Yes, and this is one of the biggest wins. Tool definitions, JSON schemas, and system-prompt scaffolding are typically the largest static portion of a modern agentic call. Putting the cache breakpoint after your tool definitions and system prompt is one of the highest-leverage optimizations available.
What are the pitfalls of prompt caching?+
The most common: (1) invalidating the cache accidentally by injecting dynamic content near the top of the prompt, (2) assuming the cache is durable when it's ephemeral, (3) hitting cache-write costs that exceed the savings if your prefix is used only once, (4) writing prompts where the "reusable" prefix drifts because of prompt tinkering, and (5) not measuring — caching decisions should always be verified with observed cost data.
Do all LLM providers support prompt caching?+
Most major providers now support some form of prompt caching. Anthropic, OpenAI, Google (Gemini), Amazon Bedrock, and DeepSeek all offer it, though the mechanics vary — some are automatic, some require explicit cache markers, and pricing structures differ. If you're using an AI gateway like Vercel's AI Gateway, it can route to whichever backend has the best caching model for your workload.