Skip to main content
When you send the same long prefix (a big system prompt, a document, a tool catalog) on call after call, prompt caching lets the provider store that prefix and skip re-processing it next time. On Anthropic (Claude) models this is a real, billable feature: a cache read costs 0.1× the normal input price, so a reused prefix gets ~90% cheaper and comes back faster. It isn’t free, though. Writing the cache costs 1.25× input, and Anthropic’s cache entries expire after 5 minutes (extendable to 1 hour). So caching only pays off when the same prefix comes back within the cache lifetime. If your calls are minutes apart with no reuse, you’d pay the 1.25× write premium every time and never collect the discount. Because of that trade-off, Opper leaves prompt caching off by default and lets you turn it on per request. You decide, because only you know whether your prefix repeats.
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.
The top-level field works on every Anthropic-routable compat endpoint: 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.
If you set both a top-level 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 a ttl, 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, on openai/... 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:
A 12-hour write costs more than a 30-minute one (the model’s 12-hour cache-write rate, 2.5× input on GPT-6.2 Sol instead of 1.25×), so use it only when reads will follow. The usage shows which lifetime you paid for: input_tokens_details.cache_write_tokens_details splits the write into ttl_30m_tokens and ttl_12h_tokens.
  • prompt_cache_options is forwarded as you send it, so the provider’s other settings work too: "mode": "explicit" with a prompt_cache_breakpoint on 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/completions the field is not forwarded: the 30-minute default applies, and the response header x-opper-ignored-params names it.
  • Models before GPT-5.6 use prompt_cache_retention ("in_memory" or "24h") instead, also on responses only.

Keep a session on one cache

A model name without a provider prefix, such as claude-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_key in the request body (chat/completions and responses), the same field OpenAI uses, or
  • an X-Session-Affinity header, on any compat endpoint.
Use a value that names what the calls share: a conversation id for an agent run, or a document id for a batch of questions about one document. Opper keeps calls with the same value together, and calls with different values can still spread across providers. Without a name, Opper still tries to keep your calls together, but a long session can move to a provider that hasn’t cached the prefix yet and pay for one more write.

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.
Every response reports what actually happened in its usage. On 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_options on responses).
  • 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_key in the body or the X-Session-Affinity header keeps calls that share it on one provider.
Last modified on November 24, 2026