Skip to content

OpenRouter route never sets cache_control for Anthropic models #39009

Description

@sergical

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_HINTSanthropic-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

  1. opencode2 run -m "openrouter/anthropic/claude-opus-4.8" "hi"
  2. 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" } } }
}}}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions