Comfy-Org/ComfyUI · error · ValueError
Gemini did not generate an image. Try rephrasing your prompt
Error message
Gemini did not generate an image. Try rephrasing your prompt or changing the response modality to 'IMAGE+TEXT' to see the model's reasoning.
What it means
Raised by the Gemini image generation node when the API response contains zero image parts (no inlineData and no fileData across all candidates) and the model also returned no text. This means Gemini accepted the request but declined or failed to produce any image payload, typically due to safety filtering or a prompt it could not interpret as an image request. The error explicitly suggests switching the response modality to 'IMAGE+TEXT' so the model's reasoning becomes visible in the text output.
Source
Thrown at comfy_api_nodes/nodes_gemini.py:231
async def get_image_from_response(response: GeminiGenerateContentResponse, thought: bool = False) -> Input.Image:
image_tensors: list[Input.Image] = []
parts = get_parts_by_type(response, "image/*")
for part in parts:
if (part.thought is True) != thought:
continue
if part.inlineData:
image_data = base64.b64decode(part.inlineData.data)
returned_image = bytesio_to_image_tensor(BytesIO(image_data))
else:
returned_image = await download_url_to_image_tensor(part.fileData.fileUri)
image_tensors.append(returned_image)
if len(image_tensors) == 0:
if not thought:
# No images generated --> extract text response for a meaningful error
model_message = get_text_from_response(response).strip()
if model_message:
raise ValueError(f"Gemini did not generate an image. Model response: {model_message}")
raise ValueError(
"Gemini did not generate an image. "
"Try rephrasing your prompt or changing the response modality to 'IMAGE+TEXT' "
"to see the model's reasoning."
)
return torch.zeros((1, 1024, 1024, 4))
return torch.cat(image_tensors, dim=0)
def get_text_from_interaction(interaction: GeminiInteraction) -> str:
"""Extract and concatenate all model output text from an Interactions API response."""
texts = []
for step in interaction.steps or []:
if step.type != "model_output":
continue
for content in step.content or []:
if content.type == "text" and content.text:
texts.append(content.text)
return "\n".join(texts)View on GitHub (pinned to 1c6d8d45b3)
Solutions
- Change the response modality from 'IMAGE' to 'IMAGE+TEXT' and rerun — the text output will usually state why no image was produced.
- Rephrase the prompt to be an explicit image-generation instruction and remove terms likely to trip safety filters.
- Retry the same prompt; transient refusals with empty responses often succeed on a second attempt.
- If a text explanation is returned instead (different branch), follow that model_message guidance.
Example fix
// before
resp = await api_generate_image(prompt, modality="IMAGE")
image = images_from_response(resp) # raises: Gemini did not generate an image...
// after
resp = await api_generate_image(prompt, modality="IMAGE+TEXT")
if not resp_has_image_parts(resp):
raise RuntimeError(f"no image; model said: {get_text_from_response(resp)}")
image = images_from_response(resp) Defensive patterns
Strategy: try-catch
Try / catch
try:
images = await gemini_image_generate(prompt, modality="IMAGE")
except ValueError as e:
if "did not generate an image" in str(e):
retry_with_text = await gemini_image_generate(prompt, modality="IMAGE+TEXT")
# inspect text output for refusal reason; surface to user
else:
raise Prevention
- Default the modality to IMAGE+TEXT during development so refusals return readable reasons.
- Avoid prompt terms known to trip image safety filters in production modality=IMAGE workflows.
- Wrap generation in a single retry with a rephrased prompt before surfacing failure to the user.
When it happens
Trigger: Calling a Gemini image node (e.g. GeminiImageGenerator image-only path) where the response has no inlineData/fileData parts, get_number_of_images-producing batches come back empty, and get_text_from_response(response).strip() is empty. Typical with response modality set to IMAGE only while the prompt triggers a safety refusal, or when the model answers with thought tokens but no visible output.
Common situations: Prompts with person/celebrity/copyright-adjacent content that Gemini's safety filters refuse; requests that the model interprets as a text question rather than an image request; intermittent provider-side refusals that return nothing on retry; using modality IMAGE where the model wants to explain why it refused.
Related errors
- The current maximum number of supported images is 14.
- Gemini API returned no response candidates. If you are using
- Gemini API blocked the request. Reasons: {blocked_reasons}
- Gemini did not generate an image. Model response: {model_mes
- Gemini did not generate a video. Model response: {model_mess
AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14).
Data as JSON: /api/errors/f5d5e52fb55faa59.
Report an issue: GitHub.