fix: enable Qwen3-Max prompt caching for hosted evals - #2404
Open
stu-cao wants to merge 1 commit into
Open
Conversation
Contributor
ApprovabilityVerdict: Not approved Macroscope's review found this PR not approvable — This PR enables new runtime behavior by automatically injecting prompt cache markers into API requests for Qwen3-Max on specific hosts. While the scope is narrow (one model, two hosts), this is a feature enablement with cost implications (1.25x cache-write premium) rather than a simple bug fix, warranting careful review of the caching logic and its integration points. You can add or adjust custom eligibility rules. Learn more. |
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.
Why this change is needed
Hosted Evals launches
prime eval run, whose default inference path builds a non-streaming Chat Completions request inOpenAIChatCompletionsClient. Alibaba'sqwen/qwen3-maxendpoint does not create an explicit prompt cache from provider pinning alone: the request must contain block-levelcache_control: {"type": "ephemeral"}breakpoints. See the OpenRouter Alibaba Qwen caching contract.The inference gateway already preserves caller-authored markers. It should not infer stable prompt boundaries for heterogeneous clients. This client is the narrowest layer where the resolved model, destination API, final structured messages, and ordered tool definitions coexist immediately before the request is sent.
What changes
For the exact
qwen/qwen3-maxmodel on the exactopenrouter.aiorapi.pinference.aihosts, the default Chat Completions client now adds explicit cache breakpoints to:The transformation is copy-on-write. It does not mutate the rollout prompt or tool definitions, and it never marks the changing user/assistant rollout tail. This limits Alibaba's 1.25x cache-write premium to content expected to be reused across examples, parallel rollouts, and tool turns.
The generated marker is exactly
{"type": "ephemeral"}. Nottlis sent because Alibaba supports a fixed five-minute cache, not Anthropic's optional one-hour retention.Caller intent always wins: if
cache_controlorprompt_cache_breakpointis already present at the request, message, direct content-block, or tool level, this client leaves the entire request unchanged. Tool parameter schemas containing a property namedcache_controlare not mistaken for cache directives.Scope and related changes
_pi_prompt_cacheroute metadata put prompt policy at the wrong layer.This PR intentionally covers the default Hosted Evals Chat Completions path. Explicit Responses, Anthropic Messages, renderer, native v1 proxy, and direct-SDK harness paths are separate request producers and are unchanged.
Validation
No paid inference APIs were called.
Rollout
After merge, publish a
verifiersrelease and ensure Hosted Evals resolves that release. The hosted runner currently installs an upgraded version satisfying the environment'sverifiersrequirement; exact older pins are intentionally preserved and will not receive this behavior. Post-deploy, verify two back-to-back requests with an identical marked static prefix and require the second response to report nonzero cached prompt tokens.Note
Cursor Bugbot is generating a summary for commit 93a9b8a. Configure here.
Note
Add automatic prompt cache markers for
qwen/qwen3-maxon hosted eval gatewaysqwen/qwen3-maxand the API base URL isopenrouter.aiorapi.pinference.ai,OpenAIChatCompletionsClient.get_native_responsenow auto-insertscache_control={'type': 'ephemeral'}on the last text segment of the final leading system/developer message and on the last function tool.cache_controlorprompt_cache_breakpointmarkers in the prompt, tools, orextra_body.qwen/qwen3-maxon the listed hosts will now include prompt cache markers by default unless the caller opts out by providing their own markers.Macroscope summarized 93a9b8a.