feat: native passthrough for OpenAI upstreams supporting both Responses and Chat Completions#3333
Open
StarryKira wants to merge 2 commits into
Open
Conversation
…eam supports both Responses and Chat Completions
Previously OpenAI APIKey routing was governed by a single bool
(ShouldUseResponsesAPI) consumed at two dispatch sites with opposite
meaning. This forced ALL of an account's traffic onto one endpoint and
applied a lossy cross-conversion to the non-matching inbound type, even
when the upstream supports both endpoints.
Replace the bool with a 3-way resolver ResolveOpenAITextRoute ->
{RouteResponses, RouteChatCompletions, RouteNative}. RouteNative passes
each inbound type to its matching upstream endpoint with no conversion:
Responses-in -> /v1/responses, Chat Completions-in -> /v1/chat/completions.
RouteNative is reached two ways:
- smart auto: an account probed as supporting Responses (auto +
openai_responses_supported=true) now uses native passthrough instead
of up-converting Chat Completions to Responses
- explicit: a new account-level "native" mode (openai_responses_mode)
force_responses / force_chat_completions, auto+unsupported (CC-only),
auto+unprobed (legacy Responses) and OAuth accounts are unchanged.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Add a "native" choice to the OpenAI APIKey Responses mode selector in the create/edit account modals, so an admin can force native passthrough (Responses-in -> /v1/responses, Chat Completions-in -> /v1/chat/completions) when an upstream supports both endpoints. Includes the OpenAIResponsesMode type, capability/status labels, en/zh i18n copy, and a component test. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
Author
这个runner怎么奇奇怪怪的 网络错误无法lint |
Contributor
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题 / Problem
当 OpenAI APIKey 账号的上游(
base_url)同时支持/v1/responses和/v1/chat/completions时,网关此前会把账号的全部流量塞进单一端点,并对不匹配的入站类型做一次有损的跨协议转换:ShouldUseResponsesAPI决定,在两个分流点以相反含义消费supported=true / 未探测→ 全部走/v1/responses(Chat Completions 入站被上转)supported=false→ 全部走/v1/chat/completions(Responses 入站被下转)即便上游双支持,也只能"二选一",无谓地损失原生端点语义。
方案 / Solution
用三态路由解析器
ResolveOpenAITextRoute(extra) → {RouteResponses, RouteChatCompletions, RouteNative}替换单布尔。RouteNative按入站类型原生透传,零跨协议转换:/v1/responses/v1/chat/completions复用已有的原生直转分支(
forwardAsRawChatCompletions/ 原生 Responses 直转),无需新增转换代码。RouteNative两种触发方式:auto+ 探测确认支持 Responses(openai_responses_supported=true)→ 自动原生透传(不再上转 CC)native模式(openai_responses_mode),前端账号创建/编辑弹窗可选路由映射
native(新增)force_responsesforce_chat_completionsauto/ 缺失auto/ 缺失auto/ 缺失OAuth 账号、
force_*、auto+未探测、auto+不支持(如火山方舟工具坏掉)行为均不变。行为变化 / Behavior change
唯一变化:现有
auto + supported=true的 APIKey 账号,Chat Completions 入站从"上转 Responses 打/v1/responses"改为"原生直转/v1/chat/completions"。对真正双支持的上游更忠实、无损。若个别上游仅暴露/v1/responses,可用force_responses兜底。验证 / Verification
go test -tags=unit ./internal/pkg/openai_compat/... ./internal/service/... ./internal/handler/...全绿;golangci-lint run0 issuesTestResolveOpenAITextRoute全组合表 + dispatcher 级TestForwardAsChatCompletions_NativeAndAutoSupportedRouteRawChatCompletionspnpm typecheck/pnpm lint:check通过;EditAccountModal.spec.ts新增 native 用例,18/18 通过🤖 Generated with Claude Code