- Reusing long system prompts across many requests to cut input token costs.
- Referencing large documents or codebases without re-sending them every call.
- Multi-turn conversations with a large, stable context that doesn’t change between turns.
- RAG pipelines where the same retrieved context is shared across many user queries.
Overview
Prompt Caching is a provider-level feature that caches prompts so that repeated requests are charged at a reduced rate. This is most effective when your requests share a large, stable prefix:- a long system prompt.
- a reference document.
- a tool definition list. Unlike Response Caching, which serves a stored response for identical requests, Prompt Caching still calls the model on every request, at a reduced cost. Both can be used together.
Anthropic
Prompt caching on Anthropic models requires explicit opt-in viacache_control markers on individual message parts. A breakpoint marks the end of a cacheable prefix: the provider caches everything up to and including the marked block, and later requests that share that prefix read the cached portion instead of reprocessing it. On the Anthropic-compatible endpoint, breakpoints pass through exactly as in the native Anthropic API; see the Anthropic Messages API for endpoint details and a multi-turn example.
Supported models
All current Claude models, including Claude Fable 5 and the Opus, Sonnet, and Haiku families.Enabling caching
Add acache_control object to any message part you want to mark as cacheable:
"ephemeral" is the only supported type. You can place it on:
- System message text parts.
- User message text parts.
- User message images, documents, and files (including PDFs).
- Tool definitions.
- Tool result content.
Minimum token thresholds
Caching only activates once the marked content exceeds a minimum token count. Requests below the threshold are processed normally at full cost.Cache TTL
Thettl parameter controls how long cached content persists before expiring.
Example
OpenAI
Prompt caching on OpenAI models is fully automatic. Nocache_control or any request changes are required. The AI Gateway forwards requests normally; OpenAI caches the prompt prefix on its side and applies the discount transparently.
Caching activates on prompts longer than 1,024 tokens, in 128-token increments from that threshold. The API caches the longest matching prefix from prior requests on the same machine.
Cache retention duration is model-dependent and determined by OpenAI. Refer to OpenAI’s prompt caching documentation for the current retention policy per model.
Cache hits are reflected in the response usage object the same way as Anthropic. See Usage in the response below.
OpenAI
Set up your OpenAI API key to use GPT models with automatic prompt caching.
Google Gemini
Google Gemini supports two caching modes through the AI Gateway. Implicit caching is enabled by default on Gemini 2.5 and newer models. No request changes are needed. The AI Gateway forwards requests normally and Google applies the cache discount automatically when a matching prefix exists. Implicit caching activates at a model-dependent minimum: 2,048 tokens on Gemini 2.5 models, higher on newer generations. Verify current thresholds and rates in Google’s caching documentation. Explicit caching is managed by the AI Gateway on supported Gemini models (Gemini 2.5 and newer). Addcache_control markers to system or user message parts (text and files), using the same syntax as on Anthropic models. The gateway creates a Google cache object for the marked content, reuses it on subsequent requests that mark the same content, and lets it expire after the TTL (5m by default, 1h supported). There is no need to create or reference Google cache objects directly.
Google AI
Set up your Google AI API key to use Gemini models with implicit prompt caching.
Usage in the response
On the Responses API (/v3/router/responses), cache activity is reported under usage.input_tokens_details:
cached_tokens counts tokens read from the cache; cache_creation_tokens counts tokens written to the cache. A first request on a new prefix writes the cache (cache_creation_tokens above zero) and subsequent requests read it (cached_tokens above zero).
On the Chat Completions API (/v3/router/chat/completions), cache reads appear under prompt_tokens_details.cached_tokens: