{"record":{"id":"b06d738c37d8dc62","repo":"Wei-Shaw/sub2api","slug":"invalid-request-error-b06d73","errorCode":"invalid_request_error","errorMessage":"model is required","messagePattern":"model is required","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"backend/internal/handler/image_task_handler.go","lineNumber":197,"sourceCode":"\tif err != nil {\n\t\timageTaskError(c, err)\n\t\treturn\n\t}\n\tc.Header(\"Cache-Control\", \"no-store\")\n\tif task.Status == service.ImageTaskStatusProcessing {\n\t\tc.Header(\"Retry-After\", \"3\")\n\t}\n\tc.JSON(http.StatusOK, task)\n}\n\nfunc (h *AsyncImageHandler) validateRequest(c *gin.Context, platform string, body []byte) error {\n\tif h.openAI == nil || h.openAI.gatewayService == nil {\n\t\treturn nil\n\t}\n\tif platform == service.PlatformGrok {\n\t\tparsed := service.ParseGrokMediaRequest(c.GetHeader(\"Content-Type\"), body)\n\t\tif strings.TrimSpace(parsed.Model) == \"\" {\n\t\t\treturn errors.New(\"model is required\")\n\t\t}\n\t\treturn nil\n\t}\n\tparsed, err := h.openAI.gatewayService.ParseOpenAIImagesRequest(c, body)\n\tif err != nil {\n\t\treturn err\n\t}\n\tif parsed.Stream {\n\t\treturn errors.New(\"streaming image requests cannot be submitted as asynchronous tasks\")\n\t}\n\treturn nil\n}\n\nfunc (h *AsyncImageHandler) executeWithGateway(platform string, c *gin.Context) {\n\tif h.openAI == nil {\n\t\timageTaskJSONError(c, http.StatusServiceUnavailable, \"api_error\", \"image gateway is unavailable\")\n\t\treturn\n\t}","sourceCodeStart":179,"sourceCodeEnd":215,"githubUrl":"https://github.com/Wei-Shaw/sub2api/blob/073e92d17178a1ccdb0a27017f572f10c9c7ab62/backend/internal/handler/image_task_handler.go#L179-L215","documentation":"Thrown by AsyncImageHandler.validateRequest when the platform is Grok and the parsed media request (from Content-Type + body) has no model field (code=invalid_request_error). Grok image requests must name a model explicitly; there is no default.","triggerScenarios":"Submitting an async Grok image task whose JSON body (or multipart form) omits \"model\", or contains a whitespace-only value.","commonSituations":"Porting OpenAI Images calls that relied on a default model; form-data submissions where the model field name is mistyped; agentic clients built for a provider that infers the model.","solutions":["Add an explicit \"model\" field (e.g. grok-2-image) to the request body or form","Verify the Content-Type matches how the model field is being sent (JSON vs multipart)","Confirm the model name matches a Grok image model exposed by your deployment"],"exampleFix":"// before\n{\"prompt\": \"a cat\"}\n// after\n{\"model\": \"grok-2-image\", \"prompt\": \"a cat\"}","handlingStrategy":"validation","validationCode":"// TS: validate Grok image payloads before submit\nfunction validateGrokImage(body: Record<string, unknown>) {\n  if (!body.model || String(body.model).trim() === '') {\n    throw new Error('model is required for Grok image tasks');\n  }\n}","typeGuard":"type GrokImageRequest = { model: string; prompt: string };\nfunction isGrokImageRequest(v: unknown): v is GrokImageRequest {\n  return typeof v === 'object' && v !== null && typeof (v as any).model === 'string' && (v as any).model.trim() !== '';\n}","tryCatchPattern":null,"preventionTips":["Never rely on a default model for Grok image calls; set it explicitly","In multipart flows, double-check the model field name and Content-Type"],"tags":["grok","image","validation","async-task"],"backgroundTag":null,"analyzedSha":"073e92d17178a1ccdb0a27017f572f10c9c7ab62","analyzedAt":"2026-08-15T14:33:00.750Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}