From 6a61b2dacae6a5e934523129ab4b0730dfd16232 Mon Sep 17 00:00:00 2001 From: li Date: Wed, 15 Jul 2026 10:48:30 +0800 Subject: [PATCH] =?UTF-8?q?fix(grok):=20=E6=8B=A6=E6=88=AA=E5=9B=BE?= =?UTF-8?q?=E7=89=87=E6=A8=A1=E5=9E=8B=E5=8F=91=E5=BE=80=20Responses=20?= =?UTF-8?q?=E7=AB=AF=E7=82=B9=EF=BC=8C=E8=BF=94=E5=9B=9E=E6=98=8E=E7=A1=AE?= =?UTF-8?q?=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixes #4301 --- .../internal/service/openai_gateway_grok.go | 3 +++ .../service/openai_gateway_grok_test.go | 22 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/backend/internal/service/openai_gateway_grok.go b/backend/internal/service/openai_gateway_grok.go index 92cf2910c6..93c0f8cb0f 100644 --- a/backend/internal/service/openai_gateway_grok.go +++ b/backend/internal/service/openai_gateway_grok.go @@ -49,6 +49,9 @@ func (s *OpenAIGatewayService) forwardGrokResponses( if strings.TrimSpace(upstreamModel) == "" { upstreamModel = grokDefaultResponsesModel } + if isGrokImageGenerationModel(upstreamModel) { + return nil, fmt.Errorf("model %s is an image model and is not available on the Responses endpoint; use /v1/images/generations instead", upstreamModel) + } cacheIdentity := resolveGrokCacheIdentity(c, body, "", upstreamModel) patchedBody, err := patchGrokResponsesBody(body, upstreamModel) if err != nil { diff --git a/backend/internal/service/openai_gateway_grok_test.go b/backend/internal/service/openai_gateway_grok_test.go index d93415b2e0..882adc56ed 100644 --- a/backend/internal/service/openai_gateway_grok_test.go +++ b/backend/internal/service/openai_gateway_grok_test.go @@ -2037,3 +2037,25 @@ func TestPatchGrokResponsesBody_MultipleReasoningContentNull(t *testing.T) { require.False(t, items[0].Get("content").Exists()) require.False(t, items[2].Get("content").Exists()) } + +func TestIsGrokImageGenerationModel(t *testing.T) { + t.Parallel() + + tests := []struct { + model string + want bool + }{ + {"grok-imagine", true}, + {"grok-imagine-image-quality", true}, + {"grok-imagine-edit", true}, + {"grok-imagine-image-hd", true}, + {"grok-4.5", false}, + {"grok-composer", false}, + } + for _, tt := range tests { + t.Run(tt.model, func(t *testing.T) { + require.Equal(t, tt.want, isGrokImageGenerationModel(tt.model)) + }) + } +} +