Skip to content

fix: 修正 chat-only API-key 账号上游端点被误记为 /v1/responses#3335

Merged
Wei-Shaw merged 1 commit into
Wei-Shaw:mainfrom
FjlI5:fix/openai-upstream-endpoint-logging
Jun 21, 2026
Merged

fix: 修正 chat-only API-key 账号上游端点被误记为 /v1/responses#3335
Wei-Shaw merged 1 commit into
Wei-Shaw:mainfrom
FjlI5:fix/openai-upstream-endpoint-logging

Conversation

@FjlI5

@FjlI5 FjlI5 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

问题

DeriveUpstreamEndpoint 对所有 OpenAI 平台请求一律推导为 /v1/responses,但 API-key 账号若上游只支持 Chat Completions(!ShouldUseResponsesAPI),实际是直接转发到 /v1/chat/completions。messages / responses / cyber_policy 三类记录点都用裸的 GetUpstreamEndpoint 推导端点,导致这些请求在用量/ops 记录里被误标成 /v1/responses

修复

把已有的 resolveRawCCUpstreamEndpoint(原本只用于 chat completions 客户端路径)泛化为 resolveOpenAIUpstreamEndpoint,并在所有 OpenAI 记录点改用它——与早已修正的 chat completions 客户端路径保持一致。GetUpstreamEndpoint 作为非 OpenAI 平台及该 resolver 的回退保留不变。

影响

  • 仅改变端点的记录值,不改变任何转发行为。
  • 非 OpenAI 平台(Anthropic/Gemini 等)行为不变。

修复前:
image
修复后:
image

测试

go build ./internal/handler/ ./internal/service/ 通过;go test ./internal/handler/ 全量通过。

… API-key accounts

DeriveUpstreamEndpoint maps every OpenAI-platform request to /v1/responses, but
API-key accounts whose upstream only speaks Chat Completions
(!ShouldUseResponsesAPI) are forwarded directly to /v1/chat/completions. The
messages, responses and cyber-policy recording sites derived the endpoint via the
bare GetUpstreamEndpoint, so usage/ops records mislabeled those requests as
/v1/responses. Generalize the existing resolveRawCCUpstreamEndpoint into
resolveOpenAIUpstreamEndpoint and use it at every OpenAI recording site, matching
the already-correct chat-completions client path.
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

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

@FjlI5 FjlI5 force-pushed the fix/openai-upstream-endpoint-logging branch from 27e7793 to bab8a9a Compare June 17, 2026 17:51
@FjlI5

FjlI5 commented Jun 17, 2026

Copy link
Copy Markdown
Contributor Author

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

github-actions Bot added a commit that referenced this pull request Jun 17, 2026
@Wei-Shaw Wei-Shaw merged commit f597e92 into Wei-Shaw:main Jun 21, 2026
8 of 9 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Jun 21, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants