{"record":{"id":"cdb557bb177b6b77","repo":"invoke-ai/InvokeAI","slug":"dashscope-image-exceeds-download-max-bytes-byte-cdb557","errorCode":null,"errorMessage":"DashScope image exceeds {_DOWNLOAD_MAX_BYTES} byte cap","messagePattern":"DashScope image exceeds (.+?) byte cap","errorType":"exception","errorClass":"ExternalProviderRequestError","httpStatus":null,"severity":"error","filePath":"invokeai/app/services/external_generation/providers/alibabacloud.py","lineNumber":319,"sourceCode":"                )\n\n            content_length = response.headers.get(\"Content-Length\")\n            if content_length is not None:\n                try:\n                    if int(content_length) > _DOWNLOAD_MAX_BYTES:\n                        raise ExternalProviderRequestError(\n                            f\"DashScope image exceeds {_DOWNLOAD_MAX_BYTES} byte cap (Content-Length={content_length})\"\n                        )\n                except ValueError:\n                    pass\n\n            buffer = bytearray()\n            for chunk in response.iter_content(chunk_size=64 * 1024):\n                if not chunk:\n                    continue\n                buffer.extend(chunk)\n                if len(buffer) > _DOWNLOAD_MAX_BYTES:\n                    raise ExternalProviderRequestError(f\"DashScope image exceeds {_DOWNLOAD_MAX_BYTES} byte cap\")\n\n        return Image.open(io.BytesIO(bytes(buffer))).convert(\"RGB\")\n\n    def _post_with_retry(\n        self,\n        url: str,\n        *,\n        headers: dict[str, str],\n        json: dict,\n        timeout: int,\n        label: str,\n    ) -> requests.Response:\n        return self._request_with_retry(\"POST\", url, headers=headers, json=json, timeout=timeout, label=label)\n\n    def _get_with_retry(\n        self,\n        url: str,\n        *,","sourceCodeStart":301,"sourceCodeEnd":337,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/services/external_generation/providers/alibabacloud.py#L301-L337","documentation":"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.","triggerScenarios":"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.","commonSituations":"CDN serving chunked responses; model configured for extremely large output; proxy that strips Content-Length; unexpected HTML/JSON error stream from a gateway.","solutions":["Reduce the requested image resolution/size so the payload fits under 32 MiB","Raise _DOWNLOAD_MAX_BYTES in alibabacloud.py if larger images are genuinely required","Confirm the URL actually serves an image (curl -I) — a gateway error stream may be the real cause","Check for proxies rewriting transfer encoding (removing Content-Length) between the app and the CDN"],"exampleFix":"// before\n_DOWNLOAD_MAX_BYTES = 32 * 1024 * 1024\n// after\n_DOWNLOAD_MAX_BYTES = 64 * 1024 * 1024  # only if your storage can handle it","handlingStrategy":"validation","validationCode":"def validate_size(width: int, height: int) -> None:\n    if width * height > 4096 * 4096:\n        raise ValueError(\"requested resolution likely exceeds the 32MiB streaming cap\")","typeGuard":null,"tryCatchPattern":"try:\n    result = provider.generate(request)\nexcept ExternalProviderRequestError as e:\n    if str(e).endswith(\"byte cap\"):\n        log.error(\"Streamed image exceeded 32MiB (no/fake Content-Length); reduce size or raise cap\")\n    raise","preventionTips":["Limit requested resolution so streamed bodies stay under 32MiB","If behind a proxy, ensure Content-Length is preserved so the pre-check fires first","Raise _DOWNLOAD_MAX_BYTES only if downstream storage/parsers support larger images","Verify with curl -I that the URL serves an image, not an oversized error stream"],"tags":["image-download","size-limit","streaming","safety-cap"],"backgroundTag":"response-size-limit-exceeded","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}