Skip to content

OpenRouter route never sets cache_control for Anthropic models #39009

Closed

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

  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" } } }
}}}

Activity

  1. github-actions commented on Jul 26, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. opencode-agent commented on Aug 1, 2026

    @opencode-agent
    Contributor

    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.

  3. rekram1-node commented on Sep 29, 2026

    @rekram1-node
    Collaborator

    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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions