Repository navigation
fix(ai): place prompt cache breakpoints on OpenRouter Anthropic and Qwen requests - #52110
Merged
Merged
Conversation
rekram1-node
force-pushed
the
openrouter-cache
branch
from
September 29, 2026 18:14
17634dd to
45c6de6
Compare
rekram1-node
force-pushed
the
openrouter-cache
branch
2 times, most recently
from
September 29, 2026 20:35
006684b to
011f324
Compare
rekram1-node
force-pushed
the
openrouter-cache
branch
from
September 29, 2026 22:16
8647c95 to
79936a1
Compare
This was referenced Sep 29, 2026
This was referenced Sep 30, 2026
2 of 6 tasks
Ichinose-Kazuki
pushed a commit
to Ichinose-Kazuki/opencode
that referenced
this pull request
Oct 7, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue for this PR
No linked issue.
Type of change
What does this PR do?
applyCachePolicyskipped OpenRouter whenever the request used the default cache policy, so OpenRouter requests only gotcache_controlmarkers when a caller set an explicit policy. Core never does, so no OpenRouter session sent breakpoints.This enables explicit caching for Anthropic and Alibaba Qwen through OpenRouter (prompt caching docs), instead of leaving Claude uncached and relying on Qwen's less predictable implicit caching.
The default policy on OpenRouter is now chosen by model:
anthropic/*and OpenRouter's~anthropic/*latest-model aliases: the usual breakpoints (last tool, first and last system parts, conversation tail).qwen/*(including leading-~aliases): system boundaries and conversation tail, without a model allowlist. Alibaba ignores breakpoints on tool definitions and caches tools as part of the system prompt (context cache docs).Explicit cache policies and manually placed cache hints still apply to every OpenRouter model, as before.
Shared Chat lowering now puts assistant and tool-result breakpoints on text content parts (
content: [{ type: "text", text, cache_control }]), rather than on the message itself. Alibaba ignores message-level markers. Unmarked assistant text remains a string, and reasoning-only assistants do not acquire fabricated text markers. A wrapped system update consumes its breakpoint budget once rather than twice.Only OpenRouter currently enables cache controls in the shared Chat lowering, so other providers' requests and native Anthropic Messages are unchanged. The existing four-breakpoint limit and per-part TTLs remain supported.
How did you verify your code works?
packages/aitest suite, focused Core request/transport/provider tests, and rootbun run checkpass.usage.cost. Claude Sonnet 4.6 billed about $0.0045 per subsequent step versus $0.037 onv2in the tested session.v2versus $0.0158 with the fix; qwen3.7-plus billed $0.0097 versus $0.0081.Screenshots / recordings
Not applicable.
Checklist