본문으로 건너뛰기

Automatic Prompt Caching

Automatically injects cache_control into multi-turn calls to Anthropic models, so you get cache discounts with zero setup.

Anthropic prompt caching is opt-in — it only works if you attach cache_control markers yourself, so you miss the discount if you don't know about it. PleumRouter automatically injects cache breakpoints into multi-turn calls routed to Anthropic models — no request changes needed, enabled by default.

multi-turn call — nothing to add
curl https://apirouter.pleum.ai/v1/chat/completions \
  -H "Authorization: Bearer $PLEUM_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "claude-sonnet-4-6",
    "messages": [
      {"role": "system", "content": "<long system prompt, 4000+ chars>"},
      {"role": "user", "content": "First question about the document."},
      {"role": "assistant", "content": "..."},
      {"role": "user", "content": "Follow-up question."}
    ]
  }'

How it decides#

Explicit always wins — if you attached cache_control anywhere in the request yourself, auto-injection backs off entirely. Requests already using explicit caching keep working unchanged.

No-op on the first turn — if the conversation has no assistant message yet (a first request), nothing is injected. It only intervenes on multi-turn conversations, where reuse is certain.

At most 2 injection points — the last block of the system prompt, and the last block of the second-to-last user message (where multi-turn prefix reuse is maximized). Each point is only used when its content totals at least 4,000 characters (matching Anthropic's minimum cacheable size).

Injection happens only inside the request after it is converted to the Anthropic API format, so even if a fallback ends up serving the request from another (OpenAI-compatible) provider, cache_control never leaks there.

Why not inject on the first turn: an Anthropic cache write costs 1.25× the regular input rate, and a one-shot request never gets the read discount — it would pay the surcharge for nothing. By intervening only on multi-turn conversations, auto-injection can never make you worse off.

Billing and the response#

On a cache hit, the response usage exposes prompt_tokens_details.cached_tokens (hit tokens) and cache_creation_input_tokens (write tokens), and the discount/surcharge is applied to billing automatically. The rates are in the per-provider table below.

usage on a cache hit
"usage": {
  "prompt_tokens": 12480,
  "completion_tokens": 210,
  "prompt_tokens_details": {"cached_tokens": 11900},
  "cache_creation_input_tokens": 0
}
If you want caching from the very first turn (when you know a conversation will follow) or want to control breakpoints yourself, specify cache_control explicitly — auto-injection steps aside and only your markers apply.

Per-provider behavior#

Automatic cache-breakpoint injection only happens on Anthropic requests converted to the Anthropic Messages format. Other providers such as OpenAI, Google and DeepSeek run their own implicit caching, so no markers are needed. How billing reflects it:

ProviderCachingBilling
AnthropicCache breakpoints auto-injected on multi-turn calls (explicit cache_control is passed through)Read 10% · Write 125%
OpenAI · Google · Vertex AI · DeepSeekProvider-side implicit caching — hit tokens surfaced in usageRead 10% (DeepSeek 2%) · no write surcharge (OpenAI GPT-5.6 and later models: write 125%)
Other OpenAI-compatibleProvider-side implicit caching — hit tokens surfaced in usageDiscounted where a model publishes cache rates, full price otherwise
Cache-hit tokens are surfaced in usage for every provider, so you can always see whether a cache hit happened — including on providers still billed at full price.