invoke-ai/InvokeAI · error · ExternalProviderRequestError
Failed to download image from DashScope: {exc}
Error message
Failed to download image from DashScope: {exc} What it means
_download_image fetches generated image URLs with requests.get(stream=True). Any requests.RequestException (DNS failure, connection reset, TLS error, timeout after _DOWNLOAD_TIMEOUT=60s) is wrapped and re-raised as ExternalProviderRequestError with the underlying exception text.
Source
Thrown at invokeai/app/services/external_generation/providers/alibabacloud.py:295
pil_image = decode_image_base64(b64_image)
images.append(ExternalGeneratedImage(image=pil_image, seed=request.seed))
if not images:
raise ExternalProviderRequestError(f"DashScope async response contained no images: {output}")
return ExternalGenerationResult(
images=images,
seed_used=request.seed,
provider_request_id=request_id,
provider_metadata={"model": request.model.provider_model_id},
)
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()View on GitHub (pinned to 0b6a024f2f)
Solutions
- Retry the generation — the provider does not retry image downloads, only API calls
- Check egress/firewall rules so the app host can reach the DashScope CDN hosts
- Download promptly after generation; expired signed URLs cause connection/HTTP failures
- Verify DNS and proxy settings (HTTP_PROXY/HTTPS_PROXY) in the deployment environment
- Test the failing URL with curl from the same host to isolate network vs code issues
Example fix
// before
response = requests.get(url, timeout=_DOWNLOAD_TIMEOUT, stream=True)
// after
for attempt in range(3):
try:
response = requests.get(url, timeout=_DOWNLOAD_TIMEOUT, stream=True)
break
except requests.RequestException:
if attempt == 2:
raise
time.sleep(2 ** attempt) Defensive patterns
Strategy: retry
Validate before calling
import socket, requests
def can_reach_host(url: str) -> bool:
try:
host = requests.utils.urlparse(url).hostname
socket.getaddrinfo(host, 443)
return True
except (socket.gaierror, ValueError):
return False Try / catch
try:
result = provider.generate(request)
except ExternalProviderRequestError as e:
if "Failed to download image from DashScope:" in str(e):
log.warning("Transient image-download failure, retrying: %s", e)
result = provider.generate(request)
else:
raise Prevention
- Consume and download results immediately after generation before URLs expire
- Open egress to DashScope CDN hosts from your deployment
- Set correct HTTP_PROXY/HTTPS_PROXY/NO_PROXY in containers
- Add a short retry with backoff around generate() for network flakiness
When it happens
Trigger: The image host is unreachable; the returned image URL has expired (DashScope URLs are time-limited); DNS/proxy issues in the deployment environment; network outage mid-generation; TLS interception by corporate proxies.
Common situations: Delaying image download until after DashScope's signed URL TTL expires (typically ~24h, but can be shorter); air-gapped/egress-restricted clusters where the app host cannot reach the CDN host; flaky container networking.
Related errors
- {label} network error: {exc}
- {reason}
- Failed to download image from DashScope (status {response.st
- {label} failed after retries: {last_exc}
- Timeout exceeded
AI-assisted analysis of invoke-ai/InvokeAI@0b6a024f2f (2026-08-29).
Data as JSON: /api/errors/114116f4fab92c9d.
Report an issue: GitHub.