{"record":{"id":"a36227152637e60d","repo":"siyuan-note/siyuan","slug":"image-model-returned-no-image","errorCode":null,"errorMessage":"image model returned no image","messagePattern":"image model returned no image","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"kernel/util/openai.go","lineNumber":906,"sourceCode":"\t\tSize:    request.Size,\n\t\tQuality: request.Quality,\n\t}\n\tif strings.HasPrefix(strings.ToLower(adapter.model), \"dall-e\") {\n\t\timageRequest.ResponseFormat = openai.CreateImageResponseFormatB64JSON\n\t\tif imageRequest.Quality == \"auto\" {\n\t\t\timageRequest.Quality = \"\"\n\t\t}\n\t} else {\n\t\timageRequest.OutputFormat = request.OutputFormat\n\t}\n\trequestCtx, cancel := context.WithTimeout(ctx, adapter.timeout)\n\tdefer cancel()\n\tresponse, err := adapter.client.CreateImage(requestCtx, imageRequest)\n\tif err != nil {\n\t\treturn GeneratedImage{}, err\n\t}\n\tif len(response.Data) == 0 {\n\t\treturn GeneratedImage{}, errors.New(\"image model returned no image\")\n\t}\n\tresult := response.Data[0]\n\tvar data []byte\n\tif result.B64JSON != \"\" {\n\t\tdata, err = base64.StdEncoding.DecodeString(result.B64JSON)\n\t} else if result.URL != \"\" {\n\t\tdata, err = downloadGeneratedImage(requestCtx, result.URL)\n\t} else {\n\t\terr = errors.New(\"image model returned neither base64 data nor URL\")\n\t}\n\tif err != nil {\n\t\treturn GeneratedImage{}, err\n\t}\n\tmimeType, extension, err := ValidateGeneratedImage(data)\n\tif err != nil {\n\t\treturn GeneratedImage{}, err\n\t}\n\treturn GeneratedImage{Data: data, MIMEType: mimeType, Extension: extension, RevisedPrompt: result.RevisedPrompt}, nil","sourceCodeStart":888,"sourceCodeEnd":924,"githubUrl":"https://github.com/siyuan-note/siyuan/blob/9f775e8a12daef8255556097396f9b2739078892/kernel/util/openai.go#L888-L924","documentation":"After CreateImage succeeds at the HTTP level, the adapter checks that the response contains at least one item in response.Data. When the provider returns an empty Data array, there is nothing to decode, so Generate returns this error. It guards against providers/proxies that answer 200 with no image payload.","triggerScenarios":"adapter.client.CreateImage returns a response whose Data slice has length 0 — e.g. the model produced no image, a proxy/gateway stripped the data array, or the configured model ID is not an image model and returned an empty success payload.","commonSituations":"Pointing the image model setting at a chat model via a compatible proxy; a self-hosted gateway returning an empty JSON body parsed as an empty Data array; provider-side content filtering that silently drops the image; API version mismatch returning a different response shape.","solutions":["Verify the configured image model is actually an image-capable model (e.g. dall-e-2/3, not a chat model)","Call the provider directly once (curl) to confirm it returns a non-empty data array — if not, fix the proxy/gateway","Check provider response for content-policy filtering and surface it to the user","Retry the generation; transient provider issues can yield empty results"],"exampleFix":"// before\nresp, err := adapter.client.CreateImage(ctx, req) // resp.Data empty -> 'image model returned no image'\n// after\nresp, err := adapter.client.CreateImage(ctx, req)\nif err != nil { return err }\nif len(resp.Data) == 0 {\n    return fmt.Errorf(\"image model %s returned no image; check model ID and provider response\", adapter.model)\n}","handlingStrategy":"validation","validationCode":"if len(response.Data) == 0 {\n    // surface a retry/fallback path instead of indexing Data[0]\n}","typeGuard":null,"tryCatchPattern":"if err != nil {\n    return fmt.Errorf(\"image generation failed: %w\", err)\n}\nif len(response.Data) == 0 {\n    return retryOrFail() // handle empty Data explicitly\n}","preventionTips":["Confirm the configured model ID is an image model","Test the provider/proxy with a direct curl before wiring it in","Handle empty Data arrays explicitly instead of assuming success means an image"],"tags":["openai","image-generation","api-response"],"backgroundTag":"empty-api-response","analyzedSha":"9f775e8a12daef8255556097396f9b2739078892","analyzedAt":"2026-09-19T03:17:15.984Z","contentChangedAt":"2026-09-19T03:17:15.984Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}