Prompt caching
When you often resend the same beginning of a prompt (instructions, documents, history), the cache avoids paying full price for it every time. It is the most powerful savings lever for coding assistants and agents.
How it works
The beginning of your request (the “prefix”) is remembered by the model provider. On later requests, if the beginning is strictly identical, the matching tokens are read from the cache instead of being processed again, at a much lower price.
Three kinds of tokens appear in your invoices and in the usage field of each response:
| Type | When | Price |
|---|---|---|
| Normal input | Tokens that are not cached | 100% of the input price |
| Cache write | The first time a prefix is stored | 125% of the input price (5-minute duration), 200% (1-hour duration) |
| Cache read | Later times, as long as the cache is valid | A fraction of the input price, shown in the catalog (often 10%, sometimes less) |
How much it saves
Cost of the same prefix sent several times, as multiples of the input price (5-minute write at 125%, read at 10%):
| Number of requests | Without cache | With cache |
|---|---|---|
| 1 | 1.00 | 1.25 |
| 2 | 2.00 | 1.35 |
| 5 | 5.00 | 1.65 |
| 10 | 10.00 | 2.15 |
| 50 | 50.00 | 6.15 |
The cache pays for itself from the second request. Over a conversation or an agent loop of 50 requests, the repeated part costs about 8 times less.
Enabling it with the native API (Claude)
Add cache_control to the last block of the prefix you want to store. You can set up to four cache points per request.
{
"model": "claude-sonnet-5-5",
"max_tokens": 1024,
"system": [
{
"type": "text",
"text": "You are the company's legal assistant… (long, stable instructions)",
"cache_control": { "type": "ephemeral" }
}
],
"messages": [{ "role": "user", "content": "What does article 7 say?" }]
}Check that the cache works in the usage field of the response:
"usage": {
"input_tokens": 12,
"cache_creation_input_tokens": 4200,
"cache_read_input_tokens": 0,
"output_tokens": 180
}On the next request, cache_read_input_tokens should appear in place of cache_creation_input_tokens.
The rules to follow
- Put stable content first (instructions, documents, tools) and changing content last (the user’s question). A single difference in the prefix invalidates the cache.
- Respect the minimum size: a prefix that is too short is not cached (on the order of 1,000 tokens or more depending on the model).
- Reuse quickly: the 5-minute cache is renewed on every read; after a pause longer than 5 minutes, it expires.
- Do not change the model: the cache is specific to each model.
- Depending on the model family, caching may be automatic and need no setting: in every case, watch the “cache” tokens in the
usagefield of your responses.