conductor-oss/conductor · error · RuntimeException

Gemini generateImages failed: {message}

Error message

Gemini generateImages failed: {message}

What it means

GeminiGenAI.call() wraps any IOException from GeminiApi.generateImages() into a RuntimeException. GeminiGenAI is the ImageModel implementation for the Gemini/Vertex provider, used for image generation via Google's Imagen models through the Gemini API. The cause IOException carries the transport or API-level error detail.

Source

Thrown at ai/src/main/java/org/conductoross/conductor/ai/providers/gemini/GeminiGenAI.java:45

    public GeminiGenAI(GeminiApi api) {
        this.api = api;
    }

    @Override
    public ImageResponse call(ImagePrompt request) {
        var options = request.getOptions();
        String model = options.getModel();
        String promptText = request.getInstructions().getFirst().getText();

        GeminiApi.GenerateImagesConfig config =
                new GeminiApi.GenerateImagesConfig(options.getN(), "image/png", true);

        GeminiApi.GenerateImagesResponse response;
        try {
            response = api.generateImages(model, promptText, config);
        } catch (java.io.IOException e) {
            throw new RuntimeException("Gemini generateImages failed: " + e.getMessage(), e);
        }

        List<GeminiApi.ImagePrediction> predictions =
                response.predictions() != null ? response.predictions() : List.of();
        List<ImageGeneration> generations = new ArrayList<>();
        for (GeminiApi.ImagePrediction pred : predictions) {
            if (pred.bytesBase64Encoded() != null) {
                org.springframework.ai.image.Image img =
                        new org.springframework.ai.image.Image(null, pred.bytesBase64Encoded());
                generations.add(new ImageGeneration(img));
            }
        }
        return new ImageResponse(generations);
    }
}

View on GitHub (pinned to cf7c3e4a8a)

Solutions

  1. Inspect getCause() for the IOException detail and any HTTP status/body.
  2. Verify the image model name is a valid Imagen model (e.g. 'imagen-3.0-generate-002', 'imagen-4.0-generate-001').
  3. Verify the API key or Vertex AI credentials have access to the image generation model.
  4. Check if the prompt was rejected by content safety (the response body will indicate this).

Example fix

// before
ImageOptions opts = ImageOptionsBuilder.builder().model("gemini-2.5-flash").build();

// after — use an actual image generation model
ImageOptions opts = ImageOptionsBuilder.builder().model("imagen-3.0-generate-002").build();
Defensive patterns

Strategy: try-catch

Validate before calling

// Validate the image model name before calling generateImages
private static final Set<String> GEMINI_IMAGE_MODELS =
    Set.of("imagen-3.0-generate-002", "imagen-4.0-generate-001",
           "imagen-4.0-ultra-generate-001");

void validateImageModel(String model) {
    if (!GEMINI_IMAGE_MODELS.contains(model)) {
        throw new IllegalArgumentException(
            "Use an Imagen model for Gemini image generation. Got: " + model);
    }
}

Try / catch

try {
    return geminiGenAI.call(imagePrompt);
} catch (RuntimeException e) {
    if (e.getCause() instanceof java.io.IOException io) {
        throw new RuntimeException(
            "Gemini image generation failed — verify model name and content policy", io);
    }
    throw e;
}

Prevention

When it happens

Trigger: The OkHttp call to the Gemini image generation endpoint fails: transport timeout, HTTP error (invalid model, content policy violation, quota exceeded), or the API key lacks permission for the image generation model.

Common situations: Using a model name that doesn't support image generation (e.g. a text-only Gemini model instead of an Imagen model like 'imagen-3.0-generate-002'). Content safety filter rejecting the prompt. Quota for image generation exhausted. API key not enabled for the Imagen API.

Related errors


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