You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OpenRouter route never sets cache_control for Anthropic models #39009
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:
Addressed by #39907. Native OpenRouter lowering now supports explicit cache policies and manual hints, emitting OpenRouter cache_control markers across tools, system/user content, assistant messages, and tool results. It also supplies a stable session prompt_cache_key for default OpenRouter caching and preserves explicit provider settings. Focused AI/Core cache, OpenRouter, provider-package, resolver, and generation tests passed. Closing as resolved on the v2 branch.
Follow-up: the earlier fix supported explicit cache policies but still skipped default/auto breakpoint placement, as reported in #51726.
That remaining default-caching bug is fixed by #52110, now merged into v2. OpenRouter Anthropic requests emit explicit breakpoints automatically, including latest-model aliases, and assistant/tool-result markers use text content parts. A manual cache_control model override is no longer necessary for the default OpenRouter path in builds containing this fix.
Activity
github-actions commentedon Jul 26, 2026
This issue might be a duplicate of existing issues. Please check:
cache_controlon Anthropic-model requests, with the same fix (cache_control: { type: "ephemeral" }on message content). It also references a linked PR (fix(opencode): set 1h prompt cache TTL for OpenRouter #16850) with an implementation.fix(provider): scope OpenRouter session_id to Anthropic and honor set…
opencode-agent commentedon Aug 1, 2026
Addressed by #39907. Native OpenRouter lowering now supports explicit cache policies and manual hints, emitting OpenRouter
cache_controlmarkers across tools, system/user content, assistant messages, and tool results. It also supplies a stable sessionprompt_cache_keyfor default OpenRouter caching and preserves explicit provider settings. Focused AI/Core cache, OpenRouter, provider-package, resolver, and generation tests passed. Closing as resolved on the v2 branch.rekram1-node commentedon Sep 29, 2026
Follow-up: the earlier fix supported explicit cache policies but still skipped default/auto breakpoint placement, as reported in #51726.
That remaining default-caching bug is fixed by #52110, now merged into
v2. OpenRouter Anthropic requests emit explicit breakpoints automatically, including latest-model aliases, and assistant/tool-result markers use text content parts. A manualcache_controlmodel override is no longer necessary for the default OpenRouter path in builds containing this fix.