DevKits
Concept

What is Prompt Caching? How LLMs Discount Repeated Prompt Prefixes

Prompt caching lets you reuse a long, repeated prompt prefix — a system prompt, few-shot examples, or a fixed document — so later requests bill those tokens at a steep discount instead of full price. This guide explains how it works across OpenAI, Anthropic, and DeepSeek, and when it saves real money.

Last updated:

Core Concepts

What prompt caching does
LLM requests often repeat a large, identical prefix — the same system prompt, the same few-shot examples, the same reference document — followed by a small changing part. Prompt caching stores the processed prefix so that on subsequent requests those prefix tokens are billed at a cache-read rate (often around 10% of the normal input price) instead of full price, and are also processed faster. You still pay full price for the fresh, changing tokens.
How providers expose it
The mechanism differs by provider. OpenAI caches automatically for prompts over a size threshold (no code change needed) and shows cached tokens in the usage. Anthropic requires you to explicitly mark cache breakpoints with cache_control on the messages you want cached. DeepSeek and others have their own automatic schemes. In all cases the cached prefix must be an exact, stable match — change one character near the start and the cache misses.
When it actually saves money
Savings depend on two things: how large the cached prefix is relative to the fresh per-request tokens, and your cache hit rate. A big system prompt or document reused across many requests is the ideal case — high hit rate, large prefix, big discount. If your prefix is small or rarely repeats, caching saves little. Model the numbers before restructuring your prompt around it.
Designing prompts to be cache-friendly
Put the stable content first and the variable content last: system prompt and fixed context at the top (cacheable), the user's changing input at the bottom. Avoid sprinkling timestamps, request IDs, or per-user tokens near the start of the prompt — anything that changes early breaks the cacheable prefix and forces a full-price reprocess.

Frequently Asked Questions

How much does prompt caching save?

Cache reads are typically billed at roughly 10% of the normal input token price (the exact discount varies by provider). Real savings depend on how much of each request is the cached prefix and how often it repeats — a large, frequently-reused prefix can cut input cost dramatically, while a small or rarely-repeated prefix saves little.

Do I need to change my code to use prompt caching?

It depends on the provider. OpenAI caches automatically above a size threshold with no code change. Anthropic requires you to mark cache_control breakpoints explicitly. Either way, structure prompts with stable content first so the prefix can be cached.

Why is my cache not hitting?

The cached prefix must match exactly and stay stable. Common causes of misses: a timestamp, request ID, or per-user value placed near the start of the prompt; reordering messages; or the prefix being below the provider's minimum cacheable size.

Try these related tools