feat(routes): add platform-based routing split for /v1/responses and /v1/chat/completions
Mirror the existing /v1/messages platform split pattern: - OpenAI groups → OpenAIGateway handlers (existing, unchanged) - Non-OpenAI groups → Gateway handlers (new Anthropic-upstream path) Updated both /v1 prefixed routes and non-prefixed alias routes (/responses, /chat/completions). WebSocket route (/v1/responses GET) remains OpenAI-only as Anthropic has no WebSocket equivalent.
This commit is contained in:
@@ -69,12 +69,30 @@ func RegisterGatewayRoutes(
|
|||||||
})
|
})
|
||||||
gateway.GET("/models", h.Gateway.Models)
|
gateway.GET("/models", h.Gateway.Models)
|
||||||
gateway.GET("/usage", h.Gateway.Usage)
|
gateway.GET("/usage", h.Gateway.Usage)
|
||||||
// OpenAI Responses API
|
// OpenAI Responses API: auto-route based on group platform
|
||||||
gateway.POST("/responses", h.OpenAIGateway.Responses)
|
gateway.POST("/responses", func(c *gin.Context) {
|
||||||
gateway.POST("/responses/*subpath", h.OpenAIGateway.Responses)
|
if getGroupPlatform(c) == service.PlatformOpenAI {
|
||||||
|
h.OpenAIGateway.Responses(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.Gateway.Responses(c)
|
||||||
|
})
|
||||||
|
gateway.POST("/responses/*subpath", func(c *gin.Context) {
|
||||||
|
if getGroupPlatform(c) == service.PlatformOpenAI {
|
||||||
|
h.OpenAIGateway.Responses(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.Gateway.Responses(c)
|
||||||
|
})
|
||||||
gateway.GET("/responses", h.OpenAIGateway.ResponsesWebSocket)
|
gateway.GET("/responses", h.OpenAIGateway.ResponsesWebSocket)
|
||||||
// OpenAI Chat Completions API
|
// OpenAI Chat Completions API: auto-route based on group platform
|
||||||
gateway.POST("/chat/completions", h.OpenAIGateway.ChatCompletions)
|
gateway.POST("/chat/completions", func(c *gin.Context) {
|
||||||
|
if getGroupPlatform(c) == service.PlatformOpenAI {
|
||||||
|
h.OpenAIGateway.ChatCompletions(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.Gateway.ChatCompletions(c)
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gemini 原生 API 兼容层(Gemini SDK/CLI 直连)
|
// Gemini 原生 API 兼容层(Gemini SDK/CLI 直连)
|
||||||
@@ -92,12 +110,25 @@ func RegisterGatewayRoutes(
|
|||||||
gemini.POST("/models/*modelAction", h.Gateway.GeminiV1BetaModels)
|
gemini.POST("/models/*modelAction", h.Gateway.GeminiV1BetaModels)
|
||||||
}
|
}
|
||||||
|
|
||||||
// OpenAI Responses API(不带v1前缀的别名)
|
// OpenAI Responses API(不带v1前缀的别名)— auto-route based on group platform
|
||||||
r.POST("/responses", bodyLimit, clientRequestID, opsErrorLogger, endpointNorm, gin.HandlerFunc(apiKeyAuth), requireGroupAnthropic, h.OpenAIGateway.Responses)
|
responsesHandler := func(c *gin.Context) {
|
||||||
r.POST("/responses/*subpath", bodyLimit, clientRequestID, opsErrorLogger, endpointNorm, gin.HandlerFunc(apiKeyAuth), requireGroupAnthropic, h.OpenAIGateway.Responses)
|
if getGroupPlatform(c) == service.PlatformOpenAI {
|
||||||
|
h.OpenAIGateway.Responses(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.Gateway.Responses(c)
|
||||||
|
}
|
||||||
|
r.POST("/responses", bodyLimit, clientRequestID, opsErrorLogger, endpointNorm, gin.HandlerFunc(apiKeyAuth), requireGroupAnthropic, responsesHandler)
|
||||||
|
r.POST("/responses/*subpath", bodyLimit, clientRequestID, opsErrorLogger, endpointNorm, gin.HandlerFunc(apiKeyAuth), requireGroupAnthropic, responsesHandler)
|
||||||
r.GET("/responses", bodyLimit, clientRequestID, opsErrorLogger, endpointNorm, gin.HandlerFunc(apiKeyAuth), requireGroupAnthropic, h.OpenAIGateway.ResponsesWebSocket)
|
r.GET("/responses", bodyLimit, clientRequestID, opsErrorLogger, endpointNorm, gin.HandlerFunc(apiKeyAuth), requireGroupAnthropic, h.OpenAIGateway.ResponsesWebSocket)
|
||||||
// OpenAI Chat Completions API(不带v1前缀的别名)
|
// OpenAI Chat Completions API(不带v1前缀的别名)— auto-route based on group platform
|
||||||
r.POST("/chat/completions", bodyLimit, clientRequestID, opsErrorLogger, endpointNorm, gin.HandlerFunc(apiKeyAuth), requireGroupAnthropic, h.OpenAIGateway.ChatCompletions)
|
r.POST("/chat/completions", bodyLimit, clientRequestID, opsErrorLogger, endpointNorm, gin.HandlerFunc(apiKeyAuth), requireGroupAnthropic, func(c *gin.Context) {
|
||||||
|
if getGroupPlatform(c) == service.PlatformOpenAI {
|
||||||
|
h.OpenAIGateway.ChatCompletions(c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
h.Gateway.ChatCompletions(c)
|
||||||
|
})
|
||||||
|
|
||||||
// Antigravity 模型列表
|
// Antigravity 模型列表
|
||||||
r.GET("/antigravity/models", gin.HandlerFunc(apiKeyAuth), requireGroupAnthropic, h.Gateway.AntigravityModels)
|
r.GET("/antigravity/models", gin.HandlerFunc(apiKeyAuth), requireGroupAnthropic, h.Gateway.AntigravityModels)
|
||||||
|
|||||||
Reference in New Issue
Block a user