@@ -19,6 +19,7 @@ func RegisterGatewayRoutes(
1919 apiKeyService * service.APIKeyService ,
2020 subscriptionService * service.SubscriptionService ,
2121 opsService * service.OpsService ,
22+ settingService * service.SettingService ,
2223 cfg * config.Config ,
2324) {
2425 bodyLimit := middleware .RequestBodyLimit (cfg .Gateway .MaxBodySize )
@@ -30,12 +31,17 @@ func RegisterGatewayRoutes(
3031 clientRequestID := middleware .ClientRequestID ()
3132 opsErrorLogger := handler .OpsErrorLoggerMiddleware (opsService )
3233
34+ // 未分组 Key 拦截中间件(按协议格式区分错误响应)
35+ requireGroupAnthropic := middleware .RequireGroupAssignment (settingService , middleware .AnthropicErrorWriter )
36+ requireGroupGoogle := middleware .RequireGroupAssignment (settingService , middleware .GoogleErrorWriter )
37+
3338 // API网关(Claude API兼容)
3439 gateway := r .Group ("/v1" )
3540 gateway .Use (bodyLimit )
3641 gateway .Use (clientRequestID )
3742 gateway .Use (opsErrorLogger )
3843 gateway .Use (gin .HandlerFunc (apiKeyAuth ))
44+ gateway .Use (requireGroupAnthropic )
3945 {
4046 gateway .POST ("/messages" , h .Gateway .Messages )
4147 gateway .POST ("/messages/count_tokens" , h .Gateway .CountTokens )
@@ -61,6 +67,7 @@ func RegisterGatewayRoutes(
6167 gemini .Use (clientRequestID )
6268 gemini .Use (opsErrorLogger )
6369 gemini .Use (middleware .APIKeyAuthWithSubscriptionGoogle (apiKeyService , subscriptionService , cfg ))
70+ gemini .Use (requireGroupGoogle )
6471 {
6572 gemini .GET ("/models" , h .Gateway .GeminiV1BetaListModels )
6673 gemini .GET ("/models/:model" , h .Gateway .GeminiV1BetaGetModel )
@@ -69,11 +76,11 @@ func RegisterGatewayRoutes(
6976 }
7077
7178 // OpenAI Responses API(不带v1前缀的别名)
72- r .POST ("/responses" , bodyLimit , clientRequestID , opsErrorLogger , gin .HandlerFunc (apiKeyAuth ), h .OpenAIGateway .Responses )
73- r .GET ("/responses" , bodyLimit , clientRequestID , opsErrorLogger , gin .HandlerFunc (apiKeyAuth ), h .OpenAIGateway .ResponsesWebSocket )
79+ r .POST ("/responses" , bodyLimit , clientRequestID , opsErrorLogger , gin .HandlerFunc (apiKeyAuth ), requireGroupAnthropic , h .OpenAIGateway .Responses )
80+ r .GET ("/responses" , bodyLimit , clientRequestID , opsErrorLogger , gin .HandlerFunc (apiKeyAuth ), requireGroupAnthropic , h .OpenAIGateway .ResponsesWebSocket )
7481
7582 // Antigravity 模型列表
76- r .GET ("/antigravity/models" , gin .HandlerFunc (apiKeyAuth ), h .Gateway .AntigravityModels )
83+ r .GET ("/antigravity/models" , gin .HandlerFunc (apiKeyAuth ), requireGroupAnthropic , h .Gateway .AntigravityModels )
7784
7885 // Antigravity 专用路由(仅使用 antigravity 账户,不混合调度)
7986 antigravityV1 := r .Group ("/antigravity/v1" )
@@ -82,6 +89,7 @@ func RegisterGatewayRoutes(
8289 antigravityV1 .Use (opsErrorLogger )
8390 antigravityV1 .Use (middleware .ForcePlatform (service .PlatformAntigravity ))
8491 antigravityV1 .Use (gin .HandlerFunc (apiKeyAuth ))
92+ antigravityV1 .Use (requireGroupAnthropic )
8593 {
8694 antigravityV1 .POST ("/messages" , h .Gateway .Messages )
8795 antigravityV1 .POST ("/messages/count_tokens" , h .Gateway .CountTokens )
@@ -95,6 +103,7 @@ func RegisterGatewayRoutes(
95103 antigravityV1Beta .Use (opsErrorLogger )
96104 antigravityV1Beta .Use (middleware .ForcePlatform (service .PlatformAntigravity ))
97105 antigravityV1Beta .Use (middleware .APIKeyAuthWithSubscriptionGoogle (apiKeyService , subscriptionService , cfg ))
106+ antigravityV1Beta .Use (requireGroupGoogle )
98107 {
99108 antigravityV1Beta .GET ("/models" , h .Gateway .GeminiV1BetaListModels )
100109 antigravityV1Beta .GET ("/models/:model" , h .Gateway .GeminiV1BetaGetModel )
@@ -108,6 +117,7 @@ func RegisterGatewayRoutes(
108117 soraV1 .Use (opsErrorLogger )
109118 soraV1 .Use (middleware .ForcePlatform (service .PlatformSora ))
110119 soraV1 .Use (gin .HandlerFunc (apiKeyAuth ))
120+ soraV1 .Use (requireGroupAnthropic )
111121 {
112122 soraV1 .POST ("/chat/completions" , h .SoraGateway .ChatCompletions )
113123 soraV1 .GET ("/models" , h .Gateway .Models )
0 commit comments