Skip to content

[upstream-port][backend+FE] AWS 渠道可选 Bedrock Mantle Messages 接口(原生 Claude、顶层 cache_control、API Key/SigV4)(new-api d0322047) #922

Closed as not planned

Description

@LIghtJUNction

上游来源

  • 仓库:QuantumNous/new-api
  • 提交:d0322047 — feat(aws): add Mantle Messages API support(Refs QuantumNous/new-api#4791)
  • 时间:2026-10-16 14:45 台北(committer)
  • 对比基线:ca2cae67 → d0322047(1 个提交)
  • 统计:+834/−3(后端 4 个文件,其中测试 +426;前端 channels 表单 + 7 个语言包)

做什么 / 为什么

AWS Bedrock 新增的 Mantle 端点(https://bedrock-mantle.<region>.api.aws/anthropic/v1/messages)直接接受原生 Anthropic Messages JSON / SSE,而不是 InvokeModel 的封装格式。上游把它做成 AWS 渠道的可选接口,默认仍走 InvokeModel:

  1. ChannelOtherSettings 新增 aws_api_type(invoke_model 默认 / mantle)。
  2. 新文件 relay/channel/aws/mantle.go:
    • 密钥格式 APIKey|Region(发 x-api-key)或 AccessKey|SecretAccessKey|Region(SigV4 签名,且会删掉无关的 Authorization/x-api-key)
    • 校验 region 字符集、自定义 base URL 必须是 https 且不带凭据/查询/fragment,自动补全 /anthropic/v1/messages
    • 模型名强制使用渠道解析后的 UpstreamModelName,claude-* 加 anthropic. 前缀,claude-haiku-4-5-20251001 映射为 claude-haiku-4-5;不套 InvokeModel 的版本后缀和跨区前缀;Nova 模型直接拒绝
    • 删除 body 中的 anthropic_version / anthropic_beta,改用 header;在 header override 之后剔除 hop-by-hop 头再签名,保证 SigV4 覆盖的头与实际发出的一致(HTTP/1.1 与 HTTP/2 均有测试)
  3. adaptor.go:GetRequestURL / DoRequest 按 AwsApiType 分支,未知值报错;DoResponse 对 Mantle 复用 Claude 原生响应处理,因此顶层 cache_control 与缓存用量可以正常透传和计费。
  4. 前端 channel-mutate-drawer.tsx / channel-form.ts 为类型 33(AWS)增加接口选择,非 AWS 渠道会清掉 aws_api_type;7 个语言包各 +4 条。

对 LMM 的意义:Bedrock 上的 Claude 走 InvokeModel 时缓存控制和新参数支持受限,Mantle 能让 Bedrock Claude 渠道的行为和计费接近直连 Anthropic;而且是 opt-in,不影响现有渠道。

LMM 现状(已核)

  • 冻结的 main@3948a0a1:apps/api-go/relaykit/dto/channel_settings.go 已有 AwsKeyType(ak_sk / api_key),但没有 AwsApiType;apps/api-go/relay/channel/aws/adaptor.go 里没有 ClientModeApiKey 分支(上游 Mantle 分支就插在这个分支前面),所以移植时需先确认 fork 的 API Key 模式是否完整,或只移植 Mantle 的 SigV4 路径。
  • 默认分支 wip/rust-core-go-extensions:代码搜索 bedrock / mantle 在非 web 代码中无命中,Rust core 目前没有 AWS 渠道;落地路径以届时 Go 网关树为准。
  • 已有 issue 中没有 Mantle 相关项([upstream-idea] Responses 响应 ID(previous_response_id / response_id)按租户绑定归属,防止共享上游 key 下跨用户续接(litellm) #914 只在 litellm 的 N/A 表里提到过 Bedrock Mantle)。

路径映射

上游路径 LMM 候选
relay/channel/aws/mantle.go(新) apps/api-go/relay/channel/aws/mantle.go
relay/channel/aws/adaptor.go apps/api-go/relay/channel/aws/adaptor.go
relay/channel/aws/relay_aws_test.go 同路径(fork 已有该测试文件,需合并)
relaykit/dto/channel_settings.go apps/api-go/relaykit/dto/channel_settings.go
web/src/features/channels/components/drawers/channel-mutate-drawer.tsx apps/web/src/features/channels/components/drawers/channel-mutate-drawer.tsx
web/src/features/channels/lib/channel-form.ts、types.ts、新测试 aws-channel.test.ts apps/web/src/features/channels/lib/…
web/src/i18n/locales/*.json apps/web/src/i18n/locales/*.json

风险 / 冲突

  • 计费:Mantle 走 Claude 原生 DoResponse,缓存读写 token 会按 Claude 规则计入;需确认与 fork 的 1 USD = 500000 credits 固定换算和钱包上下限一致,不能出现缓存用量漏计或重复计费。
  • 安全:SigV4 必须签最终发出的 payload 和 header(包括管理员 header override);不要把 Proxy-Authorization 等代理凭据发给 AWS。移植时保留上游这部分逻辑和测试。
  • 依赖:需要 aws-sdk-go-v2/aws/signer/v4;fork 现有 AWS 适配器已用 aws-sdk-go-v2,核对版本即可。
  • 与支付、订阅、assistant、HeroSMS、悬赏契约、Redis-off 运行时、task/JS plugin host 决定无直接冲突。
  • 前端部分必须由 Opus 5.5(claude-opus-5-5)云端 agent 完成,并保持 LMM 品牌和 DESIGN.md;当前 Cursor 云端 agent 额度已用完,本轮只建 issue。

测试建议

  • cd apps/api-go && go test ./relay/channel/aws/...(移植上游的 Mantle URL、SigV4 over HTTP/1.1/HTTP/2、cache 用量、旧渠道仍走 InvokeModel、非法 aws_api_type 报错等用例)
  • cd apps/web && bun test(或仓库约定的命令)跑 channel-configuration.test.tsx 和 aws-channel.test.ts
  • 手工:AWS 渠道切到 Mantle,分别用 APIKey|Region 与 AK|SK|Region 发一次流式和非流式请求,确认缓存用量和扣费;未配置 aws_api_type 的老渠道行为不变

工作量

中:后端约 3–4 小时(含测试与 API Key 模式核对);前端约 1–2 小时(Opus 5.5)。

Activity

  1. added
    botOpened by the maintenance bot
    upstream-portQuantumNous/new-api upstream commit port candidate
    on Oct 16, 2026
  2. LIghtJUNction commented on Nov 14, 2026

    @LIghtJUNction
    MemberAuthor

    本 Issue 已合并到 #987 统一跟踪:#987

    本次关闭仅用于合并去重,不代表问题已修复、已验收或放弃处理。原始正文和讨论仍保留在这里,后续实现与验收请使用新 Issue。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    botOpened by the maintenance botupstream-portQuantumNous/new-api upstream commit port candidate

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions