{"record":{"id":"1302ca9a9e79ab2a","repo":"Comfy-Org/ComfyUI","slug":"gemini-api-returned-no-response-candidates-if-you","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_gemini.py","lineNumber":173,"sourceCode":"\ndef get_parts_by_type(response: GeminiGenerateContentResponse, part_type: Literal[\"text\"] | str) -> list[GeminiPart]:\n    \"\"\"\n    Filter response parts by their type.\n\n    Args:\n        response: The API response from Gemini.\n        part_type: Type of parts to extract (\"text\" or a MIME type).\n\n    Returns:\n        List of response parts matching the requested type.\n    \"\"\"\n    if not response.candidates:\n        if response.promptFeedback and response.promptFeedback.blockReason:\n            feedback = response.promptFeedback\n            raise ValueError(\n                f\"Gemini API blocked the request. Reason: {feedback.blockReason} ({feedback.blockReasonMessage})\"\n            )\n        raise ValueError(\n            \"Gemini API returned no response candidates. If you are using the `IMAGE` modality, \"\n            \"try changing it to `IMAGE+TEXT` to view the model's reasoning and understand why image generation failed.\"\n        )\n    parts = []\n    blocked_reasons = []\n    for candidate in response.candidates:\n        if candidate.finishReason and candidate.finishReason.upper() == \"IMAGE_PROHIBITED_CONTENT\":\n            blocked_reasons.append(candidate.finishReason)\n            continue\n        if candidate.content is None or candidate.content.parts is None:\n            continue\n        for part in candidate.content.parts:\n            if part_type == \"text\" and part.text:\n                parts.append(part)\n            elif part.inlineData and _mime_matches(part.inlineData.mimeType, part_type):\n                parts.append(part)\n            elif part.fileData and _mime_matches(part.fileData.mimeType, part_type):\n                parts.append(part)","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_gemini.py#L155-L191","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Switch the response modality widget to 'IMAGE+TEXT' and re-run — the returned text usually states why generation failed.","Rephrase the prompt toward concrete visual descriptions.","Confirm the selected model actually supports image output.","Retry once; empty-candidate responses are occasionally transient."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    parts = extract_parts(response, \"image\")\nexcept ValueError as e:\n    if \"no response candidates\" in str(e):\n        # retry once with modality IMAGE+TEXT to capture the model's explanation\n        response = await call_gemini(modality=\"IMAGE+TEXT\")\n        parts = extract_parts(response, \"image\")","preventionTips":["Prefer IMAGE+TEXT modality while iterating; switch to IMAGE only once prompts reliably generate.","Confirm the chosen model variant supports image output."],"tags":["comfyui","gemini","image-generation","empty-response","modality"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}