{"record":{"id":"b30001e66380b069","repo":"spring-projects/spring-ai","slug":"image-generation-failed-no-image-returned","errorCode":null,"errorMessage":"Image generation failed: no image returned","messagePattern":"Image generation failed: no image returned","errorType":"exception","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiImageModel.java","lineNumber":212,"sourceCode":"\t\tif (logger.isTraceEnabled()) {\n\t\t\tlogger.trace(\"OpenAiImageOptions call \" + options.getModel() + \" with the following options : \"\n\t\t\t\t\t+ imageGenerateParams);\n\t\t}\n\n\t\tvar observationContext = ImageModelObservationContext.builder()\n\t\t\t.imagePrompt(imagePrompt)\n\t\t\t.provider(AiProvider.OPENAI.value())\n\t\t\t.build();\n\n\t\treturn Objects.requireNonNull(\n\t\t\t\tImageModelObservationDocumentation.IMAGE_MODEL_OPERATION\n\t\t\t\t\t.observation(this.observationConvention, DEFAULT_OBSERVATION_CONVENTION, () -> observationContext,\n\t\t\t\t\t\t\tthis.observationRegistry)\n\t\t\t\t\t.observe(() -> {\n\t\t\t\t\t\tvar images = this.openAiClient.images().generate(imageGenerateParams, requestOptions);\n\n\t\t\t\t\t\tif (images.data().isEmpty() || images.data().get().isEmpty()) {\n\t\t\t\t\t\t\tthrow new IllegalArgumentException(\"Image generation failed: no image returned\");\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\tList<ImageGeneration> imageGenerations = images.data().get().stream().map(nativeImage -> {\n\t\t\t\t\t\t\tImage image;\n\t\t\t\t\t\t\tif (nativeImage.url().isPresent()) {\n\t\t\t\t\t\t\t\timage = new Image(nativeImage.url().get(), null);\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse if (nativeImage.b64Json().isPresent()) {\n\t\t\t\t\t\t\t\timage = new Image(null, nativeImage.b64Json().get());\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\telse {\n\t\t\t\t\t\t\t\tthrow new IllegalArgumentException(\n\t\t\t\t\t\t\t\t\t\t\"Image generation failed: image entry missing url and b64_json\");\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tvar metadata = new OpenAiImageGenerationMetadata(nativeImage.revisedPrompt().orElse(null));\n\t\t\t\t\t\t\treturn new ImageGeneration(image, metadata);\n\t\t\t\t\t\t}).toList();\n\t\t\t\t\t\tImageResponseMetadata openAiImageResponseMetadata = OpenAiImageResponseMetadata.from(images);","sourceCodeStart":194,"sourceCodeEnd":230,"githubUrl":"https://github.com/spring-projects/spring-ai/blob/98a7beda4f29d80a71c5837eb4053b03a93a46f7/models/spring-ai-openai/src/main/java/org/springframework/ai/openai/OpenAiImageModel.java#L194-L230","documentation":"OpenAiImageModel.call validates that the OpenAI images API returned a non-empty data array. When the response has no entries at all, it throws this IllegalArgumentException, since an image generation with zero results is unusable.","triggerScenarios":"Calling OpenAiImageModel.call(...) when the API response's images.data() is empty or the Optional list is empty — e.g. the API silently returned no images for the prompt/model/parameters combination.","commonSituations":"Content-policy-filtered prompts, unsupported model+parameter combinations (e.g. gpt-image-1 with response_format), or a misconfigured Azure deployment returning an empty body.","solutions":["Inspect the prompt and options (model, size, quality, n) for combinations the API may reject silently; adjust and retry.","Catch IllegalArgumentException around call() and surface a user-facing 'no image produced' message.","Enable HTTP logging to inspect the raw response and confirm the API returned an empty data array."],"exampleFix":"try {\n    ImageResponse response = imageModel.call(new ImagePrompt(prompt));\n}\ncatch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"no image returned\")) {\n        throw new ImageGenerationException(\"Model returned no image; revise prompt or options\", e);\n    }\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":"if (promptText == null || promptText.isBlank()) {\n    throw new IllegalArgumentException(\"Prompt must not be blank before calling image model\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    ImageResponse r = imageModel.call(new ImagePrompt(prompt));\n} catch (IllegalArgumentException e) {\n    if (e.getMessage().contains(\"no image returned\")) {\n        throw new ImageGenerationException(\"API returned no images; revise prompt or options\", e);\n    }\n    throw e;\n}","preventionTips":["Log raw API responses when generation returns empty","Review prompt against content-policy filters","Pin model/option combinations known to return images"],"tags":["image-generation","empty-response","api"],"backgroundTag":"empty-api-response","analyzedSha":"98a7beda4f29d80a71c5837eb4053b03a93a46f7","analyzedAt":"2026-09-11T14:15:49.441Z","contentChangedAt":"2026-09-11T14:15:49.441Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}