Skip to content

Commit 8372298

Browse files
committed
fix(providers): xAI generation models bypass chat verification
grok-imagine-video and grok-2-image were not in the isNonChatModel() allowlist, causing verify to call Chat API which fails with malformed error. Also fix friendlyVerifyError() fallback splitting inside JSON values via LastIndex.
1 parent a565ad8 commit 8372298

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

internal/http/provider_verify.go

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,8 @@ func isNonChatModel(model string) bool {
166166
"veo-", "google/veo-",
167167
"dall-e-", "imagen-", "google/imagen-",
168168
"gemini-2.5-flash-image", "google/gemini-2.5-flash-image",
169+
"grok-imagine", // xAI video generation (grok-imagine-video)
170+
"grok-2-image", // xAI image generation
169171
}
170172
m := strings.ToLower(model)
171173
for _, prefix := range nonChatPrefixes {
@@ -209,14 +211,24 @@ func friendlyVerifyError(err error) string {
209211
}
210212
}
211213

212-
// Fallback: strip "HTTP NNN: provider: " prefix for cleaner display
213-
if idx := strings.LastIndex(msg, ": "); idx >= 0 && idx < len(msg)-2 {
214+
// Fallback: strip "HTTP NNN: provider: " prefix for cleaner display.
215+
// Use the FIRST ": " after "HTTP NNN" to avoid splitting inside JSON values.
216+
if idx := strings.Index(msg, ": "); idx >= 0 && idx < len(msg)-2 {
214217
suffix := msg[idx+2:]
215-
// If the remainder still looks like JSON, just say "invalid model"
218+
// Skip one more ": " to strip "provider: " prefix (e.g. "xai: {...}")
219+
if idx2 := strings.Index(suffix, ": "); idx2 >= 0 && idx2 < 30 {
220+
suffix = suffix[idx2+2:]
221+
}
222+
// If the remainder looks like JSON, say "invalid model"
216223
if strings.HasPrefix(suffix, "{") {
217224
return "Model not recognized by provider"
218225
}
219-
return suffix
226+
// Strip leaked JSON quotes/braces from partial extraction
227+
suffix = strings.TrimRight(suffix, "{}[]")
228+
suffix = strings.Trim(suffix, `"`)
229+
if suffix != "" {
230+
return suffix
231+
}
220232
}
221233

222234
return msg

0 commit comments

Comments
 (0)