conductor-oss/conductor · error · RuntimeException

Stability AI image generation failed:

Error message

Stability AI image generation failed: 

What it means

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.

Source

Thrown at ai/src/main/java/org/conductoross/conductor/ai/providers/stabilityai/StabilityAI.java:126

                                        textPrompt,
                                        model,
                                        "png",
                                        aspectRatio,
                                        null, // negativePrompt (not exposed via ImageOptions)
                                        null, // seed
                                        style);

                        // Call the v2beta API
                        StabilityAiApi.ImageResult result = api.generateImage(params);

                        // Wrap raw bytes as base64 in Spring AI's response format
                        String b64 = Base64.getEncoder().encodeToString(result.imageBytes());
                        Image image = new Image(null, b64);
                        ImageGeneration generation = new ImageGeneration(image);

                        return new ImageResponse(List.of(generation));
                    } catch (Exception e) {
                        throw new RuntimeException(
                                "Stability AI image generation failed: " + e.getMessage(), e);
                    }
                };
    }

    @Override
    public String getModelProvider() {
        return NAME;
    }

    @Override
    public ImageModel getImageModel() {
        return this.imageModel;
    }

    @Override
    public ImageOptions getImageOptions(ImageGenRequest input) {
        // Build standard ImageOptions. The model field controls endpoint routing

View on GitHub (pinned to cf7c3e4a8a)

Solutions

  1. Call getCause() on the RuntimeException to recover the real failure (IOException, IllegalArgumentException, etc.).
  2. Ensure the ImagePrompt contains at least one message with non-blank text.
  3. Verify STABILITY_API_KEY / conductor.ai.stabilityai.apiKey is set and valid.
  4. Confirm the model name routes to a valid v2beta endpoint (sd3/core/ultra).
  5. For 402/429, top up credits or apply backoff.

Example fix

// before
ImageResponse resp = stabilityAI.getImageModel().call(prompt); // RuntimeException

// after
try {
    ImageResponse resp = stabilityAI.getImageModel().call(prompt);
} catch (RuntimeException e) {
    Throwable cause = e.getCause();
    if (cause instanceof IOException io) {
        // network / API status failure
    }
    throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

if (prompt == null || prompt.getInstructions() == null || prompt.getInstructions().isEmpty()) {
    throw new IllegalArgumentException("ImagePrompt must contain at least one message");
}
String text = prompt.getInstructions().get(0).getText();
if (text == null || text.isBlank()) {
    throw new IllegalArgumentException("Prompt text must be non-blank");
}

Try / catch

try {
    ImageResponse resp = stabilityAI.getImageModel().call(prompt);
} catch (RuntimeException e) {
    Throwable cause = e.getCause();
    if (cause instanceof IllegalArgumentException) {
        // bad prompt shape - fix input
    } else if (cause instanceof IOException) {
        // API/network failure - inspect cause.getMessage() for status
    }
    throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of conductor-oss/conductor@cf7c3e4a8a (2026-08-14). Data as JSON: /api/errors/5b05a80f461cdcb9. Report an issue: GitHub.