{"record":{"id":"8214b88615981a83","repo":"conductor-oss/conductor","slug":"gemini-generateimages-failed-message","errorCode":null,"errorMessage":"Gemini generateImages failed: {message}","messagePattern":"Gemini generateImages failed: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"ai/src/main/java/org/conductoross/conductor/ai/providers/gemini/GeminiGenAI.java","lineNumber":45,"sourceCode":"\n    public GeminiGenAI(GeminiApi api) {\n        this.api = api;\n    }\n\n    @Override\n    public ImageResponse call(ImagePrompt request) {\n        var options = request.getOptions();\n        String model = options.getModel();\n        String promptText = request.getInstructions().getFirst().getText();\n\n        GeminiApi.GenerateImagesConfig config =\n                new GeminiApi.GenerateImagesConfig(options.getN(), \"image/png\", true);\n\n        GeminiApi.GenerateImagesResponse response;\n        try {\n            response = api.generateImages(model, promptText, config);\n        } catch (java.io.IOException e) {\n            throw new RuntimeException(\"Gemini generateImages failed: \" + e.getMessage(), e);\n        }\n\n        List<GeminiApi.ImagePrediction> predictions =\n                response.predictions() != null ? response.predictions() : List.of();\n        List<ImageGeneration> generations = new ArrayList<>();\n        for (GeminiApi.ImagePrediction pred : predictions) {\n            if (pred.bytesBase64Encoded() != null) {\n                org.springframework.ai.image.Image img =\n                        new org.springframework.ai.image.Image(null, pred.bytesBase64Encoded());\n                generations.add(new ImageGeneration(img));\n            }\n        }\n        return new ImageResponse(generations);\n    }\n}\n","sourceCodeStart":27,"sourceCodeEnd":61,"githubUrl":"https://github.com/conductor-oss/conductor/blob/cf7c3e4a8adfb158be778ab1ec525323c363cd3a/ai/src/main/java/org/conductoross/conductor/ai/providers/gemini/GeminiGenAI.java#L27-L61","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Inspect getCause() for the IOException detail and any HTTP status/body.","Verify the image model name is a valid Imagen model (e.g. 'imagen-3.0-generate-002', 'imagen-4.0-generate-001').","Verify the API key or Vertex AI credentials have access to the image generation model.","Check if the prompt was rejected by content safety (the response body will indicate this)."],"exampleFix":"// before\nImageOptions opts = ImageOptionsBuilder.builder().model(\"gemini-2.5-flash\").build();\n\n// after — use an actual image generation model\nImageOptions opts = ImageOptionsBuilder.builder().model(\"imagen-3.0-generate-002\").build();","handlingStrategy":"try-catch","validationCode":"// Validate the image model name before calling generateImages\nprivate static final Set<String> GEMINI_IMAGE_MODELS =\n    Set.of(\"imagen-3.0-generate-002\", \"imagen-4.0-generate-001\",\n           \"imagen-4.0-ultra-generate-001\");\n\nvoid validateImageModel(String model) {\n    if (!GEMINI_IMAGE_MODELS.contains(model)) {\n        throw new IllegalArgumentException(\n            \"Use an Imagen model for Gemini image generation. Got: \" + model);\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    return geminiGenAI.call(imagePrompt);\n} catch (RuntimeException e) {\n    if (e.getCause() instanceof java.io.IOException io) {\n        throw new RuntimeException(\n            \"Gemini image generation failed — verify model name and content policy\", io);\n    }\n    throw e;\n}","preventionTips":["Use an Imagen model name (imagen-3.0-generate-002, imagen-4.0-*) for image generation — chat models won't work.","Verify the API key / Vertex AI credentials have access to the Imagen API.","Review prompts for content that may trigger Google's image safety filters.","Check the image generation quota — it is separate from chat/text quota in Google Cloud."],"tags":["gemini","image-generation","network","io","imagen"],"backgroundTag":null,"analyzedSha":"cf7c3e4a8adfb158be778ab1ec525323c363cd3a","analyzedAt":"2026-08-14T03:33:19.897Z","schemaVersion":2},"datasetVersion":"2026-08-14T05:17:29.042Z"}