HKUDS/nanobot · error · ImageGenerationError
Gemini image generation failed
Error message
Gemini image generation failed (HTTP {response.status_code}): {detail} What it means
Raised in GeminiImageGenerator._generate_gemini_flash when the POST to {api_base}/models/{model}:generateContent returns a non-2xx status. Wraps httpx.HTTPStatusError with status code and detail, meaning the Gemini generateContent endpoint rejected the image-generation request (auth, model, quota, or safety-block issues).
Solutions
- Verify the Gemini API key and model name are correct
- Check the detail for safety-block or quota reasons and adjust the prompt
- Confirm network/proxy access to the Gemini endpoint
- Retry after fixing configuration or prompt
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at nanobot/providers/image_generation.py:837 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of HKUDS/nanobot@42f37dc4c0 (2026-08-26).
Data as JSON: /api/errors/aae637fdc9f8d2ae.
Report an issue: GitHub.
Appendix: source
Thrown at nanobot/providers/image_generation.py:837
"contents": [{"role": "user", "parts": parts}],
"generationConfig": generation_config,
}
body.update(self.extra_body)
url = f"{self.api_base}/models/{model}:generateContent"
headers = {
"x-goog-api-key": self.api_key or "",
"Content-Type": "application/json",
**self.extra_headers,
}
response = await self._http_post(url, headers=headers, body=body)
try:
response.raise_for_status()
except httpx.HTTPStatusError as exc:
detail = _http_error_detail(response)
logger.error("Gemini image generation failed (HTTP {}): {}", response.status_code, detail)
raise ImageGenerationError(
f"Gemini image generation failed (HTTP {response.status_code}): {detail}"
) from exc
data = _as_json_object(response.json()) or {}
images: list[str] = []
text_parts: list[str] = []
for candidate in _as_json_objects(data.get("candidates")):
content = _as_json_object(candidate.get("content")) or {}
for part in _as_json_objects(content.get("parts")):
if "text" in part:
text = part["text"]
if isinstance(text, str):
text_parts.append(text)
inline = _as_json_object(part.get("inlineData"))
if inline is not None:
mime = inline.get("mimeType", "image/png")
b64 = inline.get("data", "")
if isinstance(mime, str) and isinstance(b64, str) and b64:View on GitHub (pinned to 42f37dc4c0)