{"record":{"id":"e24ef4a623801341","repo":"Comfy-Org/ComfyUI","slug":"gemini-did-not-generate-an-image-model-response","errorCode":null,"errorMessage":"Gemini did not generate an image. Model response: {model_message}","messagePattern":"Gemini did not generate an image\\. Model response: (.+?)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_gemini.py","lineNumber":230,"sourceCode":"\nasync def get_image_from_response(response: GeminiGenerateContentResponse, thought: bool = False) -> Input.Image:\n    image_tensors: list[Input.Image] = []\n    parts = get_parts_by_type(response, \"image/*\")\n    for part in parts:\n        if (part.thought is True) != thought:\n            continue\n        if part.inlineData:\n            image_data = base64.b64decode(part.inlineData.data)\n            returned_image = bytesio_to_image_tensor(BytesIO(image_data))\n        else:\n            returned_image = await download_url_to_image_tensor(part.fileData.fileUri)\n        image_tensors.append(returned_image)\n    if len(image_tensors) == 0:\n        if not thought:\n            # No images generated --> extract text response for a meaningful error\n            model_message = get_text_from_response(response).strip()\n            if model_message:\n                raise ValueError(f\"Gemini did not generate an image. Model response: {model_message}\")\n            raise ValueError(\n                \"Gemini did not generate an image. \"\n                \"Try rephrasing your prompt or changing the response modality to 'IMAGE+TEXT' \"\n                \"to see the model's reasoning.\"\n            )\n        return torch.zeros((1, 1024, 1024, 4))\n    return torch.cat(image_tensors, dim=0)\n\n\ndef get_text_from_interaction(interaction: GeminiInteraction) -> str:\n    \"\"\"Extract and concatenate all model output text from an Interactions API response.\"\"\"\n    texts = []\n    for step in interaction.steps or []:\n        if step.type != \"model_output\":\n            continue\n        for content in step.content or []:\n            if content.type == \"text\" and content.text:\n                texts.append(content.text)","sourceCodeStart":212,"sourceCodeEnd":248,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_gemini.py#L212-L248","documentation":"Raised by the Gemini image extractor when the response contained candidates and parts but zero usable images, and the model's text channel contains an explanation. The node extracts the text via get_text_from_response and embeds it, so the error doubles as the model's own refusal/failure reason. This is the 'model answered with words instead of an image' path for non-thought requests.","triggerScenarios":"image_tensors is empty after iterating parts, thought is falsy, and get_text_from_response(response).strip() is non-empty — e.g. the model replied 'I can't generate that' as text in an image request.","commonSituations":"Prompt phrased as a question so the model answers instead of drawing; model declining the subject; modality mismatch where text was requested but images extracted; edge cases where the model returns inline text alongside no inlineData/fileData parts.","solutions":["Read the embedded model message — it is the model's stated reason for not producing an image.","Rewrite the prompt as an image-generation instruction ('Generate an image of ...') rather than a question or conversation.","Remove disallowed subjects if the message indicates a policy refusal.","Verify the response modality includes IMAGE if you expect image output."],"exampleFix":"// before: prompt = \"Can you draw a cat?\" (expecting an image)\n// after:  prompt = \"Generate an image of a cat sitting on a windowsill.\"","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    images = get_images_from_response(response)\nexcept ValueError as e:\n    if \"did not generate an image\" in str(e):\n        # error text contains the model's own explanation; log it for the user\n        log.warning(\"Gemini image generation failed: %s\", e)\n        raise","preventionTips":["Phrase image requests as generation instructions, not questions.","Read the embedded model message — it states the actual refusal reason.","Ensure the response modality includes IMAGE when image output is expected."],"tags":["comfyui","gemini","image-generation","empty-response","prompt-format"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}