invoke-ai/InvokeAI · error · ExternalProviderRequestError

DashScope image exceeds {_DOWNLOAD_MAX_BYTES} byte cap (Cont

Error message

DashScope image exceeds {_DOWNLOAD_MAX_BYTES} byte cap (Content-Length={content_length})

What it means

Before streaming the body, _download_image inspects the Content-Length header and aborts with ExternalProviderRequestError if it already exceeds _DOWNLOAD_MAX_BYTES (32 MiB). This is a deliberate safety cap to prevent a huge response from exhausting memory/disk.

Source

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

    def _download_image(self, url: str) -> PILImageType:
        """Download an image from a URL and return it as a PIL Image, with a size cap."""
        try:
            response = requests.get(url, timeout=_DOWNLOAD_TIMEOUT, stream=True)
        except requests.RequestException as exc:
            raise ExternalProviderRequestError(f"Failed to download image from DashScope: {exc}") from exc

        with response:
            if not response.ok:
                raise ExternalProviderRequestError(
                    f"Failed to download image from DashScope (status {response.status_code})"
                )

            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,

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Reduce the requested image size/resolution in the generation request
  2. If legitimately needed, raise _DOWNLOAD_MAX_BYTES in alibabacloud.py (a code change, not config)
  3. Verify the response is actually an image and not an oversized error artifact
  4. Check whether the model produces multi-MB outputs by design for your parameters

Example fix

// before
parameters["size"] = "4096*4096"  # Content-Length > 32MiB
// after
parameters["size"] = "2048*2048"  # stays under the 32MiB cap
Defensive patterns

Strategy: validation

Validate before calling

MAX_PIXELS_FOR_32MIB = 4096 * 4096  # rough heuristic
def validate_size(width: int, height: int) -> None:
    if width * height > MAX_PIXELS_FOR_32MIB:
        raise ValueError("requested resolution likely exceeds the 32MiB download cap")

Try / catch

try:
    result = provider.generate(request)
except ExternalProviderRequestError as e:
    if "byte cap (Content-Length=" in str(e):
        log.error("Image too large (%s); reduce requested size", e)
    raise

Prevention

When it happens

Trigger: DashScope returns an image whose declared Content-Length exceeds 32 MiB — e.g. very large resolution requests (size parameter), or an unexpected non-image payload with a large body.

Common situations: Requesting extremely large sizes via the size parameter for qwen/wan models; a misbehaving endpoint returning huge payloads; raising resolution without realizing the 32 MiB download cap exists.

Related errors


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