Prompt Caching Explained: Lower Costs on Repeated LLM Calls

If your application sends the same long system prompt to an LLM hundreds of times a day, you are paying to reprocess those tokens on every single call. Prompt caching fixes that waste: the provider stores the reusable prefix of your prompt once, and later requests that begin with the identical prefix skip most of the reprocessing. You get lower token costs and faster first tokens on repeated calls, with no change to the model’s answers.

This guide explains how prompt caching works under the hood, which parts of a prompt qualify for caching, and how to structure your prompts so the cache hit rate stays high.

How prompt caching works

When a model processes your prompt, it converts the input tokens into an internal representation called the KV cache. That computation is the expensive part of the prefill phase, and normally it repeats from scratch on every request.

Prompt caching lets the provider keep that computed state and key it to the exact token prefix of your prompt. The first request with a new prefix does the full computation and writes the result to the cache. The next request that starts with the same prefix reuses the stored state instead of recomputing it.

Three rules govern every implementation:

  • Exact prefix match. The cache keys on the beginning of the prompt. If one token changes near the start, everything after that point must be recomputed.
  • Reads are cheap, writes cost extra. The first request that populates the cache typically carries a small markup; subsequent cache hits are billed at a discounted rate.
  • Caches expire. Every provider sets a time-to-live. After the TTL lapses, the entry is evicted and the next request recomputes from scratch.

What qualifies for caching

Caching rewards prompts with a long, stable beginning. The best candidates are:

  • System prompts and developer instructions. The persona, rules, and formatting requirements you attach to every call are ideal cache material.
  • Few-shot examples. Example inputs and outputs that rarely change sit naturally at the front of a prompt.
  • Retrieved documents in RAG pipelines. When several user questions share the same retrieved context, the shared context can be cached.
  • Tool and function definitions. Agentic applications often send hundreds of lines of tool schemas with each turn; these change rarely.

Most providers set a minimum cacheable length, so very short prompts may not qualify. Anthropic, for example, documents a minimum token threshold that varies by model. Check your provider’s documentation for the current number before you plan around it.

Cache writes, cache reads, and the break-even point

The pricing model is simple in structure, even though the exact numbers differ by provider and change over time. Always check the provider’s current pricing page; the figures below are approximate ranges, not quotes.

  • Cache write: the first request pays the normal input price plus a markup. On Anthropic’s API, the markup is roughly a quarter above the base input rate on the standard short TTL window, and higher on the extended one-hour window.
  • Cache read: later requests that hit the cache pay a fraction of the normal input rate. Anthropic prices cache reads at roughly a tenth of regular input tokens; OpenAI’s automatic prompt caching discounts cached input tokens on qualifying requests as well.

The break-even math is straightforward. You pay the write markup once, then collect the read discount on every reuse inside the TTL window. A prompt template that runs dozens or hundreds of times per hour pays back the write cost almost immediately. A prompt that runs once never should be cached at all. The variable that matters is reuse frequency, so start caching with your highest-volume templates first.

Designing prompts for higher cache hit rates

Cache hits depend on the prefix staying byte-identical across requests. Four habits keep the hit rate high:

  1. Put stable content first, dynamic content last. System prompt, few-shot examples, tool definitions, and retrieved context go at the top. The user’s unique question goes at the end. This single reordering is the highest-impact change you can make.
  2. Keep the prefix identical across requests. Do not inject timestamps, request IDs, or per-user greetings early in the prompt. Anything that varies per request belongs at the end, after the cached region.
  3. Use explicit cache breakpoints. Anthropic lets you mark up to four breakpoints in a prompt, so you control exactly which sections get cached. Put a breakpoint after each stable section and leave the dynamic tail uncached.
  4. Batch similar work inside the TTL window. If you process a queue of documents with the same system prompt, run them back-to-back so each request finds a warm cache instead of letting it expire between runs.

TTLs and eviction: how long the cache lasts

A cached prefix does not live forever. Anthropic’s default TTL is five minutes, with an optional one-hour extended window that costs more on the write. OpenAI’s automatic prompt caching manages TTLs internally and refreshes entries on use, so you think about it less but control it less too.

Design for expiry rather than fighting it:

  • Treat a cache miss as a normal event, not an error. Your application must work identically with and without a hit.
  • If traffic is bursty, a periodic keep-alive request can hold the cache warm through quiet gaps. Weigh the keep-alive cost against the savings.
  • Monitor eviction in the provider dashboard. A sudden drop in hit rate usually means the TTL window no longer matches your traffic pattern.

When prompt caching does not help

Caching is not a universal win. Skip it when:

  • Requests are one-off. A single call can never amortize the write markup.
  • The prompt is fully dynamic. If every request differs from the first token, there is no shared prefix to cache.
  • Prompts fall below the provider’s minimum cacheable length. Caching a 50-token prefix buys nothing.
  • Quality requires the dynamic part first. In rare cases, putting user context before instructions improves answers. Test quality before you let cost optimization dictate prompt order.

Measuring your savings

Start with the provider dashboard, which reports cache hit rates and cached token counts directly. For a rough estimate before you implement, multiply three numbers: requests per TTL window, cacheable tokens per request, and the discounted read rate. Compare that against the write markup paid once per window.

Most teams find that one or two templates dominate their bill: the system prompt of the main agent loop, or the shared context block of a RAG pipeline. Cache those first, measure for a week, then decide whether the long tail is worth restructuring. Where prompts repeat in meaning rather than exact wording, semantic caching is the complementary technique to reach for.

The practical takeaway is simple. Keep the repeated, boring parts of your prompts at the front and the unique parts at the end. Prompt caching turns that small structural discipline into a direct cut on your LLM bill and noticeably faster responses on every repeated call.

Ditulis oleh

Firdaus Safari Putra

Founder, PT FirKaizen Digital Solutions

Firdaus Safari Putra adalah founder PT FirKaizen Digital Solutions. Ia membangun dan mengoperasikan infrastruktur server di balik panduan ini, dan menulis berdasarkan apa yang benar-benar ia jalankan, uji, dan ukur — bukan teori.