Most of this page is about Anthropic prompt caching. OpenAI and Gemini cache automatically, server-side, with no flag, so there’s nothing to enable. The
cache_control field below is a no-op on those providers, so the same request stays portable across models. On OpenAI GPT-5.6 and later (also on Azure) you can choose how long the cache lives: see OpenAI and Azure: choose the cache lifetime.Which mode to use
The difference matters. The top-level field caches everything up to the latest message, question included. A later call that changes the question no longer matches that prefix, so it writes the cache again instead of reading it.
Growing conversations: top-level cache_control
Add a top-level cache_control to the request body. Opper places a single moving breakpoint at the end of the prompt and advances it as the conversation grows (the “automatic” mode). Each call reads what the previous call cached and writes only the new messages, which is what multi-turn chats and agent loops need.
chat/completions, v1/messages, responses, openresponses, and the Google-shape interactions / generateContent.
Shared prefix: per-block cache_control
To cache a prefix that stays the same while the rest of the prompt changes, put cache_control directly on the last block of that prefix instead of the top level. Everything up to and including that block is cached, and anything after it can change freely. Anthropic allows up to four such breakpoints. This is the same syntax the Anthropic API uses natively, so existing code works unchanged.
Per-block placement is supported on chat/completions (OpenAI shape) and v1/messages (Anthropic shape). Tool definitions come before the system prompt, so a breakpoint on the system prompt caches the tools too.
cache_control and explicit per-block breakpoints, the per-block breakpoints win: Opper won’t add its automatic one on top.
Extend the lifetime to 1 hour
Add attl, at the top level or on a block. Useful when the same prefix comes back every few minutes rather than every few seconds (a long research session, a slow agent, a queue of jobs that share one prompt). A 1-hour write costs 2× input instead of 1.25×, and reads still cost 0.1×.
OpenAI and Azure: choose the cache lifetime
OpenAI GPT-5.6 and later models (the GPT-6 family included) cache every request automatically, onopenai/... and on Azure (azure:eu/..., azure:global/...). The cache lives for at least 30 minutes, and the provider may keep it longer. Writing the cache is billed at the model’s cache-write rate and reading it at the cached-input rate; the model’s page lists both.
When the same prefix comes back hours apart (a nightly job, a document people return to during the day), ask for 12 hours with prompt_cache_options on responses:
input_tokens_details.cache_write_tokens_details splits the write into ttl_30m_tokens and ttl_12h_tokens.
prompt_cache_optionsis forwarded as you send it, so the provider’s other settings work too:"mode": "explicit"with aprompt_cache_breakpointon an input block caches only up to that block.- Name the provider in the model (
openai/gpt-6.2-sol,azure:eu/gpt-6.2-sol). A model name without a provider can be served by a provider that does not take this option, and then the default applies. - On
chat/completionsthe field is not forwarded: the 30-minute default applies, and the response headerx-opper-ignored-paramsnames it. - Models before GPT-5.6 use
prompt_cache_retention("in_memory"or"24h") instead, also onresponsesonly.
Keep a session on one cache
A model name without a provider prefix, such asclaude-haiku-5-5, can be served by more than one provider, and each provider keeps its own cache. To keep the calls that share a prefix on the same provider, give them a stable name:
prompt_cache_keyin the request body (chat/completionsandresponses), the same field OpenAI uses, or- an
X-Session-Affinityheader, on any compat endpoint.
When it’s worth it
Turn it on
A large, stable prefix reused within the cache lifetime: agent loops and multi-turn chat (top-level field), or many questions over the same system prompt, document or tool catalog (breakpoint on that block).
Leave it off
One-shot calls, or calls spaced further apart than the cache lifetime. You’d pay the write premium with no read to recoup it.
chat/completions, prompt_tokens_details.cache_write_tokens is what was written and prompt_tokens_details.cached_tokens what was read. On v1/messages the same numbers are cache_creation_input_tokens and cache_read_input_tokens. Watch them to confirm caching is paying off: reads should dominate writes once your prefix starts repeating. If every call writes and none reads, check that the cached part of the prompt is byte-for-byte the same on each call and that the breakpoint sits at its end.
Reference
- Field:
cache_control, top-level (automatic) or on a content block (explicit). - Value:
{ "type": "ephemeral" }, optionally"ttl": "1h"(default is 5 minutes). - Activates on: Anthropic-family models. No-op on OpenAI / Gemini (they cache automatically; on OpenAI and Azure GPT-5.6 and later, set the lifetime with
prompt_cache_optionsonresponses). - Pricing: cache write 1.25× input (2× with
"ttl": "1h"), cache read 0.1× input. - Breakpoints: up to 4 explicit per-block; or 1 automatic top-level.
- Session key:
prompt_cache_keyin the body or theX-Session-Affinityheader keeps calls that share it on one provider.