HKUDS/nanobot · error · ImageGenerationError

generated image URL exceeded the redirect limit

Error message

generated image URL exceeded the redirect limit

What it means

Loop-exhaustion guard in _download_image_data_url: the for/else fired because the manual redirect chain exceeded _IMAGE_DOWNLOAD_MAX_REDIRECTS without reaching a final response. Indicates a redirect loop or an abnormally long redirect chain from the image host.

Solutions

  1. Retry generation to obtain a fresh URL
  2. If a provider proxy is configured, verify it isn't injecting extra redirects
  3. Use a different provider if its CDN loops redirects
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at nanobot/providers/image_generation.py:224 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/7df8faccec283bcf. Report an issue: GitHub.

Appendix: source

Thrown at nanobot/providers/image_generation.py:224

                                raise ImageGenerationError(
                                    "generated image exceeded the 32 MiB download limit"
                                )
                        except ValueError:
                            pass

                    chunks: list[bytes] = []
                    total = 0
                    async for chunk in response.aiter_bytes():
                        total += len(chunk)
                        if total > _IMAGE_DOWNLOAD_MAX_BYTES:
                            raise ImageGenerationError(
                                "generated image exceeded the 32 MiB download limit"
                            )
                        chunks.append(chunk)
                    raw = b"".join(chunks)
                    break
            else:
                raise ImageGenerationError("generated image URL exceeded the redirect limit")
    except UnsafeURLRequestError as exc:
        raise ImageGenerationError(f"blocked unsafe generated image URL: {exc}") from exc
    except httpx.RequestError as exc:
        raise ImageGenerationError(f"failed to download generated image: {exc}") from exc

    mime = detect_image_mime(raw)
    if mime is None:
        raise ImageGenerationError("generated image URL did not return a supported image")
    encoded = base64.b64encode(raw).decode("ascii")
    return f"data:{mime};base64,{encoded}"


# ---------------------------------------------------------------------------
# Registry
# ---------------------------------------------------------------------------

_IMAGE_GEN_PROVIDERS: dict[str, type[ImageGenerationProvider]] = {}

View on GitHub (pinned to 42f37dc4c0)