The Complete Guide to Prompt Caching: How It Works, Cost Model, and Implementation
Prompt caching can reduce the input token cost of repeated prefixes by an order of magnitude. This article breaks down the differences between Anthropic's and OpenAI's cache implementations, which scenarios actually save money, and how to reuse the same caching strategy across multiple models with a unified gateway.
What problem does prompt caching solve
In most LLM calls, a substantial portion of the input is the same every time: system prompts, few-shot examples, retrieved fixed documents, and tool definitions (tool schema). Under normal billing, you pay for these repeated input tokens every time, and the attention is recomputed every time as well.
The idea behind prompt caching is straightforward: the server stores the computed result of this prefix, and on the next request, if the prefix is exactly the same, it reuses it directly and only recomputes the newly added part. Anthropic positions it in its [prompt caching documentation](https://platform.claude.com/docs/en/build-with-claude/prompt-caching) as a way to reduce latency and cost; on the OpenAI side, the corresponding mechanisms are automatic prompt caching and batch discounts.
Which scenarios actually save money
Prompt caching is not a switch you flip to save money. It has a clear break-even boundary: number of times the same prefix is reused × prefix length > the extra overhead of writing the cache.
- Long system prompt + multi-turn conversation: system prompts of several thousand tokens with many conversation turns almost always pay off.
- RAG + fixed document set: put unchanging policy documents/knowledge bases in the prefix and let only the user question vary.
- Code agents / tool calls: tool schemas and repository structure descriptions are usually repeated in every call.
- One-off calls with short prefixes: the cost of writing the cache may exceed the savings; do not force caching.
Five common mistakes that invalidate the cache
- Mixing timestamps or random IDs into the prefix: even a single
Date.now()at a fixed position changes the entire prefix. - Dynamically assembling the system prompt: different users get different prefixes, diluting the cache hit rate to near zero.
- Summarizing and compressing historical messages: rewriting once per turn makes the prefix unstable.
- Putting user input first: this is the most common structural mistake; variables should be as late as possible.
- Looking only at the bill and not the hit rate: without a hit rate metric, cache benefits cannot be attributed at all.
Reusing the same caching strategy across multiple models
If your product uses both Claude and GPT, cache semantics are not fully consistent across vendors (who declares cache breakpoints, how long the TTL is, how billing works). Putting this adaptation behind a unified gateway has the benefit that business code maintains only one prompt structure and does not need to be rewritten when switching models.
Admesh's gateway maintains an OpenAI-compatible protocol downstream, so the same prompt structure can switch between vendors by changing only the model field; cache hit billing is reflected uniformly in the usage details of the bill, so you do not need to integrate each vendor's billing semantics separately.
Admesh live rates (excerpt)
Prices come from the live Admesh configuration, in USD per million tokens. See the model catalog for the full list.
| Model Name and ID | Context Window | Enter price / 1M | Output Price / 1M | Cache Hits / 1M |
|---|---|---|---|---|
Claude Fable 5 anthropic/claude-fable-5 | 1M | $3.25 / 1M | $16.25 / 1M | $0.325 / 1M |
Claude Fable 5.1 anthropic/claude-fable-5-1 | 1M | $3.25 / 1M | $16.25 / 1M | $0.08125 / 1M |
Claude Haiku 4.5 anthropic/claude-haiku-4-5-20251001 | 200K | $0.325 / 1M | $1.625 / 1M | $0.0325 / 1M |
Claude Haiku 5.5 anthropic/claude-haiku-5-5 | 1M | $0.0325 / 1M | $0.1625 / 1M | $0.00325 / 1M |
Claude Opus 4.5 anthropic/claude-opus-4-5-20251101 | 200K | $1.625 / 1M | $8.125 / 1M | $0.1625 / 1M |
Claude Opus 4.6 anthropic/claude-opus-4-6 | 1M | $1.625 / 1M | $8.125 / 1M | $0.1625 / 1M |
Claude Opus 4.7 anthropic/claude-opus-4-7 | 1M | $1.625 / 1M | $8.125 / 1M | $0.1625 / 1M |
Claude Opus 4.8 anthropic/claude-opus-4-8 | 1M | $1.625 / 1M | $8.125 / 1M | $0.1625 / 1M |
The above are the standard unit prices for public channels; billing is based on actual token usage. View the complete model catalog
Implementation checklist
- Split the prompt into three parts: 'stable prefix / semi-stable part / user input', with the stable part first.
- Ensure the stable prefix contains no timestamps, random numbers, or user IDs.
- Track cache read/write tokens separately in the bill and convert them into a real hit rate.
- Use a fixed set of evaluation requests for regular regression to confirm that prompt changes have not broken the hit rate.
- Set a lower bound for cache benefit (for example, roll back the prompt structure if it falls below 5%) to avoid optimizing for optimization's sake.
FAQ
How much can prompt caching save?
Can other users read the cached output?
Does the cache remain after switching models?
References
Call these models through one gateway
Admesh provides a unified OpenAI-compatible API: one Base URL and one key for Claude, GPT, DeepSeek and more. New accounts get trial credit that never expires.
