HKUDS/nanobot · error · ImageGenerationError
Gemini Imagen generation failed
Error message
Gemini Imagen generation failed (HTTP {response.status_code}): {detail} What it means
Raised in GeminiImageGenerator._generate_imagen when the POST to {api_base}/models/{model}:predict returns a non-2xx status. Wraps httpx.HTTPStatusError with status code and upstream detail, meaning the Gemini Imagen (predict) endpoint rejected the request — typically an invalid API key, unsupported model, or invalid parameters.
Solutions
- Verify the Gemini/Imagen API key is set and valid (x-goog-api-key header)
- Confirm the model name is a valid Imagen model available to the key
- Check the detail text for quota or parameter errors and adjust prompt/parameters
- Retry after correcting configuration; review extra_body/extra_headers overrides
Defensive patterns
Strategy: try-catch
When it happens
Trigger: Thrown at nanobot/providers/image_generation.py:778 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/69bdc5cc8719b362.
Report an issue: GitHub.
Appendix: source
Thrown at nanobot/providers/image_generation.py:778
"instances": [{"prompt": prompt}],
"parameters": parameters,
}
body.update(self.extra_body)
url = f"{self.api_base}/models/{model}:predict"
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 Imagen generation failed (HTTP {}): {}", response.status_code, detail)
raise ImageGenerationError(
f"Gemini Imagen generation failed (HTTP {response.status_code}): {detail}"
) from exc
data = _as_json_object(response.json()) or {}
images: list[str] = []
for prediction in _as_json_objects(data.get("predictions")):
b64 = prediction.get("bytesBase64Encoded")
mime = prediction.get("mimeType", "image/png")
if isinstance(b64, str) and b64 and isinstance(mime, str):
images.append(f"data:{mime};base64,{b64}")
self._require_images(images, data)
return GeneratedImageResponse(images=images, content="", raw=data)
async def _generate_gemini_flash(
self,
*,View on GitHub (pinned to 42f37dc4c0)