Prompt Caching Across AI Providers: Prices, TTLs and Setup

TL;DR
Prompt caching across OpenAI, Anthropic, Gemini, DeepSeek, Mistral, xAI and Qwen: prices, TTLs, setup code. A reused 100K prefix costs 71-93% less.
Last updated: October 18, 2026
Every major model API now discounts a repeated prompt prefix, but billing splits two ways. "Pay to write, read cheap" covers OpenAI GPT-5.6 and later, Anthropic, and Qwen's explicit cache, all charging 1.25x input on the write; "free write, best-effort hit" covers DeepSeek, Mistral, xAI, Gemini implicit caching and OpenAI models before GPT-5.6. On a 100K-token prefix sent in 20 requests (one write, then 19 reuses), most of the models priced below cut prefix cost by 82-93%. Grok 4.7 is the outlier at about 71%, because its cached rate is 25% of input rather than 10% or less. Use explicit caching when your prefix is large and reuse is predictable. When traffic is bursty, let automatic caching do the work. For the per-model matrix, see models with prompt caching.
This post compares providers. For Claude-only mechanics, the Claude API production guide covers breakpoint placement and hit-rate monitoring, and the Fable 5 caching economics post covers the 5-minute vs 1-hour break-even. Neither is repeated here.
At a glance: how each provider caches#
Everything in this table comes from each provider's caching docs and pricing pages, read on October 18, 2026.
| Provider | Mode | How to turn it on | Minimum | TTL | Write premium | Read rate | Usage field |
|---|---|---|---|---|---|---|---|
| OpenAI GPT-5.6+ | Implicit (default) or explicit | prompt_cache_options.mode, prompt_cache_breakpoint on a content block | 1,024 visible tokens | At least 30m ("30m" is the only value) | 1.25x | 0.1x (0.05x on GPT-6.1 Sol) | input_tokens_details.cached_tokens, cache_write_tokens |
| OpenAI before 5.6 | Automatic | On by default; prompt_cache_retention | Varies with request settings | in_memory (typically 5-10 min) or 24h (on models that support extended retention) | None | Model's cached rate | cached_tokens, rounded down to 128 |
| Anthropic | Automatic or explicit | Top-level cache_control, or cache_control on blocks (max 4 breakpoints) | 512-4,096 by model | 5m or 1h | 1.25x (5m), 2x (1h) | 0.1x default; 0.05x Opus/Sonnet 5.5; 0.025x Fable/Mythos 5.1 | cache_creation_input_tokens, cache_read_input_tokens |
| Gemini implicit | Automatic (2.5 and newer) | Nothing to set | 2,048-4,096 | Not stated | None | 5% of input on Gemini 4 Argon; 10% on 3.8 Flash and 3.1 Pro Preview | usage_metadata cached token count |
| Gemini explicit | Manual (3.x and 2.5; not Gemini 4 Argon) | caches.create, then cachedContent | Per model | Default 1h, no bounds | Storage per hour | Cached rate | cachedContentTokenCount |
| DeepSeek | Automatic disk cache | Nothing to set | Prefix units | Hours to days, best effort | None | 2% of input on deepseek-flash | prompt_cache_hit_tokens, prompt_cache_miss_tokens |
| Mistral | No opt-in flag | prompt_cache_key improves hit odds | 64-token blocks | Not published | None | 10% | prompt_tokens_details.cached_tokens |
| xAI | Available on all Grok language models | x-grok-conv-id header or prompt_cache_key for routing | Not published | Not published | None | 25% on Grok 4.7 | cached_tokens |
| Qwen (Model Studio) | Implicit always on, plus explicit | cache_control: {type: "ephemeral"} on a content block | 1,024 | Explicit 5m, reset on hit | 1.25x (explicit) | Typically 10% explicit / 20% implicit; Qwen3.8-Max is 8.5% explicit / 12.5% implicit | Provider usage fields |
Two things stand out. First, the write premium is identical wherever it exists: OpenAI, Anthropic and Alibaba all charge 1.25x the input rate for a short-lived cache write. Second, the read discount varies more than the write premium. It ranges from 2% of input (DeepSeek flash) to 25% (Grok 4.7).
%% title: Two billing models for prompt caching
flowchart TD
R["Request with a repeated prefix"] --> P{"Provider billing model"}
P --> A["Write premium: OpenAI 5.6+, Anthropic, Qwen explicit"]
A --> A1["First call: prefix at 1.25x (2x for Anthropic 1h)"]
A1 --> A2["Later calls: 0.025x to 0.1x"]
P --> B["No write fee: DeepSeek, Mistral, xAI, Gemini implicit"]
B --> B1["First call: prefix at 1x"]
B1 --> B2["Later calls: cached rate if it hits"]
P --> C["Storage fee: Gemini explicit"]
C --> C1["Per-hour storage plus cached rate"]Prices side by side#
Prices come from the site's verified model dataset (each row checked against the vendor's pricing page on October 17, 2026) and were cross-checked against the caching docs on October 18. Units are USD per 1M tokens.
| Model | Input | Cached read | Cache write | Storage |
|---|---|---|---|---|
| GPT-6.1 Sol (up to 272K input) | $2.00 | $0.10 | $2.50 | - |
| GPT-6 Sol | $2.00 | $0.20 | $2.50 | - |
| GPT-6 Luna | $0.10 | $0.01 | $0.125 | - |
| Claude Opus 5.5 | $4.00 | $0.20 | $5.00 (5m) / $8.00 (1h) | - |
| Claude Sonnet 5.5 | $2.00 | $0.10 | $2.50 (5m) / $4.00 (1h) | - |
| Claude Haiku 5.5 (up to 100K) | $0.10 | $0.01 | $0.125 (5m) / $0.20 (1h) | - |
| Gemini 4 Argon | $2.00 | $0.10 | none (implicit only) | - |
| Gemini 3.8 Flash | $0.75 | $0.075 | none | $0.50 per 1M tokens per hour |
| Gemini 3.1 Pro Preview (up to 200K) | $2.00 | $0.20 | none | $4.50 per 1M tokens per hour |
| DeepSeek deepseek-flash, peak | $0.30 | $0.006 | none | - |
| DeepSeek deepseek-flash, off-peak | $0.15 | $0.003 | none | - |
| Mistral Medium 3.5 | $1.50 | $0.15 | none | - |
| Mistral Large 4 (list) | $1.36 | $0.14 | none | - |
| Grok 4.7 (under 200K) | $2.00 | $0.50 | none | - |
| Qwen3.8-Max (International) | $2.00 | $0.17 explicit / $0.25 implicit | $2.50 (explicit) | - |
Dated changes to know about:
- Gemini 4 Argon doubles from December 1, 2026, to $4 input / $0.20 cached / $20 output per 1M tokens (from $2 / $0.10 / $10).
- Gemini 3.8 Flash doubles from January 1, 2027 ($1.50 input, $0.15 cached, storage $1.00 per 1M per hour).
- Mistral Large 4 showed a 50%-off launch sale on October 17 that was due to end around October 19. The table uses list price.
- Claude Sonnet 5.5 cache reads dropped from $0.20 to $0.10 on October 7, 2026, per Anthropic's release notes.
Cost arithmetic: one 100K prefix, 20 requests#
Here is the scenario. A 100,000-token stable prefix (system prompt, tool definitions, a reference document) is reused by 20 requests, all inside the TTL. That means 1 cache write and 19 reads. Only the prefix's input cost is counted; the per-request suffix and output cost the same with or without caching.
| Model | Uncached | Cached | Saved |
|---|---|---|---|
| DeepSeek flash (peak) | $0.60 | $0.0414 | 93% |
| Gemini 4 Argon (implicit, best case) | $4.00 | $0.39 | 90% |
| GPT-6.1 Sol | $4.00 | $0.44 | 89% |
| Claude Opus 5.5 | $8.00 | $0.88 | 89% |
| Claude Sonnet 5.5 (5m write) | $4.00 | $0.44 | 89% |
| Claude Sonnet 5.5 (1h write) | $4.00 | $0.59 | 85% |
| Qwen3.8-Max (explicit) | $4.00 | $0.573 | 86% |
| Gemini 3.8 Flash (implicit, best case) | $1.50 | $0.2175 | 85.5% |
| Mistral Medium 3.5 | $3.00 | $0.435 | 85.5% |
| Gemini 3.8 Flash (explicit, 1h storage)* | $1.50 | $0.20-$0.275 | 82-87% |
| Claude Haiku 5.5 / GPT-6 Luna | $0.20 | $0.0315 | 84% |
| Qwen3.8-Max (implicit) | $4.00 | $0.675 | 83% |
| Grok 4.7 | $4.00 | $1.15 | 71% |
* Google's caching page does not say how the initial cache creation is billed, so this row is a range. The low end assumes creation is free. The high end bills creation at the standard $0.75 input rate.
How a row is computed, using GPT-6.1 Sol: the write is 0.1M tokens x $2.50 = $0.25, the reads are 19 x 0.1M x $0.10 = $0.19, total $0.44. The uncached cost is 20 x 0.1M x $2.00 = $4.00. For the no-write-fee providers, the first request pays full input and the next 19 pay the cached rate. The Gemini 3.8 Flash explicit row counts 20 reads at the cached rate (20 x 0.1M x $0.075 = $0.15) plus one hour of storage (0.1M x $0.50 = $0.05), which gives $0.20. Billing creation at full input adds 0.1M x $0.75 = $0.075, which gives $0.275. At the high end, explicit caching on this model is slightly worse than the implicit best case for a single hour of 20 requests. It pulls ahead when hits are not guaranteed or when reuse runs longer. DeepSeek off-peak halves its row to about $0.021.
Three caveats matter more than the percentages:
- Implicit rows assume every request hits. DeepSeek, Gemini implicit, xAI, Mistral and Qwen's implicit cache all say in their docs that hits are not guaranteed. A 70% hit rate on a no-write-fee provider still saves money, but less than the table shows.
- The write premium pays for itself on the first reuse. OpenAI's guide gives the arithmetic: one write plus one full reuse costs 1.35x the uncached input, against 2x without caching. One write plus nine reads costs 2.15x against 10x. With a 1.25x write and a 0.1x read, the second request already puts you ahead.
- Long-context cliffs reprice everything. GPT-6.1 Sol above 272K input pays $4 input, $0.20 cached read and $5 cache write for the whole request. Claude Haiku 5.5 over 100K pays $0.50 input, $0.05 cache read, and $0.625 (5m) / $1 (1h) cache writes. Grok 4.7 from 200K prompt tokens pays $4 input and $1 cached read. The cached tokens get repriced along with everything else, so a prefix sitting just under a threshold can double or more in cost (5x on Haiku 5.5) when the suffix pushes the request over it.
To rerun this with your own token counts, use the AI cost calculator.
When is it worth padding a short prefix?#
OpenAI's guide includes a break-even formula for padding a prefix up to the 1,024-token minimum: L = M(r + (w - r)/N). Here M is the minimum, r the read multiplier, w the write multiplier and N the number of requests. With M = 1,024, r = 0.1 and w = 1.25, the crossover is 102.4 + 1,177.6/N tokens. Across 10 requests, expanding any prefix of at least 221 tokens to 1,024 is cheaper than leaving it uncached. The same formula works for Anthropic's 5-minute writes, because the multipliers are the same: plug in that model's minimum and read rate.
Gemini explicit caching: when storage pays#
Gemini's explicit cache replaces the write fee with a storage fee billed per hour of TTL. Storage pays for itself when each cached token is read often enough per hour. Break-even is storage cost per hour divided by the saving per hit (input price minus cached price):
| Model | Storage / 1M / hour | Saving per hit / 1M | Break-even hits per hour |
|---|---|---|---|
| Gemini 3.8 Flash | $0.50 | $0.675 | ~0.74 |
| Gemini 3.1 Pro Preview | $4.50 | $1.80 | 2.5 |
| Gemini 2.5 Flash | $1.00 | $0.27 | ~3.7 |
On Gemini 3.8 Flash, a cache read less than once an hour already covers its storage. On 3.1 Pro Preview you need two or three reads an hour. A document Q&A tool with steady use clears both thresholds easily. A cache left running overnight with no traffic does not.
The bigger change: Google's caching page says explicit caching is not supported on Gemini 4 Argon and later. The newest model has only implicit caching, with a 4,096-token minimum and no cost-saving guarantee. Google's generateContent caching page says explicit caching can be manually enabled on Gemini 3 and 2.5 models, so if you need guaranteed cache pricing on Gemini, you are choosing a 3.x or 2.5 model.
%% title: OpenAI GPT-5.6+ explicit breakpoint
sequenceDiagram
participant App
participant API
participant Cache
App->>API: Request 1: dev message with breakpoint + Q1
API->>Cache: Write prefix at 1.25x
API-->>App: usage.cache_write_tokens
App->>API: Request 2: same prefix and key + Q2
API->>Cache: Look up longest prefix
Cache-->>API: Hit, billed at 0.1x
API-->>App: usage.cached_tokens
Note over API: Suffix after the breakpoint pays the normal rate, no writeHow to turn it on: OpenAI#
On GPT-5.6 and later, caching is on by default in implicit mode. The API places a breakpoint at the end of the latest eligible message: user messages, the last tool response in a group, or the last developer message in the initial group. explicit mode caches only where you place prompt_cache_breakpoint on a content block. In explicit mode with no breakpoints, nothing is cached and nothing is written. A request can make up to four cache writes, and an implicit breakpoint uses one of those slots.
The example below was type-checked against openai@7.38.0 (TypeScript 7.0.2, strict). No API calls were made. prewarm() and ask() share one developer message, one cache mode and one prompt_cache_key, so the prefix the prewarm writes is the prefix ask() reads.
import OpenAI from "openai";
const client = new OpenAI();
const MODEL = "gpt-6.1-sol";
const STABLE_INSTRUCTIONS = "Long, stable instructions and reference material...";
// The cacheable prefix. prewarm() and ask() must send it identically.
const developerMessage: OpenAI.Responses.ResponseInputItem = {
role: "developer",
content: [
{
type: "input_text",
text: STABLE_INSTRUCTIONS,
prompt_cache_breakpoint: { mode: "explicit" },
},
],
};
// One cache per customer: blocks cross-user probing, costs one write per customer
const cacheKey = (userId: string) => `support:${userId}`;
export async function prewarm(userId: string) {
await client.responses.create({
model: MODEL,
prompt_cache_key: cacheKey(userId),
prompt_cache_options: { mode: "explicit", ttl: "30m", prewarm: true },
input: [developerMessage],
});
}
export async function ask(question: string, userId: string) {
const response = await client.responses.create({
model: MODEL,
prompt_cache_key: cacheKey(userId),
prompt_cache_options: { mode: "explicit", ttl: "30m" },
input: [developerMessage, { role: "user", content: question }],
});
const usage = response.usage;
console.log({
input: usage?.input_tokens,
cached: usage?.input_tokens_details.cached_tokens,
written: usage?.input_tokens_details.cache_write_tokens,
});
return response.output_text;
}
// Models before GPT-5.6 use prompt_cache_retention instead
export async function legacy(question: string) {
const response = await client.responses.create({
model: "gpt-5.4",
prompt_cache_key: "support-v1",
prompt_cache_retention: "24h",
instructions: STABLE_INSTRUCTIONS,
input: question,
});
return response.usage?.input_tokens_details.cached_tokens;
}
What to know:
"30m"is the only TTL value. The SDK types reject"1h". An entry stays eligible for at least 30 minutes after its most recent write or reuse, and a reuse refreshes that window without another write charge.- Prewarm is not free, and it only pays off if the next request matches.
prewarm: truebuilds the cache without generating output, and those tokens bill at the cache-write rate. OpenAI's guide says to follow a prewarm with a request that has the same prompt prefix. Because separate keys keep separate caches (see the next two bullets), that request also needs the sameprompt_cache_key: a prewarm under a different key, or with no key, writes a cache that the later request never reads. prompt_cache_keychanged role. Before GPT-5.6, a stable key improved routing to the machine holding your cache (OpenAI suggests around 15 requests per minute per key, since caches live on individual machines). On GPT-5.6 and later, routing is automatic. The key is optional and serves two other purposes: separate per-customer cache accounting, and preventing cache-hit probing across users. Caches are never shared across organizations or regional processing boundaries.- Per-customer keys cost one write per customer. OpenAI's guide says a supplied key separates cache reuse between groups of requests, even when their requests contain the same prefix. With a per-customer key, each customer pays its own 1.25x write for the shared instructions. That is the price of anti-probing isolation. If you do not need isolation, use one shared key (or none) and the prefix is written once.
- Some request changes rewrite the prefix. Changing tools,
parallel_tool_calls,text.format,text.verbosity, compaction settings or the model can break it. On GPT-6 models, to change reasoning effort mid-conversation, append aconfiguration_updateinput item rather than editing top-levelreasoning.effort, which can rewrite hidden instructions. To stop the model from using a tool, usetool_choice: "none"orallowed_toolsrather than removing the tool definition. - Placement limits. Top-level
instructionscannot hold an explicit breakpoint, so put the stable text in a developer message as shown above. - Older models.
prompt_cache_retentionis"in_memory"(typically 5-10 minutes inactive, up to an hour) or"24h"(up to 24 hours, on models that support extended retention: gpt-5.5, gpt-5.5-pro, gpt-5.4, gpt-5.2, the gpt-5.1 family, gpt-5, gpt-5-codex and gpt-4.1). Non-ZDR organizations default to24h. ZDR organizations default toin_memory. GPT-5.5 and 5.5 Pro support only24h. These models have no cache-write charge, and theircached_tokenscount rounds down to a multiple of 128.
How to turn it on: Anthropic#
Anthropic now offers an automatic mode: one top-level cache_control field. The API places the breakpoint on the last cacheable block and moves it forward as the conversation grows. Explicit breakpoints still work by putting cache_control on individual blocks in tools, system or messages. The example below was type-checked against @anthropic-ai/sdk@0.135.0.
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
const STABLE_SYSTEM = "Long, stable system prompt and reference material...";
// Automatic caching: one top-level field, breakpoint moves with the conversation
export async function automatic(messages: Anthropic.MessageParam[]) {
const msg = await client.messages.create({
model: "claude-sonnet-5-5",
max_tokens: 1024,
cache_control: { type: "ephemeral" },
system: STABLE_SYSTEM,
messages,
});
return msg.usage;
}
// Explicit breakpoint with a 1-hour TTL on the system prompt
export async function explicit(question: string) {
const msg = await client.messages.create({
model: "claude-sonnet-5-5",
max_tokens: 1024,
system: [
{
type: "text",
text: STABLE_SYSTEM,
cache_control: { type: "ephemeral", ttl: "1h" },
},
],
messages: [{ role: "user", content: question }],
});
const u = msg.usage;
console.log({
written: u.cache_creation_input_tokens,
read: u.cache_read_input_tokens,
uncached: u.input_tokens,
written1h: u.cache_creation?.ephemeral_1h_input_tokens,
});
return msg;
}
The parts that differ from other providers:
- Lower minimums on most 5.x models. 512 tokens on Fable 5.1, Mythos 5.1, Opus 5.5, Opus 5, Sonnet 5.5, Fable 5, Mythos 5 and Haiku 5.5. 1,024 on Opus 4.8 and the Sonnet 5 / 4.6 / 4.5 line, so Sonnet 5 is the 5.x exception. 2,048 on Mythos Preview and Opus 4.7. 4,096 on Opus 4.6, Opus 4.5 and Haiku 4.5. Shorter prompts run uncached without an error.
- Four breakpoints, and automatic mode uses one. Adding a top-level
cache_controlwhen four explicit breakpoints already exist returns a 400. Each breakpoint looks back at most 20 blocks. - Parallel fan-out misses. A cache entry exists only once the first response begins. Requests sent in parallel before then all pay full price. Pre-warm with
max_tokens: 0, which writes the cache with no output charge. It is rejected with streaming, extended thinking, structured outputs, forcedtool_choiceand inside Message Batches. - Isolation. Caches are per workspace on the Claude API, Claude Platform on AWS and Microsoft Foundry, and per organization on Bedrock and Google Cloud.
- Usage accounting. Total input =
cache_read_input_tokens+cache_creation_input_tokens+input_tokens, whereinput_tokenscovers only what comes after the last breakpoint.
Breakpoint placement for agents, hit-rate monitoring and invalidation debugging are in the Claude API production guide. Whether the 2x 1-hour write beats repeated 5-minute writes is worked through in Fable 5 prompt caching economics.
How to turn it on: Gemini#
Implicit caching needs no code on Gemini 2.5 and newer. Google's advice is to put large shared content at the start of the prompt and send requests with similar prefixes close together in time. Explicit caching is a separate resource: you create it, reference it by name, and delete it when you are done. The example below was type-checked against @google/genai@2.30.0.
import { GoogleGenAI } from "@google/genai";
const ai = new GoogleGenAI({});
const MODEL = "gemini-3.8-flash";
// Explicit cache: create once, reference by name, pay storage per hour
export async function withExplicitCache(corpus: string, questions: string[]) {
const cache = await ai.caches.create({
model: MODEL,
config: {
systemInstruction: "Answer questions about the attached corpus.",
contents: [{ role: "user", parts: [{ text: corpus }] }],
ttl: "600s",
},
});
if (!cache.name) throw new Error("cache was not created");
for (const q of questions) {
const res = await ai.models.generateContent({
model: MODEL,
contents: q,
config: { cachedContent: cache.name },
});
console.log(res.usageMetadata?.cachedContentTokenCount, res.text);
}
await ai.caches.delete({ name: cache.name });
}
// Implicit cache: nothing to configure, just keep the prefix stable
export async function implicit(corpus: string, q: string) {
const res = await ai.models.generateContent({
model: "gemini-4-argon",
contents: `${corpus}\n\n${q}`,
});
return res.usageMetadata?.cachedContentTokenCount;
}
Notes from Google's docs:
- TTL. It defaults to 1 hour when unset, and there are "no minimum or maximum bounds". After creation you can update only
ttlorexpire_time. You cannot read the cached content back, only its metadata. - Delete when done. Storage bills for the TTL, so an explicit
caches.deleteat the end of a batch stops the meter. - Implicit minimums. 4,096 tokens on Gemini 4 Argon, 3.8 Flash, 3.6 Flash and 3.1 Pro Preview; 2,048 on 2.5 Flash and 2.5 Pro.
- Interactions API. Implicit caching works in both stateful (
previous_interaction_id) and stateless modes, and hits show up inusage.total_cached_tokens. - OpenAI-compatible endpoint. Users of the OpenAI library pass
cached_contentthroughextra_body.
DeepSeek, Mistral, xAI and Qwen: no write fee, one knob each#
None of these four needs an opt-in flag for basic caching or charges a write fee for it. What you control is routing, not billing.
DeepSeek: nothing to configure. Context Caching on Disk is on for every account. Each request persists cache "prefix units" at the end of the user input and the end of the model output, plus units at fixed intervals on long inputs. A hit has to match a whole unit. So if you send prefix A+B and then A+C, the second request misses; DeepSeek then persists A as its own unit, so a third request starting with A hits. Cache construction takes seconds, and unused entries are cleared "usually within a few hours to a few days". Read prompt_cache_hit_tokens and prompt_cache_miss_tokens. Off-peak hours halve the hit price to $0.003. The windows are covered in the DeepSeek 4.1 Flash cache and peak-hours post.
Mistral: pass a stable prompt_cache_key. Use a conversation, session or workflow ID, and never put secrets in it. Mistral says the key "increases the chance of a cache hit, but it doesn't guarantee one". Cache blocks are 64 tokens, so cached_tokens is always a multiple of 64 and prompts under 64 tokens never hit. Cached tokens bill at 10% of input. The page does not state a TTL.
xAI: route to the same server. xAI says prompt caching "is available on all grok language models". Entries are stored per server, so set the x-grok-conv-id HTTP header on Chat Completions (or gRPC metadata), or prompt_cache_key on the Responses API, to land on the server that holds your prefix. No TTL is published, and xAI's FAQ says entries "can be evicted at any time due to server load or restarts". To force a miss, change or omit the conversation ID. Grok 4.7's cached input is $0.50 against $2.00 uncached.
Qwen (Alibaba Model Studio): implicit always, explicit by opt-in. The implicit cache cannot be disabled, does not guarantee hits and has no fixed TTL. Explicit caching uses cache_control: {type: "ephemeral"} on a message content block, the same shape as Anthropic's. It lasts 5 minutes and resets on each hit. Both modes need 1,024 tokens. Typical pricing is 125% for explicit creation, 10% for an explicit hit and 20% for an implicit hit. Alibaba lists qwen3.8-max, qwen3.8-max-0902, qwen3.8-flash and qwen3.8-2.4t-a95b as exceptions whose explicit hit price is not 10% and whose implicit hit price is not 20%. On Qwen3.8-Max, QwenCloud's model page lists $0.17 for an explicit hit (8.5% of the $2 input) and $0.25 for an implicit hit (12.5%).
%% title: Will this request hit the cache?
flowchart TD
S["New request"] --> Q1{"Prefix identical byte for byte?"}
Q1 -->|No| M1["Miss"]
Q1 -->|Yes| Q2{"Above provider minimum? 64 to 4,096 tokens"}
Q2 -->|No| M2["Miss"]
Q2 -->|Yes| Q3{"Within TTL? 5m, 30m, 1h or best effort"}
Q3 -->|No| M3["Miss and rewrite"]
Q3 -->|Yes| Q4{"Same server or routing key? OpenAI pre-5.6, xAI, Mistral"}
Q4 -->|No| M4["Possible miss"]
Q4 -->|Yes| H["Hit"]What breaks caches everywhere#
Every provider here caches a prefix, so the same habits break all of them:
- Volatile content early in the prompt. A timestamp, request ID or user name in the first system line makes every prefix unique. Move it after the last breakpoint or into the user turn.
- Editing or reordering tool definitions. On Anthropic, a change to tools invalidates every cache level. On OpenAI, changing tools can break the prefix. Keep tool lists stable and gate them with
tool_choiceorallowed_tools. - Switching model or speed mode. Caches are per model. Anthropic's fast vs standard speed setting invalidates the system and message caches.
- Compaction and summarization. Rewriting earlier history produces a new prefix. Compact rarely, and expect one full-price write after each compaction.
- Changing reasoning effort the wrong way. On GPT-6 models, editing top-level
reasoning.effortcan rewrite hidden instructions. Aconfiguration_updateinput item does not. - Parallel fan-out before the first response lands. This is documented for Anthropic, and pre-warming is the fix. Other providers do not document the timing, but DeepSeek notes that cache construction takes seconds.
- No routing key on per-machine caches. OpenAI before GPT-5.6, xAI and Mistral all hit more often when related requests carry the same key or conversation ID.
- A different cache key on OpenAI GPT-5.6+. Requests with different
prompt_cache_keyvalues keep separate caches even with an identical prefix, so a prewarm or earlier request under another key does not help.
Pick by workload#
| Workload | Reasonable pick | Why, per the docs |
|---|---|---|
| Long stable system prompt plus chat | Any automatic provider, or Anthropic automatic mode | One field or none; the breakpoint follows the conversation |
| Agent loop with many tool calls | OpenAI implicit mode, or Anthropic automatic mode | OpenAI's implicit breakpoint lands on the last tool response in a group; Anthropic moves the breakpoint forward each turn |
| Large document Q&A over hours | Gemini 3.x or 2.5 explicit (check the storage break-even), or Anthropic 1h TTL | Gemini's TTL has no upper bound; Anthropic's 1h write costs 2x once |
| Cheapest cached tokens | DeepSeek flash, off-peak | $0.003 per 1M cache hit, no write fee, best-effort hits |
| Guaranteed cache pricing on the newest Gemini | Not available | Gemini 4 Argon is implicit only; explicit caching means a 3.x or 2.5 model |
| Per-tenant isolation or cost accounting | OpenAI prompt_cache_key per customer; Anthropic workspaces | OpenAI uses the key for per-customer accounting and anti-probing, but each key gets its own cache, so a shared prefix is written once per tenant at 1.25x; Anthropic isolates caches per workspace |
Caching and routing compound: once each provider's cache is warm, sending each workload to the cheapest capable model saves more. Kimi K3 and other providers whose caching docs were not read for this post are out of scope.
FAQ#
Which provider has the cheapest cached input tokens?#
Of the models priced here, DeepSeek's deepseek-flash is cheapest at $0.006 per 1M cached tokens at peak and $0.003 off-peak, with no write fee. Claude Haiku 5.5 and GPT-6 Luna follow at $0.01 per 1M, though both charge $0.125 for a 5-minute write (Haiku's 1-hour write is $0.20).
Do I pay to write to the cache?#
On OpenAI GPT-5.6 and later, Anthropic (5-minute TTL) and Qwen's explicit cache, yes: 1.25x the input rate. Anthropic's 1-hour TTL costs 2x. DeepSeek, Mistral, xAI, Gemini implicit caching and OpenAI models before GPT-5.6 charge no write fee. Gemini explicit caching charges storage per hour instead. On OpenAI, each distinct prompt_cache_key pays its own write for the same prefix.
How long does a cached prompt last?#
- OpenAI GPT-5.6 and later: at least 30 minutes after the last write or reuse.
- Older OpenAI models:
in_memory(typically 5-10 minutes) or24h. - Anthropic: 5 minutes or 1 hour, refreshed on each use.
- Gemini explicit: 1 hour by default, and you can set any TTL.
- Qwen explicit: 5 minutes, reset on hit.
- DeepSeek: hours to days, best effort.
- Mistral and xAI: no TTL published.
What is the minimum prompt size for caching?#
- Anthropic: 512 to 4,096 tokens depending on the model (512 on the 5.5, 5.1 and most 5.x models; Sonnet 5 is 1,024).
- OpenAI GPT-5.6 and later: 1,024 visible tokens.
- Gemini implicit: 2,048 to 4,096.
- Qwen: 1,024.
- Mistral: caches in 64-token blocks.
- DeepSeek: caches by prefix units rather than a fixed minimum.
Does prompt caching change the model's output?#
No. Caching reuses the computation for an identical prefix. Anthropic and DeepSeek both state that the response is still generated normally, and xAI's FAQ says the output "is identical whether the prompt is served from cache or computed from scratch". It changes cost and latency, not the answer.
Sources#
- OpenAI: Prompt caching guide
- OpenAI: API pricing
- Anthropic: Prompt caching
- Anthropic: Pricing
- Anthropic: Claude Platform release notes
- Google: Gemini API caching overview
- Google: Gemini context caching (generateContent)
- Google: Gemini API pricing
- DeepSeek: Context caching
- DeepSeek: Models and pricing
- Mistral: Prompt caching
- Mistral: Chat completion API reference
- Mistral: Pricing
- xAI: Maximizing cache hits
- xAI: Prompt caching best practices
- xAI: Prompt caching usage and pricing
- xAI: Pricing
- Alibaba Cloud Model Studio: Context cache
- Alibaba Cloud Model Studio: Model pricing
- QwenCloud: Qwen3.8-Max
Continue Reading#
Get the next deep dive like this in your inbox
One email a week on Prompt Caching and the rest of the AI dev stack. Free.
Read next on Claude Code
Prompt Caching in the Claude API: A Production Guide
Cut Claude API spend by up to 90% with prompt caching. Real numbers, TypeScript SDK code, and the gotchas Anthropic's docs gloss over.
11 min readPrompt Caching Economics on Fable 5: When the 5-Minute TTL Pays
Fable 5 prompt caching economics: cache-write vs cache-read pricing, 5-minute vs 1-hour TTL break-even math, and worked agent-loop examples.
10 min readClaude Code Prompt Cache: Read the Hit Ratio, Set 5m or 1h TTLs
Claude Code now reports prompt cache hit ratio and miss causes in /usage. How to read it, script a status line, and set 5m or 1h TTLs.
9 min readTechnical content at the intersection of AI and development. Building with AI agents, Claude Code, and modern dev tools - then showing you exactly how it works.








