Comfy-Org/ComfyUI · error · ValueError

Gemini API returned no response candidates. If you are using

Error message

Gemini API returned no response candidates. If you are using the `IMAGE` modality, try changing it to `IMAGE+TEXT` to view the model's reasoning and understand why image generation failed.

What it means

Raised when a Gemini response has no candidates and no promptFeedback.blockReason — the model simply returned nothing structured. The message specifically hints that image-generation requests using the IMAGE-only modality often fail this way, and switching to IMAGE+TEXT exposes the model's own explanation in the text channel.

Source

Thrown at comfy_api_nodes/nodes_gemini.py:173

def get_parts_by_type(response: GeminiGenerateContentResponse, part_type: Literal["text"] | str) -> list[GeminiPart]:
    """
    Filter response parts by their type.

    Args:
        response: The API response from Gemini.
        part_type: Type of parts to extract ("text" or a MIME type).

    Returns:
        List of response parts matching the requested type.
    """
    if not response.candidates:
        if response.promptFeedback and response.promptFeedback.blockReason:
            feedback = response.promptFeedback
            raise ValueError(
                f"Gemini API blocked the request. Reason: {feedback.blockReason} ({feedback.blockReasonMessage})"
            )
        raise ValueError(
            "Gemini API returned no response candidates. If you are using the `IMAGE` modality, "
            "try changing it to `IMAGE+TEXT` to view the model's reasoning and understand why image generation failed."
        )
    parts = []
    blocked_reasons = []
    for candidate in response.candidates:
        if candidate.finishReason and candidate.finishReason.upper() == "IMAGE_PROHIBITED_CONTENT":
            blocked_reasons.append(candidate.finishReason)
            continue
        if candidate.content is None or candidate.content.parts is None:
            continue
        for part in candidate.content.parts:
            if part_type == "text" and part.text:
                parts.append(part)
            elif part.inlineData and _mime_matches(part.inlineData.mimeType, part_type):
                parts.append(part)
            elif part.fileData and _mime_matches(part.fileData.mimeType, part_type):
                parts.append(part)

View on GitHub (pinned to 1c6d8d45b3)

Solutions

  1. Switch the response modality widget to 'IMAGE+TEXT' and re-run — the returned text usually states why generation failed.
  2. Rephrase the prompt toward concrete visual descriptions.
  3. Confirm the selected model actually supports image output.
  4. Retry once; empty-candidate responses are occasionally transient.
Defensive patterns

Strategy: fallback

Try / catch

try:
    parts = extract_parts(response, "image")
except ValueError as e:
    if "no response candidates" in str(e):
        # retry once with modality IMAGE+TEXT to capture the model's explanation
        response = await call_gemini(modality="IMAGE+TEXT")
        parts = extract_parts(response, "image")

Prevention

When it happens

Trigger: Gemini API returns candidates=[] with no blockReason — commonly image-generation requests where the model declined to emit an image and, in IMAGE-only mode, had no text channel to explain why.

Common situations: Using an image-generation Gemini model with response modality set to IMAGE; prompts the model can't render (excessive text, disallowed subjects); transient API behavior; model variants that only emit text.

Related errors


AI-assisted analysis of Comfy-Org/ComfyUI@1c6d8d45b3 (2026-08-14). Data as JSON: /api/errors/1302ca9a9e79ab2a. Report an issue: GitHub.