Skip to content

新增账号支持使用 Chat Completions 协议上游#2255

Open
DASungta wants to merge 6 commits into
Wei-Shaw:mainfrom
DASungta:feat/apikey-chat-completions-bridge
Open

新增账号支持使用 Chat Completions 协议上游#2255
DASungta wants to merge 6 commits into
Wei-Shaw:mainfrom
DASungta:feat/apikey-chat-completions-bridge

Conversation

@DASungta
Copy link
Copy Markdown

@DASungta DASungta commented May 7, 2026

Summary

  • 新增 apikey-chat-completions 账号类型,将 Anthropic Messages / OpenAI Responses API 流量桥接到只支持 Chat Completions 协议的上游(如 b.ai 等)
  • 新增 strip_reasoning_effort_on_cc 账号字段,适配拒绝 reasoning_effort 参数的 Chat Completions 上游
  • 新增双向协议转换器 Responses↔ChatCompletionsapicompat 包),附完整单元测试链式覆盖
  • 前端创建/编辑账号弹窗同步新增相关字段开关

Changes

Backend

模块 变更内容
ent/schema/account type 字段扩至 40 字符;新增 strip_reasoning_effort_on_cc bool 字段
migrations/020 宽化 accounts.type
migrations/021 新增 strip_reasoning_effort_on_cc
internal/pkg/apicompat 新增 responses_to_chatcompletions_request.go + chatcompletions_to_responses_response.go 及对应测试
internal/service 新增 gateway_claude_chat_completions_raw.gogateway_forward_anthropic_as_cc.goopenai_gateway_responses_to_cc.go 及对应测试
internal/handler/openai_gateway_handler 新增 Responses→CC 路由分支
internal/handler/admin CRUD API 透传新字段

Frontend

  • CreateAccountModal.vue / EditAccountModal.vue:新增 strip_reasoning_effort_on_cc 开关
  • i18n/locales/en.ts / zh.ts:补充新字段国际化文案

Test plan

  • go test -tags=unit ./... 全部通过(TestResolvePageImagePath 为 macOS /private/var 预存失败,与本 PR 无关)
  • 新增 apicompat 链式转换测试:Responses→CC 请求转换、CC→Responses 响应转换
  • 新增 handler-level E2E 测试:anthropic_messages_apikey_ccopenai_chat_completions_apikey_ccopenai_responses_apikey_cc
  • go build ./... 编译通过
  • Ent 生成代码已提交(ent/ 目录)

🤖 Generated with Claude Code

DASungta and others added 2 commits May 7, 2026 18:09
…pletions bridge

Introduce a new account type `apikey-chat-completions` that allows
forwarding Anthropic/Responses API traffic to upstreams that only speak
the OpenAI Chat Completions protocol. Includes:

- ent schema: widen `type` column to 40 chars; add `strip_reasoning_effort_on_cc` field
- migrations 020/021 for the schema changes
- apicompat: bidirectional Responses↔ChatCompletions converters
  (`responses_to_chatcompletions_request`, `chatcompletions_to_responses_response`)
- fix: preserve tool messages with call_id in normalizeChatMessagesForToolCallPairs
- service: gateway routing for the new account type (Claude raw + Anthropic-as-CC + Responses-to-CC)
- handler/admin: surface strip_reasoning_effort_on_cc in account CRUD API
- frontend: add strip_reasoning_effort_on_cc toggle to CreateAccountModal & EditAccountModal

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 7, 2026

All contributors have signed the CLA. ✅
Posted by the CLA Assistant Lite bot.

@DASungta
Copy link
Copy Markdown
Author

DASungta commented May 7, 2026

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request May 7, 2026
@DASungta
Copy link
Copy Markdown
Author

DASungta commented May 7, 2026

1 4 3 2

@muzilong
Copy link
Copy Markdown

请求合并,很需要这个功能

@Week888
Copy link
Copy Markdown

Week888 commented May 13, 2026

这个功能很有用!支持合并

gclm added a commit to gclm/sub2api that referenced this pull request May 18, 2026
…protocol bridging

新增 apikey-chat-completions 账号类型,将 Anthropic Messages / OpenAI Responses
流量桥接到只支持 Chat Completions 协议的上游;新增 Responses↔ChatCompletions
双向转换器及前端字段支持。
@HD-L
Copy link
Copy Markdown

HD-L commented May 19, 2026

image 我看了下,机审有验不过去的地方,不然就通过了,求作者更新一下代码

@gclm
Copy link
Copy Markdown

gclm commented May 25, 2026

麻烦大佬更新一下

DASungta and others added 3 commits May 31, 2026 00:31
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Allow apikey-chat-completions accounts to select Authorization, api-key, or x-api-key authentication headers, and preserve exact Chat Completions test URLs.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Resolve PR Wei-Shaw#2255 conflicts with upstream's gateway refactor:

- openai_gateway_handler.go: keep WS chat-completions branch (ProxyResponsesWebSocketAsChatCompletions) and adopt upstream's pre-hooks requestPayloadHash computation.

- Adapt to parsed.Body now being *RequestBodyRef: use .Bytes() in ForwardAnthropicAsChatCompletions and NewRequestBodyRef() in apikey-chat-completions tests.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@DASungta
Copy link
Copy Markdown
Author

DASungta commented Jun 1, 2026

已经解决冲突并且更新到最新了。

作者估计没有合并的想法,可以直接用我的docker镜像进行部署:

docker pull zhangyc/sub2api:v0.1.133

版本号会和源项目保持一致。

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants