fix(openai): bypass responses for unknown third-party API keys

This commit is contained in:
Your Name
2026-05-21 12:20:41 +08:00
parent 70ca4eb72c
commit 0d9df842e4
6 changed files with 239 additions and 33 deletions

View File

@@ -10,7 +10,6 @@ import (
pkghttputil "github.com/Wei-Shaw/sub2api/internal/pkg/httputil"
"github.com/Wei-Shaw/sub2api/internal/pkg/ip"
"github.com/Wei-Shaw/sub2api/internal/pkg/logger"
"github.com/Wei-Shaw/sub2api/internal/pkg/openai_compat"
middleware2 "github.com/Wei-Shaw/sub2api/internal/server/middleware"
"github.com/Wei-Shaw/sub2api/internal/service"
"github.com/gin-gonic/gin"
@@ -291,13 +290,12 @@ func (h *OpenAIGatewayHandler) ChatCompletions(c *gin.Context) {
}
// resolveRawCCUpstreamEndpoint returns the actual upstream endpoint for
// OpenAI Chat Completions requests. For APIKey accounts whose upstream
// has been probed to not support the Responses API, the request is
// forwarded directly to /v1/chat/completions — not through the default
// CC→Responses conversion path.
// OpenAI Chat Completions requests. For APIKey accounts that should bypass
// the Responses path (explicitly unsupported, or unknown support with a
// third-party custom base_url), the request is forwarded directly to
// /v1/chat/completions.
func resolveRawCCUpstreamEndpoint(c *gin.Context, account *service.Account) string {
if account != nil && account.Type == service.AccountTypeAPIKey &&
!openai_compat.ShouldUseResponsesAPI(account.Extra) {
if account != nil && account.ShouldUseRawOpenAIChatCompletions() {
return "/v1/chat/completions"
}
return GetUpstreamEndpoint(c, account.Platform)