[BUG] AWS Claude /v1/messages 流式响应会覆盖模型重定向后的 upstream_model_name
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 65/100
Research direction
Start with relay/channel/claude/relay-claude.go and inspect the message_start handling, then trace RelayInfo through relay/helper/model_mapped.go and relay/channel/aws/relay-aws.go. Check service/log_info_generate.go to confirm that a mapped upstream model remains available after streaming, without changing the non-streaming behavior.
Written by the indexing model from the issue text.
Description
提交前必读(请勿删除本节)
- 文档:https://docs.newapi.ai/
- 使用问题先看或先问:https://deepwiki.com/QuantumNous/new-api
- 警告:删除本模板、删除小节标题或随意清空内容的 issue,可能会被直接关闭;重复恶意提交者可能会被 block。
您当前的 newapi 版本
9f8a4ec,提交时间:2026-04-28 11:29:30 +0800
提交确认
- 我已确认目前没有类似 issue
- 我已完整查看过文档 https://docs.newapi.ai/ 和项目 README,尤其是常见问题部分
- 我未删除此模板中的任何引导内容或小节标题,并会按要求完整填写
- 我理解项目维护者精力有限,不遵循模板要求的 issue 可能会被无视或直接关闭
问题描述
在 /v1/messages 使用 AWS Claude 渠道,并开启模型重定向/模型映射时,非流式请求可以正确显示重定向后的上游模型;但流式请求看起来会出现“模型重定向失效”。
已确认:
- 未开启任何透传配置。
- 渠道类型是 AWS Claude。
- 请求入口是
/v1/messages。 stream=true时复现。stream=false时正常。- 渠道亲和性开启或关闭都不影响该问题。
预期行为
当模型映射生效后,RelayInfo.UpstreamModelName 应始终表示实际请求上游使用的模型名/模型 ID。流式响应解析不应把它改回响应里的 message.model,否则日志、usage fallback、计费相关的 other.upstream_model_name 会表现为模型重定向失效。
实际行为
AWS Claude 流式请求阶段实际已经使用了映射后的模型:
/v1/messages会进入 Claude relay:router/relay-router.go
- 请求阶段会执行模型映射:
relay/claude_handler.go
ModelMappedHelper会把映射后的模型写入info.UpstreamModelName,并回写 request model:relay/helper/model_mapped.go
- AWS SDK 流式请求使用的是
getAwsModelID(info.UpstreamModelName),并传给InvokeModelWithResponseStreamInput.ModelId:relay/channel/aws/relay-aws.go
但是在 Claude 流式响应处理时,message_start 又覆盖了 info.UpstreamModelName:
if claudeResponse.Type == "message_start" {
// message_start, 获取usage
if claudeResponse.Message != nil {
info.UpstreamModelName = claudeResponse.Message.Model
}
}
位置:
relay/channel/claude/relay-claude.go
这会导致流式请求后续日志里的 upstream_model_name 变成响应中的 message.model,而不是实际请求 AWS Bedrock 使用的重定向后模型。
日志记录位置:
service/log_info_generate.go
if relayInfo.IsModelMapped {
other["is_model_mapped"] = true
other["upstream_model_name"] = relayInfo.UpstreamModelName
}
影响
/v1/messages+ AWS Claude +stream=true时,usage log / 请求日志中显示的upstream_model_name可能错误。- 从日志看会像模型重定向失效,但实际 AWS
InvokeModelWithResponseStreamInput.ModelId在请求创建时已经使用映射后的模型。 - 后续依赖
info.UpstreamModelName的 usage fallback 或计费逻辑也可能拿到被覆盖后的模型名。
初步判断
这是流式响应解析阶段对 RelayInfo.UpstreamModelName 的误修改。UpstreamModelName 更适合作为“实际请求上游使用的模型”保留,不应被响应中的 message.model 覆盖。
建议修复
可以考虑移除该赋值,或者至少在模型映射已生效时不要覆盖:
if claudeResponse.Type == "message_start" && claudeResponse.Message != nil && !info.IsModelMapped {
info.UpstreamModelName = claudeResponse.Message.Model
}
更干净的方式是:响应里的模型名只记录到 claudeInfo.Model 或新增独立字段,不复用/覆盖 RelayInfo.UpstreamModelName。
复现步骤
- 配置一个 AWS Claude 渠道。
- 配置模型重定向/模型映射,例如将客户端请求模型 A 映射到上游模型 B。
- 使用
/v1/messages发起 Claude Messages 请求。 - 对比:
stream=false:日志中的上游模型显示正常。stream=true:日志中的上游模型可能被message_start.message.model覆盖,看起来像重定向失效。
- Dominant language
- Go
- Stars
- 48.5k
- Forks
- 11.6k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 61
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from QuantumNous/new-api
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
QuantumNous/new-api#7511 · 1 comment ·
-
fix(relay): terminal stream chunk with finish_reason is dropped when client does not request usage Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
QuantumNous/new-api#7489 · 1 comment ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
QuantumNous/new-api#7479 · 1 comment ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
QuantumNous/new-api#7467 · 1 comment ·
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
QuantumNous/new-api#7417 · 1 comment ·
All issues in QuantumNous/new-api
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
enhancement needs triage
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
kind/cleanup
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
kubernetes-sigs/kueue#15947 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
sympozium-ai/sympozium#627 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100