Skip to content

fix(ai): select OpenRouter auto cache markers by model - #52119

Closed
opencode-agent[bot] wants to merge 1 commit into
v2from
openrouter-model-cache
Closed

opencode-agent[bot] wants to merge 1 commit into
v2from
openrouter-model-cache

Conversation

@opencode-agent

@opencode-agent opencode-agent Bot commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

  • auto is selected by the OpenRouter route using model prefixes: anthropic/ places tool/system/tail breakpoints; qwen/ places system/tail content breakpoints (Alibaba ignores tool-definition markers); all other prefixes add none and retain implicit caching.
  • The shared cache-policy pass just places the selected hints. Explicit cache policies and per-part hints always bypass the route default; prompt_cache_key still flows normally.
  • One focused wire-body test table covers the model families, and one test verifies explicit overrides.

Why

Live OpenRouter streamed usage showed multi-turn Qwen Plus saving ~36% with explicit markers and a stable prompt_cache_key; the previous auto tail marker made Gemini 2.5 Flash cost more than its unmarked implicit caching. A Qwen snapshot that does not support explicit caching accepted the markers and reported the same billed cost as the unmarked request in a compatibility probe. This replaces the blanket OpenRouter enablement in #52110; the two PRs overlap and should not be merged independently.

Verification

  • bun test test/provider/openrouter.test.ts test/cache-policy.test.ts in packages/ai: 47 pass.
  • bun typecheck in packages/ai: pass.
  • Prettier and diff whitespace check: pass.
  • Full bun run check: lint passes; monorepo typecheck stops in unrelated @opencode/posts because this host's Node 18.19.1 is below Astro's required >=22.12.0.

Requested by: @rekram1-node (Aiden via Slack)

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant