Docs / How Agents Talk to Models / Prompt caching
Prompt caching
Caching attacks the one cost history, tools, and MCP all create: the repeated prefix. Mark a stable prefix with
cache_control; the first call pays a one-time write (~1.25× input), every later reuse pays a read (~0.1× input) instead of full price. It cuts input, not output or call count — but on a long, tool-heavy session it takes most of the input bill off the table. It only helps if your prefix is actually stable.history, tools, and MCP all inflate input tokens — the same long prefix (system prompt, tools, early history) re-read on every call. Prompt caching is the provider's fix. You mark a stable prefix with cache_control; the first call pays a one-time cache write (~1.25× the input rate) to store it, and every later call that reuses that prefix pays a cache read (~0.1× the input rate) instead of the full price. The response's usage splits the input into fresh vs cached so you can see it working:
json
// request: mark the stable prefix cacheable (system + tools + old turns)
"system": [ { "type": "text", "text": "You are…",
"cache_control": { "type": "ephemeral" } } ]
// response usage on a later turn — most input is now a cheap cache read
"usage": {
"input_tokens": 210, // fresh tokens, full price
"cache_read_input_tokens": 24000, // reused prefix, ~0.1× price
"cache_creation_input_tokens": 0, // nonzero only on the write
"output_tokens": 420
}Common mistake Assuming caching “just works” once you set
cache_control. The cache keys on an exact prefix match and entries are short-lived (minutes). Change one byte early in the prompt — a rotating timestamp in the system prompt, a reordered tools array, a per-request id — and every downstream token becomes a fresh full-price read again. Caching rewards a stable prefix; a prompt that mutates near the top quietly pays full price while looking cached.Prompt caching re-prices the repeated prefix from full rate to ~0.1×, flattening multi-turn's climb — but only for the bytes that stay byte-identical across calls.