Skip to content

feat: add support for AWS Bedrock provider#2826

Closed
zilianpn wants to merge 2 commits into
router-for-me:devfrom
zilianpn:feature/bedrock-reasoning
Closed

feat: add support for AWS Bedrock provider#2826
zilianpn wants to merge 2 commits into
router-for-me:devfrom
zilianpn:feature/bedrock-reasoning

Conversation

@zilianpn
Copy link
Copy Markdown
Contributor

概述

为 AWS Bedrock provider 添加完整支持,通过 Bedrock Converse API 实现 Claude Messages API 和 OpenAI Chat Completions 两套协议的调用链路。

变更详情

🏗️ Bedrock Executor

  • 新增 BedrockExecutor,对接 AWS Bedrock Converse API(/model/{modelId}/converse/model/{modelId}/converse-stream
  • 支持非流式(converse)和流式(converse-stream)两种调用模式
  • 支持 Bedrock → Claude messages 端点的 token counting

🔄 Claude ↔ Bedrock 转译

  • 新增 Claude Messages API → Bedrock Converse 请求转译(anthropic 格式 → converse 格式)
  • 新增 Bedrock Converse → Claude Messages API 响应转译,包括 reasoning 内容的解析(兼容 reasoningContent / reasoning 多种嵌套路径)
  • 处理 assistant 消息中 toolUse 块的重排序,确保连续 toolUse 块满足 Bedrock Converse 的格式要求

🔄 OpenAI ↔ Bedrock 转译

  • 新增 OpenAI Chat Completions → Bedrock Converse 请求转译(chat/completions 格式 → converse 格式)
  • 新增 OpenAI Responses → Bedrock 的级联转译(Responses → Chat Completions → Bedrock)
  • 新增 Bedrock Converse → OpenAI Chat Completions 响应转译
  • 支持 thinking 模式下的 reasoning 内容提取,兼容多种 Bedrock 返回格式(reasoningContent.reasoningText.text / reasoningContent.reasoning / reasoning.text / type: thinking 等)

⚙️ 配置与路由

  • 新增 aws-bedrock-api-key 配置段:支持 API Key + Region 认证,模型通过 Name / ID(推理配置 ARN)/ Alias 三级映射
  • 模型支持 prefix 命名空间隔离和 proxy-url 独立代理设置
  • SDK auth conductor 集成 Bedrock 模型别名解析,支持多凭证按 priority 选择

🧪 模型注册与热更新

  • 模型注册表新增 Bedrock 模型定义
  • Config watcher 新增 Bedrock provider 差异比对与热更新支持

📝 配置示例

aws-bedrock-api-key:
  - api-key: "your-bedrock-api-key"
    region: "us-west-2"
    prefix: "test"
    proxy-url: "socks5://proxy.example.com:1080"
    models:
      - name: "anthropic.claude-sonnet-4-20250514-v1:0"
        id: "arn:aws:bedrock:us-west-2:123456789012:application-inference-profile/abcd1234"
        alias: "bedrock-sonnet"
    excluded-models:
      - "amazon.titan-*"

测试截图

代码已投入线上环境运行

image image

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for AWS Bedrock as a new provider, including configuration management, request/response translation, and executor implementation. The review identified several areas for improvement: code duplication between the auth and service packages regarding configuration resolution, inefficient slice element modification in the patch handler, redundant logic across executor methods, and inconsistency in model hash calculations between the diff summary and the synthesizer. I have kept these comments as they highlight actionable technical debt and potential bugs.

Comment thread sdk/cliproxy/service.go
Comment thread internal/api/handlers/management/config_lists.go Outdated
Comment thread internal/runtime/executor/bedrock_executor.go Outdated
Comment thread internal/watcher/diff/models_summary.go Outdated
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 66a0cfacf9

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/runtime/executor/bedrock_executor.go Outdated
Comment thread internal/translator/claude/bedrock/claude_bedrock_request.go
@zilianpn zilianpn force-pushed the feature/bedrock-reasoning branch from 66a0cfa to 1733bfe Compare April 16, 2026 06:55
Copy link
Copy Markdown
Collaborator

@luispater luispater left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary

Adds first-class AWS Bedrock support (Converse + Converse-stream) across config → auth synthesis → executor → translators (Claude + OpenAI + OpenAI Responses) → model registry/watchers, including model aliasing (Name/ID/ARN) and token counting.

Key findings (non-blocking)

  • config.example.yaml: the commented sensitive-words list items look mis-indented (may become invalid YAML when uncommented).
  • Usage accounting: please confirm whether Bedrock cacheWriteInputTokens is additive vs a subset of inputTokens; current mapping adds it to ReasoningTokens, affecting totals.
  • OpenAI streaming ordering: if metadata arrives before messageStop, the usage chunk can be emitted before the terminal finish_reason / [DONE]; consider buffering usage until completion for better OpenAI compatibility.
  • Tool results: consider also accepting tool_call_id for tool_result parts (in addition to tool_use_id) for Responses-style payloads.

Checks / CI

  • pr-test-build succeeded.
  • translator-path-guard failed (ignored per review instructions).

Test plan

  • I did not run anything locally (no checkout). Suggested:
    • go test ./...
    • Exercise non-stream + stream flows for: Chat Completions, Responses, and Claude Messages against a real Bedrock endpoint and an inference profile ARN.

This is an automated Codex review result and still requires manual verification by a human reviewer.

@zilianpn zilianpn force-pushed the feature/bedrock-reasoning branch from 1733bfe to 2192d26 Compare April 22, 2026 16:00
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2192d26ca6

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/api/handlers/management/config_lists.go Outdated
Comment thread internal/runtime/executor/bedrock_executor.go Outdated
@zilianpn zilianpn force-pushed the feature/bedrock-reasoning branch from 2192d26 to bb9eab6 Compare April 22, 2026 16:25
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: bb9eab6a58

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/api/handlers/management/config_lists.go Outdated
Comment thread internal/runtime/executor/bedrock_executor.go Outdated
@zilianpn zilianpn force-pushed the feature/bedrock-reasoning branch 2 times, most recently from 536be61 to 1376e1b Compare April 22, 2026 16:55
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 1376e1b9e4

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/api/handlers/management/config_auth_index.go Outdated
@zilianpn zilianpn force-pushed the feature/bedrock-reasoning branch from 1376e1b to 3e9372f Compare April 22, 2026 17:06
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 3e9372fef8

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/runtime/executor/bedrock_executor.go
Comment thread internal/translator/openai/bedrock/openai_bedrock_request.go
Comment thread internal/translator/openai/bedrock/openai_bedrock_request.go
- Add AWS Bedrock executor with Converse API support (/converse, /converse-stream)
- Add Claude Messages API to Bedrock Converse request/response translation
- Add OpenAI Chat Completions to Bedrock Converse translation support
- Add Bedrock model registry, capability resolution, and alias configuration
- Add Bedrock region endpoint derivation from region config
- Extract shared request preparation into prepareBedrockRequest helper (Execute/ExecuteStream/CountTokens)
- Fix PatchAWSBedrockKey value copy by using pointer reference
- Fix model alias hash to include model.ID for change detection
- Preserve non-text/non-toolUse blocks in Bedrock assistant message reordering
@zilianpn zilianpn force-pushed the feature/bedrock-reasoning branch from 3e9372f to ff7d63f Compare April 22, 2026 17:31
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: ff7d63fa17

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread internal/translator/openai/bedrock/openai_bedrock_request.go
@zilianpn
Copy link
Copy Markdown
Contributor Author

@luispater 该特性我们已在生产环境应用了10 多天,未发现其他问题,帮忙评估一下是否可以接受这个特性。

…est URL

Bedrock config model.ID (ARN) was not being used to construct the upstream
request URL. The executor always used model.Name, causing 400 errors when
invoking inference profiles. Now RouteTarget (ARN) takes precedence over Name.
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a879a8e82d

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread sdk/cliproxy/auth/conductor.go
@zilianpn zilianpn closed this Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants