HKUDS/nanobot · error · ImageGenerationError
generated image payload was not a supported image
Error message
generated image payload was not a supported image
What it means
Guard in _b64_image_data_url: the payload decoded successfully but its magic bytes do not match any supported image type. The provider returned data that is valid base64 yet not a recognizable PNG/JPEG/WebP image — another untrusted-response validation.
Solutions
- Retry generation; the provider may have emitted an error page or placeholder encoded as base64
- Inspect the provider's raw response to see what was actually returned
- Switch models/providers if this provider persistently returns non-image payloads
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at nanobot/providers/image_generation.py:127 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/d600f781bf837756.
Report an issue: GitHub.
Appendix: source
Thrown at nanobot/providers/image_generation.py:127
mime, encoded = _read_image_b64(path)
return f"data:{mime};base64,{encoded}"
def image_path_to_inline_data(path: str | Path) -> dict[str, str]:
"""Convert a local image path to a Gemini ``inlineData`` payload dict."""
mime, encoded = _read_image_b64(path)
return {"mimeType": mime, "data": encoded}
def _b64_image_data_url(value: str) -> str:
encoded = "".join(value.split())
try:
raw = base64.b64decode(encoded, validate=True)
except binascii.Error as exc:
raise ImageGenerationError("generated image payload was not valid base64") from exc
mime = detect_image_mime(raw)
if mime is None:
raise ImageGenerationError("generated image payload was not a supported image")
return f"data:{mime};base64,{encoded}"
def _aihubmix_size(aspect_ratio: str | None, image_size: str | None) -> str:
"""Return an OpenAI Images API size string for AIHubMix.
The WebUI emits compact size hints like ``1K`` for OpenRouter. AIHubMix's
Images API expects OpenAI-style dimensions or ``auto``, so only pass
through explicit dimension strings and otherwise derive the closest
supported orientation from aspect ratio.
"""
if image_size and "x" in image_size.lower():
return image_size
if aspect_ratio in _AIHUBMIX_ASPECT_RATIO_SIZES:
return _AIHUBMIX_ASPECT_RATIO_SIZES[aspect_ratio]
return "auto"
View on GitHub (pinned to 42f37dc4c0)