fix(grok): 拦截图片模型发往 Responses 端点,返回明确错误

Fixes #4301
This commit is contained in:
li
2026-07-15 11:16:07 +08:00
parent cf6aa1a5c3
commit 6a61b2daca
2 changed files with 25 additions and 0 deletions
@@ -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 {
@@ -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))
})
}
}