{"record":{"id":"5b05a80f461cdcb9","repo":"conductor-oss/conductor","slug":"stability-ai-image-generation-failed","errorCode":null,"errorMessage":"Stability AI image generation failed: ","messagePattern":"Stability AI image generation failed: ","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"ai/src/main/java/org/conductoross/conductor/ai/providers/stabilityai/StabilityAI.java","lineNumber":126,"sourceCode":"                                        textPrompt,\n                                        model,\n                                        \"png\",\n                                        aspectRatio,\n                                        null, // negativePrompt (not exposed via ImageOptions)\n                                        null, // seed\n                                        style);\n\n                        // Call the v2beta API\n                        StabilityAiApi.ImageResult result = api.generateImage(params);\n\n                        // Wrap raw bytes as base64 in Spring AI's response format\n                        String b64 = Base64.getEncoder().encodeToString(result.imageBytes());\n                        Image image = new Image(null, b64);\n                        ImageGeneration generation = new ImageGeneration(image);\n\n                        return new ImageResponse(List.of(generation));\n                    } catch (Exception e) {\n                        throw new RuntimeException(\n                                \"Stability AI image generation failed: \" + e.getMessage(), e);\n                    }\n                };\n    }\n\n    @Override\n    public String getModelProvider() {\n        return NAME;\n    }\n\n    @Override\n    public ImageModel getImageModel() {\n        return this.imageModel;\n    }\n\n    @Override\n    public ImageOptions getImageOptions(ImageGenRequest input) {\n        // Build standard ImageOptions. The model field controls endpoint routing","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/conductor-oss/conductor/blob/cf7c3e4a8adfb158be778ab1ec525323c363cd3a/ai/src/main/java/org/conductoross/conductor/ai/providers/stabilityai/StabilityAI.java#L108-L144","documentation":"Thrown by StabilityAI's ImageModel lambda (StabilityAI.java:126) when ANY exception occurs during image generation; it wraps the cause in a RuntimeException with prefix 'Stability AI image generation failed: '. The wrapped exception's message is appended. The cause may be an IllegalArgumentException (empty prompt), an IOException from StabilityAiApi (235/236), or any other failure in the adapter.","triggerScenarios":"An ImagePrompt with no instructions (IllegalArgumentException 'Image prompt must contain at least one message'), a StabilityAiApi HTTP failure (IOException 235), empty response body (236), invalid API key, exhausted credits (402), or rate limiting (429).","commonSituations":"Empty ImagePrompt, missing/invalid STABILITY_API_KEY (401), depleted Stability credits (402), unsupported model name routing to the wrong endpoint, or an aspect ratio/size the API rejects.","solutions":["Call getCause() on the RuntimeException to recover the real failure (IOException, IllegalArgumentException, etc.).","Ensure the ImagePrompt contains at least one message with non-blank text.","Verify STABILITY_API_KEY / conductor.ai.stabilityai.apiKey is set and valid.","Confirm the model name routes to a valid v2beta endpoint (sd3/core/ultra).","For 402/429, top up credits or apply backoff."],"exampleFix":"// before\nImageResponse resp = stabilityAI.getImageModel().call(prompt); // RuntimeException\n\n// after\ntry {\n    ImageResponse resp = stabilityAI.getImageModel().call(prompt);\n} catch (RuntimeException e) {\n    Throwable cause = e.getCause();\n    if (cause instanceof IOException io) {\n        // network / API status failure\n    }\n    throw e;\n}","handlingStrategy":"try-catch","validationCode":"if (prompt == null || prompt.getInstructions() == null || prompt.getInstructions().isEmpty()) {\n    throw new IllegalArgumentException(\"ImagePrompt must contain at least one message\");\n}\nString text = prompt.getInstructions().get(0).getText();\nif (text == null || text.isBlank()) {\n    throw new IllegalArgumentException(\"Prompt text must be non-blank\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    ImageResponse resp = stabilityAI.getImageModel().call(prompt);\n} catch (RuntimeException e) {\n    Throwable cause = e.getCause();\n    if (cause instanceof IllegalArgumentException) {\n        // bad prompt shape - fix input\n    } else if (cause instanceof IOException) {\n        // API/network failure - inspect cause.getMessage() for status\n    }\n    throw e;\n}","preventionTips":["Always inspect getCause() - the wrapping message hides the real error.","Validate the ImagePrompt has non-blank text before calling.","Confirm STABILITY_API_KEY is set and credits remain.","Pre-validate aspect_ratio/style against Stability's allowed values."],"tags":["stabilityai","image-generation","runtime-exception","wrapper","api-key"],"backgroundTag":null,"analyzedSha":"cf7c3e4a8adfb158be778ab1ec525323c363cd3a","analyzedAt":"2026-08-14T03:33:19.897Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}