Skip to content

Commit d927c0e

Browse files
committed
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.
1 parent 31660c4 commit d927c0e

1 file changed

Lines changed: 41 additions & 10 deletions

File tree

backend/internal/server/routes/gateway.go

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,30 @@ func RegisterGatewayRoutes(
6969
})
7070
gateway.GET("/models", h.Gateway.Models)
7171
gateway.GET("/usage", h.Gateway.Usage)
72-
// OpenAI Responses API
73-
gateway.POST("/responses", h.OpenAIGateway.Responses)
74-
gateway.POST("/responses/*subpath", h.OpenAIGateway.Responses)
72+
// OpenAI Responses API: auto-route based on group platform
73+
gateway.POST("/responses", func(c *gin.Context) {
74+
if getGroupPlatform(c) == service.PlatformOpenAI {
75+
h.OpenAIGateway.Responses(c)
76+
return
77+
}
78+
h.Gateway.Responses(c)
79+
})
80+
gateway.POST("/responses/*subpath", func(c *gin.Context) {
81+
if getGroupPlatform(c) == service.PlatformOpenAI {
82+
h.OpenAIGateway.Responses(c)
83+
return
84+
}
85+
h.Gateway.Responses(c)
86+
})
7587
gateway.GET("/responses", h.OpenAIGateway.ResponsesWebSocket)
76-
// OpenAI Chat Completions API
77-
gateway.POST("/chat/completions", h.OpenAIGateway.ChatCompletions)
88+
// OpenAI Chat Completions API: auto-route based on group platform
89+
gateway.POST("/chat/completions", func(c *gin.Context) {
90+
if getGroupPlatform(c) == service.PlatformOpenAI {
91+
h.OpenAIGateway.ChatCompletions(c)
92+
return
93+
}
94+
h.Gateway.ChatCompletions(c)
95+
})
7896
}
7997

8098
// Gemini 原生 API 兼容层(Gemini SDK/CLI 直连)
@@ -92,12 +110,25 @@ func RegisterGatewayRoutes(
92110
gemini.POST("/models/*modelAction", h.Gateway.GeminiV1BetaModels)
93111
}
94112

95-
// OpenAI Responses API(不带v1前缀的别名)
96-
r.POST("/responses", bodyLimit, clientRequestID, opsErrorLogger, endpointNorm, gin.HandlerFunc(apiKeyAuth), requireGroupAnthropic, h.OpenAIGateway.Responses)
97-
r.POST("/responses/*subpath", bodyLimit, clientRequestID, opsErrorLogger, endpointNorm, gin.HandlerFunc(apiKeyAuth), requireGroupAnthropic, h.OpenAIGateway.Responses)
113+
// OpenAI Responses API(不带v1前缀的别名)— auto-route based on group platform
114+
responsesHandler := func(c *gin.Context) {
115+
if getGroupPlatform(c) == service.PlatformOpenAI {
116+
h.OpenAIGateway.Responses(c)
117+
return
118+
}
119+
h.Gateway.Responses(c)
120+
}
121+
r.POST("/responses", bodyLimit, clientRequestID, opsErrorLogger, endpointNorm, gin.HandlerFunc(apiKeyAuth), requireGroupAnthropic, responsesHandler)
122+
r.POST("/responses/*subpath", bodyLimit, clientRequestID, opsErrorLogger, endpointNorm, gin.HandlerFunc(apiKeyAuth), requireGroupAnthropic, responsesHandler)
98123
r.GET("/responses", bodyLimit, clientRequestID, opsErrorLogger, endpointNorm, gin.HandlerFunc(apiKeyAuth), requireGroupAnthropic, h.OpenAIGateway.ResponsesWebSocket)
99-
// OpenAI Chat Completions API(不带v1前缀的别名)
100-
r.POST("/chat/completions", bodyLimit, clientRequestID, opsErrorLogger, endpointNorm, gin.HandlerFunc(apiKeyAuth), requireGroupAnthropic, h.OpenAIGateway.ChatCompletions)
124+
// OpenAI Chat Completions API(不带v1前缀的别名)— auto-route based on group platform
125+
r.POST("/chat/completions", bodyLimit, clientRequestID, opsErrorLogger, endpointNorm, gin.HandlerFunc(apiKeyAuth), requireGroupAnthropic, func(c *gin.Context) {
126+
if getGroupPlatform(c) == service.PlatformOpenAI {
127+
h.OpenAIGateway.ChatCompletions(c)
128+
return
129+
}
130+
h.Gateway.ChatCompletions(c)
131+
})
101132

102133
// Antigravity 模型列表
103134
r.GET("/antigravity/models", gin.HandlerFunc(apiKeyAuth), requireGroupAnthropic, h.Gateway.AntigravityModels)

0 commit comments

Comments
 (0)