Skip to main content
Infrastructure

Prefix Caching

Prefix caching is an inference optimization that reuses the KV-cache computed for a shared prompt prefix — system prompts, few-shot examples, retrieved documents — across multiple requests, eliminating redundant prefill compute.

AIDOLS Research Team · Editorial standards

Full definition

When two requests share the first N tokens, the KV-cache for those tokens is identical and can be cached and reused. Anthropic's Prompt Caching, OpenAI's prefix caching, Google's context caching, and vLLM's automatic prefix caching all implement variants. On current Anthropic and OpenAI models, cached input is billed at 10% of the base input price or less, and caching can cut time to first token by up to 85% on long prompts (Anthropic). Cache lifetimes vary: Anthropic's default is 5 minutes with an optional 1 hour, while OpenAI's extended retention can keep entries for up to 24 hours. Cache effectiveness depends on prefix stability — varying tokens at the start defeats caching.

Why it matters

Prefix caching is the highest-impact cost optimization for any LLM workload with long shared context (RAG, agent system prompts, multi-turn chat). Teams not using it on Anthropic or OpenAI APIs typically overpay 3–10x for production traffic.

Example

A coding assistant with a 12k-token system prompt and 8k tokens of retrieved code: with prefix caching, per-query cost drops from $0.18 to $0.03 and TTFT from 2.4s to about 0.5s — a transformative product change.

Next steps

More infrastructure terms

Source & further reading

Primary source: Anthropic — "Prompt caching with Claude" (2024).

Citation policy: this entry is part of the AIDOLS AI Implementation Glossary and may be quoted for research, journalism, and education with attribution to aidolsgroup.com/en/glossary/prefix-caching/.