{"record":{"id":"176102399311a533","repo":"binary-husky/gpt_academic","slug":"no-image-url-found-in-the-response","errorCode":null,"errorMessage":"No image URL found in the response.","messagePattern":"No image URL found in the response\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"crazy_functions/Image_Generate.py","lineNumber":259,"sourceCode":"        response = requests.post(url, headers=headers, json=payload)\n        result = response.json()\n        image_url = None\n        generated_content = \"\"\n        if result.get(\"choices\"):\n            message = result[\"choices\"][0][\"message\"]\n            if message.get(\"images\"):\n                generated_content = message.get('reasoning', \"\") + message.get('content', \"\")\n                for image in message[\"images\"]:\n                    image_url = image[\"image_url\"][\"url\"]\n                    print(f\"Generated image: {image_url[:50]}...\")\n\n\n        if response.status_code != 200:\n            yield from update_ui_latest_msg(lastmsg=f\"Generate Failed\\n\\n{generated_content}\\n\\nStatus Code: {response.status_code}\", chatbot=chatbot, history=history, delay=0)\n            return\n\n        if image_url is None:\n            raise RuntimeError(\"No image URL found in the response.\")\n\n        logger.info(f'Generated image.')\n        yield from update_ui_latest_msg(lastmsg=f\"Downloading image\", chatbot=chatbot, history=history, delay=0)\n\n        if ';base64,' in image_url:\n            base64_string = image_url.split('base64,')[-1]\n            image_data = base64.b64decode(base64_string)\n            file_path = f'{get_log_folder()}/image_gen/'\n            os.makedirs(file_path, exist_ok=True)\n            file_name = 'Image' + time.strftime(\"%Y-%m-%d-%H-%M-%S\", time.localtime()) + '.png'\n            fp = file_path+file_name\n            with open(fp, 'wb+') as f: f.write(image_data)\n        else:\n            raise ValueError(\"Invalid image URL format.\")\n\n        return image_url, fp\n\n    except Exception as e:","sourceCodeStart":241,"sourceCodeEnd":277,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/crazy_functions/Image_Generate.py#L241-L277","documentation":"After a 200 response from the NanoBanana-compatible endpoint, gen_image_banana() only sets image_url when it finds choices[0].message.images[].image_url.url. This RuntimeError means the HTTP call succeeded but the response contained no image URL. It is immediately caught by the surrounding except and usually re-raised as error 9.","triggerScenarios":"The model returns text only, a safety filter refuses the prompt, the response has no choices, message.images is absent or empty, or the provider uses a different response schema.","commonSituations":"The relay/model named google/gemini-3-pro-image-preview is not actually enabled for image output; GEMINI_API_KEY/GEMINI_BASE_URL or ONE_API key lacks image access; prompt is blocked; quota is exhausted; a provider returns an OpenAI chat schema without the images extension.","solutions":["Log response.status_code and the complete response JSON for the failing request.","Confirm the configured base URL, API key, and model actually support image generation and the modalities field.","Inspect generated_content for safety/refusal text and rewrite the prompt if needed.","Switch to a supported NanoBanana/Gemini image model or provider.","Add an explicit schema check that reports the missing field instead of a generic no-URL error."],"exampleFix":"# before\nif image_url is None:\n    raise RuntimeError(\"No image URL found in the response.\")\n\n# after\nif image_url is None:\n    raise RuntimeError(\n        \"No image URL found in the response. \"\n        f\"Status={response.status_code}, content={generated_content!r}, payload={result!r}\"\n    )\n","handlingStrategy":"validation","validationCode":"payload = {\n    \"model\": expected_image_model,\n    \"modalities\": [\"image\", \"text\"],\n    ...\n}\nassert \"image\" in payload[\"modalities\"]\nassert api_key and base_url.startswith((\"http://\", \"https://\"))\n","typeGuard":"def has_banana_image_url(result) -> bool:\n    try:\n        images = result[\"choices\"][0][\"message\"][\"images\"]\n        return bool(images) and isinstance(images[0][\"image_url\"][\"url\"], str) and bool(images[0][\"image_url\"][\"url\"])\n    except (KeyError, IndexError, TypeError):\n        return False\n","tryCatchPattern":"try:\n    yield from gen_image_banana(...)\nexcept RuntimeError as e:\n    if \"No image URL\" in str(e):\n        log_banana_payload_and_prompt()\n    raise\n","preventionTips":["Use an endpoint and model actually enabled for image output.","Inspect both text content and image fields in responses.","Avoid prompts likely to trigger safety refusals.","Keep the provider's documented schema in parser tests."],"tags":["image-generation","gemini","api-response","schema"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}