invoke-ai/InvokeAI · error · ExternalProviderRequestError

DashScope image exceeds {_DOWNLOAD_MAX_BYTES} byte cap

Error message

DashScope image exceeds {_DOWNLOAD_MAX_BYTES} byte cap

What it means

While streaming the body in 64 KiB chunks, _download_image aborts once the accumulated bytes exceed _DOWNLOAD_MAX_BYTES (32 MiB). This catches cases where Content-Length was absent, chunked, or lied, and the actual transfer exceeds the safety cap.

Source

Thrown at invokeai/app/services/external_generation/providers/alibabacloud.py:319

                )

            content_length = response.headers.get("Content-Length")
            if content_length is not None:
                try:
                    if int(content_length) > _DOWNLOAD_MAX_BYTES:
                        raise ExternalProviderRequestError(
                            f"DashScope image exceeds {_DOWNLOAD_MAX_BYTES} byte cap (Content-Length={content_length})"
                        )
                except ValueError:
                    pass

            buffer = bytearray()
            for chunk in response.iter_content(chunk_size=64 * 1024):
                if not chunk:
                    continue
                buffer.extend(chunk)
                if len(buffer) > _DOWNLOAD_MAX_BYTES:
                    raise ExternalProviderRequestError(f"DashScope image exceeds {_DOWNLOAD_MAX_BYTES} byte cap")

        return Image.open(io.BytesIO(bytes(buffer))).convert("RGB")

    def _post_with_retry(
        self,
        url: str,
        *,
        headers: dict[str, str],
        json: dict,
        timeout: int,
        label: str,
    ) -> requests.Response:
        return self._request_with_retry("POST", url, headers=headers, json=json, timeout=timeout, label=label)

    def _get_with_retry(
        self,
        url: str,
        *,

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Reduce the requested image resolution/size so the payload fits under 32 MiB
  2. Raise _DOWNLOAD_MAX_BYTES in alibabacloud.py if larger images are genuinely required
  3. Confirm the URL actually serves an image (curl -I) — a gateway error stream may be the real cause
  4. Check for proxies rewriting transfer encoding (removing Content-Length) between the app and the CDN

Example fix

// before
_DOWNLOAD_MAX_BYTES = 32 * 1024 * 1024
// after
_DOWNLOAD_MAX_BYTES = 64 * 1024 * 1024  # only if your storage can handle it
Defensive patterns

Strategy: validation

Validate before calling

def validate_size(width: int, height: int) -> None:
    if width * height > 4096 * 4096:
        raise ValueError("requested resolution likely exceeds the 32MiB streaming cap")

Try / catch

try:
    result = provider.generate(request)
except ExternalProviderRequestError as e:
    if str(e).endswith("byte cap"):
        log.error("Streamed image exceeded 32MiB (no/fake Content-Length); reduce size or raise cap")
    raise

Prevention

When it happens

Trigger: Response has no Content-Length (chunked transfer) and streams more than 32 MiB; Content-Length header mismatches the actual body; a non-image stream (e.g. endless error page) exceeding the cap.

Common situations: CDN serving chunked responses; model configured for extremely large output; proxy that strips Content-Length; unexpected HTML/JSON error stream from a gateway.

Related errors


AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29). Data as JSON: /api/errors/cdb557bb177b6b77. Report an issue: GitHub.