Description
Anthropic models routed through OpenRouter never get prompt caching on the V2 native route. cache_control is never set on the request, so every turn is billed at full input price.
applyCachePolicy (packages/llm/src/cache-policy.ts) only runs for routes in RESPECTS_INLINE_HINTS — anthropic-messages and bedrock-converse. The OpenRouter route isn't in that set, so the whole cache pass is skipped. That's correct for OpenAI-style implicit caching, but OpenRouter proxying to Anthropic needs an explicit breakpoint.
The same model through the anthropic provider caches normally, so it's specific to the OpenRouter route.
OpenCode version
opencode2 v0.0.0-next-16234
Steps to reproduce
opencode2 run -m "openrouter/anthropic/claude-opus-4.8" "hi"
- Look at the assistant message's tokens
cache.read and cache.write are both 0, and stay at 0 however long the session runs.
Real numbers from one session before I noticed: 181 requests, 29.2M input tokens, none cached, $149. At cache-read rates that's roughly $23.
Workaround until this is fixed — set the top-level field yourself:
"provider": { "openrouter": { "models": {
"anthropic/claude-opus-4.8": { "options": { "cache_control": { "type": "ephemeral" } } }
}}}
Description
Anthropic models routed through OpenRouter never get prompt caching on the V2 native route.
cache_controlis never set on the request, so every turn is billed at full input price.applyCachePolicy(packages/llm/src/cache-policy.ts) only runs for routes inRESPECTS_INLINE_HINTS—anthropic-messagesandbedrock-converse. The OpenRouter route isn't in that set, so the whole cache pass is skipped. That's correct for OpenAI-style implicit caching, but OpenRouter proxying to Anthropic needs an explicit breakpoint.The same model through the
anthropicprovider caches normally, so it's specific to the OpenRouter route.OpenCode version
opencode2 v0.0.0-next-16234
Steps to reproduce
opencode2 run -m "openrouter/anthropic/claude-opus-4.8" "hi"cache.readandcache.writeare both0, and stay at0however long the session runs.Real numbers from one session before I noticed: 181 requests, 29.2M input tokens, none cached, $149. At cache-read rates that's roughly $23.
Workaround until this is fixed — set the top-level field yourself: