{"record":{"id":"12dde7a1c82cbd41","repo":"invoke-ai/InvokeAI","slug":"dashscope-image-exceeds-download-max-bytes-byte","errorCode":null,"errorMessage":"DashScope image exceeds {_DOWNLOAD_MAX_BYTES} byte cap (Content-Length={content_length})","messagePattern":"DashScope image exceeds (.+?) byte cap \\(Content-Length=(.+?)\\)","errorType":"exception","errorClass":"ExternalProviderRequestError","httpStatus":null,"severity":"error","filePath":"invokeai/app/services/external_generation/providers/alibabacloud.py","lineNumber":307,"sourceCode":"\n    def _download_image(self, url: str) -> PILImageType:\n        \"\"\"Download an image from a URL and return it as a PIL Image, with a size cap.\"\"\"\n        try:\n            response = requests.get(url, timeout=_DOWNLOAD_TIMEOUT, stream=True)\n        except requests.RequestException as exc:\n            raise ExternalProviderRequestError(f\"Failed to download image from DashScope: {exc}\") from exc\n\n        with response:\n            if not response.ok:\n                raise ExternalProviderRequestError(\n                    f\"Failed to download image from DashScope (status {response.status_code})\"\n                )\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,","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/services/external_generation/providers/alibabacloud.py#L289-L325","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Reduce the requested image size/resolution in the generation request","If legitimately needed, raise _DOWNLOAD_MAX_BYTES in alibabacloud.py (a code change, not config)","Verify the response is actually an image and not an oversized error artifact","Check whether the model produces multi-MB outputs by design for your parameters"],"exampleFix":"// before\nparameters[\"size\"] = \"4096*4096\"  # Content-Length > 32MiB\n// after\nparameters[\"size\"] = \"2048*2048\"  # stays under the 32MiB cap","handlingStrategy":"validation","validationCode":"MAX_PIXELS_FOR_32MIB = 4096 * 4096  # rough heuristic\ndef validate_size(width: int, height: int) -> None:\n    if width * height > MAX_PIXELS_FOR_32MIB:\n        raise ValueError(\"requested resolution likely exceeds the 32MiB download cap\")","typeGuard":null,"tryCatchPattern":"try:\n    result = provider.generate(request)\nexcept ExternalProviderRequestError as e:\n    if \"byte cap (Content-Length=\" in str(e):\n        log.error(\"Image too large (%s); reduce requested size\", e)\n    raise","preventionTips":["Keep requested size within resolutions that produce < 32MiB PNGs","Don't blindly increase resolution without checking the download cap","Remember the cap is a compile-time constant, not user-configurable","Validate size parameters before submission"],"tags":["image-download","size-limit","content-length","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"}