sub2api icon indicating copy to clipboard operation
sub2api copied to clipboard

[Bug] Anthropic 账号测试固定发送 temperature 导致 claude-opus-4-8 返回 400

Open QLHazyCoder opened this issue 3 weeks ago • 1 comments

问题

POST /api/v1/admin/accounts/:id/test 测试 claude-opus-4-8 时,Sub2API 固定发送 temperature: 1,上游返回 HTTP 400:

{
  "error": {
    "type": "invalid_request_error",
    "message": "`temperature` is deprecated for this model."
  },
  "type": "error"
}

这会让账号测试把可用模型误判为不可用。

复现

  1. 创建一个 Anthropic API Key 账号,使其可访问 claude-opus-4-8。
  2. 调用账号测试:POST /api/v1/admin/accounts/{account_id}/test,并指定 model_id=claude-opus-4-8。
  3. 请求返回 HTTP 400,提示该模型已不再接受 temperature。

根因

当前 main(ee58c0013)的 backend/internal/service/account_test_service.go 中,createTestPayload() 对所有 Claude 测试请求无条件写入:

"temperature": 1,

部分新模型已不接受该采样参数。

期望行为

  • 账号测试请求应按模型能力构造;不支持采样参数的模型不发送 temperature。
  • 继续支持 temperature 的模型保持现有行为。
  • 增加 claude-opus-4-8 的请求 payload 回归测试,确保测试请求中不存在该字段。

QLHazyCoder avatar Nov 09 '26 12:11 QLHazyCoder

补充一个版本维度的诊断:当前账号测试确实固定携带 temperature: 1,但还需要区分最终出站的 anthropic-version。

在 main@ee58c0013c76ccd3f36439881bc848d342ec1c9d 上,通过 TestAccountConnection 入口捕获 HTTPUpstream 收到的最终请求(6 个本地合成子用例):

账号 / 配置 模型 最终 anthropic-version body
API Key,默认或显式旧版本 claude-opus-4-8 2023-06-01 temperature: 1
API Key,启用新版本 header 覆写 claude-opus-4-8 2026-10-21 temperature: 1
API Key,同样的新版本覆写 claude-haiku-4-5 2026-10-21 temperature: 1
API Key,覆写关闭 / OAuth 默认 claude-opus-4-8 2023-06-01 temperature: 1

其中新版本覆写的两例存在明确的请求契约冲突:参数 body 先构造,随后才执行 ApplyHeaderOverrides,最终组合为新版本 + 旧采样字段。当前构造和发送代码

Anthropic 版本说明明确 2026-10-21 对所有模型移除 temperature/top_p/top_k;参数参考还保留默认 temperature=1 的兼容接受说明。因此,仅凭模型名暂不能把所有旧版本请求都归为同一种拒绝原因。

已有 #8497 的账号测试改动会先解析生效版本,并在新版本下移除 temperature,与这里的新版本冲突直接相关,可以复用该方向。若实际出站仍是 2023-06-01 也收到上述错误,补充最终版本及上游是官方还是兼容端点,有助于确认是否还需要独立的兼容处理。

本地验证只证明请求形态;响应使用合成 SSE,未调用真实 Anthropic/兼容上游,也未验证真实账号可用性。

r266-tech avatar Nov 09 '26 15:11 r266-tech