Repository navigation
fix(gateway): drop sampling params rejected by Claude 4.7+ upstreams - #517
Merged
Merged
Conversation
Claude 4.7 and later return 400 for temperature/top_p/top_k on both the Messages API and Anthropic's OpenAI-compatible endpoint, while OpenAI-style clients send temperature routinely. Aggregate transport now removes those fields once the routed upstream model is Claude 4.7+; older Claude and non-Claude request bodies are left byte-for-byte unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
变更摘要
temperature、top_p、top_k。/v1/chat/completions都一样(temperature小于 1 即报错)。OpenAI 风格客户端几乎都会带temperature,所以把这些模型配成聚合上游后,带参数的请求全部失败。compatible、codex、claude类型的聚合 API 都适用。复现方式
compatible类型的聚合 API,地址填https://api.anthropic.com/v1,使用 Anthropic API Key。claude-haiku-5-5(换成claude-sonnet-5-5或claude-opus-5-5结果相同)。{ "model": "<platform-model>", "temperature": 0.2, "max_completion_tokens": 200, "messages": [{"role": "user", "content": "hello"}] }修复前:上游返回 400,报错
invalid_request_error: `temperature` is deprecated for this model,网关向客户端返回 502。同样的请求去掉temperature后返回 200。修复后:带
temperature0.2 的非流式请求和带temperature0.7 的流式工具调用请求都返回 200,tool_calls正常。上游分别为claude-haiku-5-5、claude-sonnet-5-5,均为真实调用验证。路由到claude-opus-4-6时保留temperature,该模型仍接受这个参数。改动范围
主要文件
crates/service/src/gateway/upstream/protocol/claude_sampling.rs(新增):识别 Claude 4.7+ 模型名,兼容anthropic.和anthropic/前缀以及带日期的快照后缀,并去掉不受支持的采样参数;包含单元测试。crates/service/src/gateway/upstream/protocol/aggregate_api.rs:在rewrite_body_for_candidate_transport完成模型覆盖后调用上述函数;新增候选转发回归测试。crates/service/src/gateway/upstream/protocol/mod.rs:注册模块。验证
pnpm -C apps run testpnpm -C apps run buildpnpm -C apps run test:uicargo test --workspace已执行的实际验证:
未执行的验证与原因:
风险与影响面
tool_choice为required或指定函数时返回 400),会改变请求语义,本 PR 不处理。claude类型 Responses→Messages 桥接里的thinking.budget_tokens在 Claude 4.7+ 上同样会被拒绝,也可以另开 PR 处理。备注
🤖 Generated with Claude Code