Prompt Caching: How to Measure Real LLM API Savings

Prompt caching can cut LLM API costs and latency. Learn how Anthropic and OpenAI caching works and how to measure savings.

Pricing and API behavior checked against Anthropic and OpenAI documentation on October 1, 2026. Provider prices and model behavior can change.

Prompt caching reuses a stable prefix of a request instead of processing the same long instructions, tools, examples, or documents from scratch every time. It can reduce input-token cost and sometimes improve latency, but only when the prefix is large enough, ordered consistently, and reused before its cache entry expires.

Short answer: Put stable content first, keep changing user data after it, then measure cache reads and uncached tokens from the provider’s usage fields. Do not quote a headline discount without checking cache misses, write charges, TTL, model pricing, and the workload’s request spacing.
LLM prompt prefix flowing through cache write and cache read paths to reduce API cost
Prompt caching is a billing and latency optimization for repeated input context, not a way to cache the model’s output.

This guide compares the mechanics documented by Anthropic and OpenAI, explains when caching pays off, and gives you a small experiment you can run with your own API workload. The article separates verified provider behavior from measurements that depend on a particular model, account, region, and request pattern.

Why repeated context becomes expensive

Many LLM requests contain two different kinds of input. The first is stable: system instructions, tool definitions, examples, a product handbook, or a large RAG context. The second changes on every request: the user question, a timestamp, or the latest retrieved records.

Without caching, the provider processes the entire input each time. If a support bot sends a 10,000-token handbook with every 500-token question, most of the input is repeated. Caching lets the provider reuse an eligible prefix while processing the new suffix normally.

The benefit is not automatic for every prompt. A short prompt may not meet the minimum cacheable length. A timestamp inserted near the beginning can change the prefix. A request that arrives after the TTL may need a new cache write. A multi-tenant system must also consider whether shared prefixes could reveal information through cache behavior.

The three levers of LLM cost

LeverQuestion it answersTypical action
RoutingWhich model should handle this request?Send simple tasks to a cheaper model and reserve stronger models for hard cases.
ServingHow efficiently can we run a model?Optimize batching, memory, quantization, and infrastructure.
CachingHow often are we paying to process the same input prefix?Keep stable context at the front and measure cache reads.

Caching complements routing and serving. It does not replace either one. A badly routed request can still be expensive after caching, and a poorly structured prompt can miss the cache even when the model supports it.

How prompt caching works

Prompt caching mechanics showing stable prefix, variable input, cache hit, cache miss, and TTL
The reusable prefix must remain stable. The changing user input normally belongs after the cache boundary.

Prefix order matters

Place the content that changes least at the beginning of the request. A practical order is tool definitions, system instructions, stable examples, shared reference material, retrieved context, and finally the user’s current question. The exact hierarchy differs by API, but the principle is the same: preserve the longest useful prefix.

Cache writes and cache reads are different

The first eligible request may create a cache entry. A later matching request can report cached input tokens. Providers may charge differently for creating a cache entry, reading it, and processing input that was not cached. A “90% discount” on cache reads does not mean the entire request is 90% cheaper.

TTL controls reuse

A cache entry is not permanent. Anthropic documents a default 5-minute TTL and an optional 1-hour TTL at a higher cache-write price. OpenAI documents model-dependent retention and TTL behavior. Reuse can refresh the lifetime, but a quiet workload can still experience a miss after expiry.

Anthropic prompt caching

Anthropic supports explicit cache breakpoints through cache_control. You mark the end of a reusable content block, such as a system prompt or tool definition. The Messages API reports fields including cache creation input tokens, cache read input tokens, and uncached input tokens.

Anthropic’s current documentation describes a 5-minute default TTL and a 1-hour TTL option. The 1-hour option costs more for cache creation, while cache reads use the provider’s documented read rate. The API also has limits on breakpoint slots and rules about block ordering, so a complex prompt should be tested rather than assumed to cache exactly as intended.

A useful accounting check is:

total_input_tokens = cache_read_input_tokens \
                   + cache_creation_input_tokens \
                   + input_tokens

The last field is not necessarily the entire request input when caching is active. It can represent only the uncached portion after the last breakpoint. That distinction matters when calculating cost.

OpenAI prompt caching

OpenAI documents automatic and explicit prompt caching, with behavior that depends on the model generation. The API can report cached tokens in the input-token details. On current models, the documented minimum cacheable prefix and retention controls are model-specific, so use the pricing and model documentation for the exact model you deploy.

For the GPT-5 model used in our smoke-test environment, the current pricing page lists standard input at $1.25 per million tokens and cached input at $0.125 per million tokens. That price is model-specific and should not be copied to GPT-5 mini, GPT-4o, or a future model without checking the live table.

OpenAI also documents that cached entries can live on individual machines and that routing, load, region, model, and request structure affect reuse. A cache hit is therefore not a contractual guarantee. Treat cached_tokens as an observed usage field for that request.

What caching does not fix

  • Changing prefixes: A dynamic timestamp, user-specific instruction, or frequently changing tool definition near the front can prevent the intended prefix from matching.
  • Small prompts: If the prompt does not reach the model’s minimum cacheable length, there may be nothing useful to cache.
  • Cache misses: A cold start, expired entry, changed model, changed region, or different request shape can require a new write.
  • Output cost: Prompt caching affects input processing. It does not make generated output tokens free.
  • Rate limits: Cached tokens may still count toward token-per-minute limits. Lower cost does not automatically mean higher throughput.
  • Privacy boundaries: Shared prefixes must not contain information that one tenant should never be able to influence or infer.

A reproducible measurement experiment

Do not start with a provider’s maximum headline discount. Start with the workload you actually operate. A useful test has one fixed prompt prefix, a controlled set of changing questions, and a separate control run with no reusable prefix.

Five-stage workflow for measuring prompt-caching savings from a fixed workload
Measure the same workload twice, log provider usage fields, and calculate cost from the current model pricing table.

Setup

  • Choose one model and record its exact ID, provider, region, date, and pricing page.
  • Create a stable prefix larger than the model’s documented minimum. Include realistic instructions and reference context, not meaningless filler.
  • Prepare 20 to 50 varied questions that are similar to your real workload.
  • Keep output limits, reasoning settings, tools, temperature-equivalent settings, and request order consistent.

Control run

Run the questions with a prefix that is intentionally unique for each request, or use the provider’s documented way to disable caching if available. Keep the total prompt size and output settings as close as possible to the cached run. Log the provider’s usage object and wall-clock latency.

Cached run

Run the same questions with the stable prefix unchanged and the question after the stable content. Repeat the sequence enough times to observe a warm-up request and later reuse. Do not delete the first request from the data; it shows the write or cold-cache cost.

Metrics

MetricWhy it matters
Cached input tokensShows how much input the provider reported as reused.
Cache creation tokensShows the input written into a cache entry when the provider exposes it.
Uncached input tokensShows the changing suffix and any content outside the cache boundary.
Cost per runCalculates the effect using the current model’s input, cached-input, write, and output rates.
p50 and p95 latencyShows typical and slow-tail behavior without overinterpreting one request.
Hit rateShows how often the workload actually reused a prefix.

Cost calculation

cost = (uncached_input_tokens / 1_000_000) * input_rate
      + (cached_input_tokens / 1_000_000) * cached_input_rate
      + (cache_write_tokens / 1_000_000) * cache_write_rate
      + (output_tokens / 1_000_000) * output_rate

Use the provider’s own usage fields and pricing units. If the provider does not expose a cache-write field, do not invent one. Report token counts and say which components could not be separated.

What our smoke test showed—and did not show

We ran a small OpenAI API smoke test with gpt-5, an approximately 9,000-character stable system prefix, and eight changing questions. The API reported 1,280 cached tokens on seven of eight stable-prefix requests; the first request behaved like a warm-up request. This verifies that the usage telemetry can expose reuse in this environment.

We do not present that smoke test as a savings benchmark. The sandbox proxy also reported cached tokens in a separate control attempt, and its routing behavior is not the same as a direct production account. We therefore do not claim a percentage cost saving or a causal latency improvement from that run. The reproducible experiment above is the correct way to measure your own account.

When should you enable prompt caching?

  1. Estimate the repeated prefix size and request frequency.
  2. Check the model’s minimum cacheable length, pricing, and TTL.
  3. Move stable content before variable content.
  4. Run a warm-up and a control workload.
  5. Calculate cost from actual usage fields.
  6. Monitor hit rate, cache age, p50 latency, p95 latency, and errors after launch.

Caching is usually worth testing when the same large prefix is reused many times inside its TTL. It is less attractive when requests are rare, prompts are short, prefixes change often, or privacy rules require strict isolation between tenants.

Production checklist

  • Pin and record the model ID.
  • Keep stable instructions, tools, and examples before user-specific data.
  • Do not place secrets or tenant-private context in a shared prefix without an explicit privacy review.
  • Log cache reads, writes, misses, uncached tokens, request IDs, and model versions.
  • Track p50 and p95 latency separately from cost.
  • Recheck provider pricing and TTL behavior after model or API changes.
  • Use a budget alert so a cache-miss storm cannot silently increase spend.

Frequently asked questions

Does prompt caching cache the answer?

No. It reuses eligible input context. The model still generates a new response for the current request.

Is the advertised discount applied to the whole request?

No. It normally applies to cached input tokens. Uncached input, cache writes, output tokens, and any other provider charges still count.

How large should the stable prefix be?

At least the model’s documented minimum, but large enough to matter for your workload. Use the provider’s current model documentation because thresholds can differ.

Can I use one cache across all customers?

Do not assume that is safe. Separate tenants and review provider retention, routing, data handling, and cache-key behavior before sharing prefixes.

Does caching always reduce latency?

Not always. It can reduce repeated processing, but network conditions, queueing, model load, cache misses, and output generation can dominate the observed latency.

Conclusion

Prompt caching is a useful third cost lever beside model routing and efficient serving. Its value comes from repeated, stable input context. The correct workflow is simple: keep the prefix stable, measure provider usage, calculate cost with current rates, and report misses and TTL effects alongside any savings.

Do not publish a universal “save 80%” claim from a single warm request. A trustworthy result names the model, workload, cache policy, date, usage fields, and limitations.

FE
Written and reviewed by Fouad El Mourabit

Fouad El Mourabit is a Morocco-based technology writer and editor covering artificial intelligence, search, content systems, software, and practical digital workflows.

For corrections or updated sources, visit the PromptSphere About page.

Sources and further reading

  1. Anthropic Prompt Caching documentation — breakpoints, TTLs, usage fields, and cache behavior.
  2. Anthropic pricing — current model input, cache-write, cache-read, and output rates.
  3. OpenAI Prompt Caching guide — automatic and explicit caching, cache telemetry, retention, and model differences.
  4. OpenAI API pricing — current input, cached-input, cache-write, and output pricing by model.
  5. PromptSphere LLM Model Routing — the routing lever that complements caching.
  6. PromptSphere LLM Inference Optimization — serving-side optimization and the difference from API prompt caching.
  7. PromptSphere RAG Evaluation — a workload where repeated context can make caching worth testing.