Skip to content

Commit f597e92

Browse files
authored
Merge pull request #3335 from FjlI5/fix/openai-upstream-endpoint-logging
fix: 修正 chat-only API-key 账号上游端点被误记为 /v1/responses
2 parents 7b5fbe5 + bab8a9a commit f597e92

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

backend/internal/handler/openai_chat_completions.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ func (h *OpenAIGatewayHandler) ChatCompletions(c *gin.Context) {
289289
userAgent := c.GetHeader("User-Agent")
290290
clientIP := ip.GetClientIP(c)
291291
inboundEndpoint := GetInboundEndpoint(c)
292-
upstreamEndpoint := resolveRawCCUpstreamEndpoint(c, account)
292+
upstreamEndpoint := resolveOpenAIUpstreamEndpoint(c, account)
293293

294294
cyberBlocked := service.GetOpsCyberPolicy(c) != nil
295295
h.submitOpenAIUsageRecordTask(c.Request.Context(), result, func(ctx context.Context) {
@@ -325,12 +325,12 @@ func (h *OpenAIGatewayHandler) ChatCompletions(c *gin.Context) {
325325
}
326326
}
327327

328-
// resolveRawCCUpstreamEndpoint returns the actual upstream endpoint for
329-
// OpenAI Chat Completions requests. For APIKey accounts whose upstream
330-
// is forced or probed to not support the Responses API, the request is
331-
// forwarded directly to /v1/chat/completions — not through the default
332-
// CC→Responses conversion path.
333-
func resolveRawCCUpstreamEndpoint(c *gin.Context, account *service.Account) string {
328+
// resolveOpenAIUpstreamEndpoint returns the actual upstream endpoint for an
329+
// OpenAI account, used by every OpenAI usage-recording site. APIKey accounts
330+
// whose upstream is forced or probed to not support the Responses API are
331+
// served directly via /v1/chat/completions (the raw chat path) regardless of
332+
// the inbound endpoint; everything else goes through the Responses API.
333+
func resolveOpenAIUpstreamEndpoint(c *gin.Context, account *service.Account) string {
334334
if account != nil && account.Type == service.AccountTypeAPIKey &&
335335
!openai_compat.ShouldUseResponsesAPI(account.Extra) {
336336
return "/v1/chat/completions"

backend/internal/handler/openai_gateway_handler.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ func (h *OpenAIGatewayHandler) Responses(c *gin.Context) {
496496
clientIP := ip.GetClientIP(c)
497497
requestPayloadHash := service.HashUsageRequestPayload(body)
498498
inboundEndpoint := GetInboundEndpoint(c)
499-
upstreamEndpoint := GetUpstreamEndpoint(c, account.Platform)
499+
upstreamEndpoint := resolveOpenAIUpstreamEndpoint(c, account)
500500

501501
// 使用量记录通过有界 worker 池提交,避免请求热路径创建无界 goroutine。
502502
cyberBlocked := service.GetOpsCyberPolicy(c) != nil
@@ -901,7 +901,7 @@ func (h *OpenAIGatewayHandler) Messages(c *gin.Context) {
901901
clientIP := ip.GetClientIP(c)
902902
requestPayloadHash := service.HashUsageRequestPayload(body)
903903
inboundEndpoint := GetInboundEndpoint(c)
904-
upstreamEndpoint := GetUpstreamEndpoint(c, account.Platform)
904+
upstreamEndpoint := resolveOpenAIUpstreamEndpoint(c, account)
905905

906906
cyberBlocked := service.GetOpsCyberPolicy(c) != nil
907907
h.submitOpenAIUsageRecordTask(c.Request.Context(), result, func(ctx context.Context) {
@@ -1496,7 +1496,7 @@ func (h *OpenAIGatewayHandler) ResponsesWebSocket(c *gin.Context) {
14961496
}
14971497
h.gatewayService.ReportOpenAIAccountScheduleResult(account.ID, true, result.FirstTokenMs)
14981498
inboundEndpoint := GetInboundEndpoint(c)
1499-
upstreamEndpoint := GetUpstreamEndpoint(c, account.Platform)
1499+
upstreamEndpoint := resolveOpenAIUpstreamEndpoint(c, account)
15001500
cyberBlocked := service.GetOpsCyberPolicy(c) != nil
15011501
h.submitOpenAIUsageRecordTask(ctx, result, func(taskCtx context.Context) {
15021502
if err := h.gatewayService.RecordUsage(taskCtx, &service.OpenAIRecordUsageInput{
@@ -2297,7 +2297,7 @@ func (h *OpenAIGatewayHandler) recordCyberPolicyIfMarked(c *gin.Context, apiKey
22972297
var accountID int64
22982298
if account != nil {
22992299
accountID = account.ID
2300-
upstreamEndpoint = GetUpstreamEndpoint(c, account.Platform)
2300+
upstreamEndpoint = resolveOpenAIUpstreamEndpoint(c, account)
23012301
}
23022302
stream := false
23032303
if v, ok := c.Get(opsStreamKey); ok {

0 commit comments

Comments
 (0)