Prompt caching cuts large language model (LLM) costs when requests reuse the same prompt content and the model provider offers a discounted rate for processing that repeated content. To estimate the savings, compare the normal input-token cost with the cached-input cost for the reusable tokens, then subtract any extra cache fees and account for cache hits, expiration, and provider-specific rules.
What prompt caching does
A language model usually receives instructions and context again with every request. That may include a system prompt, tool definitions, examples, policy text, or a long document. Prompt caching lets a service reuse the computation or stored representation of an eligible prefix rather than treating all those tokens as new input each time.
“Cache” does not always mean the same implementation. Some providers automatically recognize matching prompt prefixes; others expose explicit cache creation, identifiers, or time-to-live settings. A cache may save prefill work, reduce billed input-token charges, lower latency, or do some combination of these. The exact benefit depends on the API and its current pricing rules.
It does not ordinarily make generated output free. Output tokens, uncached input tokens, tool calls, and other billable operations may still be charged normally. Caching also does not make a different prompt equivalent: dynamic text that changes between calls may prevent a shared prefix from being reused.
When caching is most likely to save money
The strongest case is a large, stable prompt repeated across many requests. For example, a support assistant may use the same 4,000-token instructions and reference material for 10,000 conversations. If that prefix qualifies for caching and most requests hit it, the discount can apply repeatedly while users supply different questions afterward.
- Repeated instructions: Long system prompts, output schemas, and tool descriptions reused across a workload.
- Shared context: A stable document or knowledge excerpt placed before request-specific content.
- High repetition: Enough requests arrive while the cache remains valid to amortize any creation or storage charge.
- Meaningful input volume: The eligible prefix is large enough that its discounted processing matters relative to total input and output spending.
Caching may have little value for short prompts, one-off requests, or workloads where the changing portion comes first and disrupts prefix matching. It can also be unattractive if cache creation, storage, or minimum-token requirements outweigh the discounted reads.
How to calculate the savings
Use the provider’s actual prices and count only tokens that are eligible for caching. Let:
- N = eligible repeated input tokens per request
- R = number of requests
- H = fraction of requests that are cache hits, from 0 to 1
- P = normal input price per million tokens
- C = cached-input price per million tokens
- F = cache creation, storage, or other applicable fees for the period
A basic estimate is:
Gross savings = N × R × H × (P − C) ÷ 1,000,000
Net savings = gross savings − F
For a more complete comparison, include the uncached input and output charges on both sides. Those costs generally cancel out when caching changes only the price of the repeated prefix, but they do not cancel if cache use changes the prompt, output length, or number of calls.
Example: Suppose a workload sends a qualifying 4,000-token prefix in 10,000 requests, with an 80% hit rate. For illustration only, assume normal input costs $2 per million tokens and cached input costs $0.50 per million, with no separate fees. The estimated discounted volume is 4,000 × 10,000 × 0.8 = 32 million tokens. Gross savings are 32 × ($2 − $0.50) = $48. If there are cache fees, subtract them; if the hit rate or eligible token count differs, recalculate. These prices are hypothetical, not a quote or a claim about any provider.
Measure eligible tokens and hit rate
Do not estimate from the character count or the total prompt alone. Tokenization varies by model and text, and only a portion of the prompt may qualify. Use the provider’s tokenizer or request usage fields where available, and inspect logs for cached-token counts, cache-read events, or equivalent usage metrics.
Measure over a representative period. A cache hit rate can change with traffic patterns, prompt versions, deployment restarts, and expiration policies. Calculate a weighted rate from the actual eligible tokens served as cache hits, rather than averaging percentages across requests of very different sizes.
Also verify what the billing report calls a cached token. Some systems charge a separate rate for cache writes or creation and another rate for reads. A cache might expire after a fixed duration, or remain available only under specific conditions. Include those effects rather than treating every repeated request as a free hit.
Prompt design and common pitfalls
In systems that cache matching prefixes, place stable content first and variable content later. A useful order is shared instructions, shared examples or reference text, then the user’s changing question. If a timestamp or request identifier is inserted near the beginning, it can make the rest of the prompt different and prevent a match.
- Keep reusable sections byte-for-byte or token-for-token consistent where the provider requires exact matching.
- Check whether tool definitions, images, or other non-text inputs qualify; do not assume every input type is cached.
- Account for minimum prefix sizes, cache lifetimes, and any explicit cache-write charges.
- Do not count the same saved tokens twice when a provider’s usage totals already distinguish cached from ordinary input.
- Compare like with like: same model, workload, output behavior, and billing period.
A common misconception is that a cached prompt is skipped entirely. The model still needs to use the context to answer; caching generally avoids repeating some processing or changes how that input is billed. Another is that caching always reduces response time. It may reduce prompt-processing latency, but network time, queueing, generation length, and other system work still affect total response time.
Cost savings versus latency and alternatives
Cost and speed are related but distinct outcomes. A provider may offer discounted cached input without a guaranteed latency improvement, or faster prompt processing without a large price reduction. Track both billed cost and end-to-end latency before deciding whether a change helped.
For infrequently reused material, alternatives may be better: shorten redundant instructions, retrieve only relevant passages, or move suitable work to a smaller model. These approaches can reduce tokens but may change answer quality or behavior, so evaluate them against the same task and quality criteria. Caching is particularly attractive when the content must remain in the prompt and repeats often.
Frequently Asked Questions
Does prompt caching reduce every LLM request’s cost?
No. It helps only when eligible prompt content is reused and the request gets a cache hit under the provider’s rules. Output and other uncached charges usually remain.
How do I find my prompt-cache hit rate?
Check API usage details, response metadata, or billing reports for cached input tokens or cache reads. Divide the eligible cached-token volume by the total eligible repeated-token volume for the same period.
Does changing one word invalidate a prompt cache?
It depends on the implementation. Prefix-based caches may still reuse an unchanged earlier prefix but not the content after the change. Confirm the provider’s matching rules and inspect usage data.
Is prompt caching the same as retrieval-augmented generation?
No. Caching reuses eligible repeated prompt processing or billing treatment. Retrieval selects relevant information for a request; it can reduce prompt size, and the retrieved content may or may not itself be cacheable.
Can prompt caching make an LLM response faster?
It can reduce some prompt-processing work, but it does not guarantee a faster complete response. Generation, network conditions, and service load also matter.
Related
Method: the standard formula for this calculation, rounded as each result states. See how the calculators work or report an error.
More cards in this drawer
- AI Inference Near the Device: When It Makes Sense
- Immortals Fenyx Rising Co-op, Crossplay and Friends
- Restore Default Settings on a Sons of the Forest Server
- Best Music Streaming Service in India: How to Choose
- How to Clean Gaming Headset Ear Pads Safely
- First Light Trophy List and How to Earn Them