invoke-ai/InvokeAI · error · ExternalProviderRequestError

DashScope request failed with status {response.status_code}

Error message

DashScope request failed with status {response.status_code} for model '{model_id}': {response.text}

What it means

In the synchronous DashScope path, the HTTP POST response is checked with response.ok; any non-2xx status (auth failure, invalid params, rate limit, server error) is converted into an ExternalProviderRequestError carrying the status code and the raw response body. It surfaces upstream DashScope API errors to the caller.

Source

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

        if request.seed is not None:
            parameters["seed"] = request.seed

        payload: dict[str, object] = {
            "model": model_id,
            "input": {
                "messages": [
                    {
                        "role": "user",
                        "content": content,
                    }
                ]
            },
            "parameters": parameters,
        }

        response = self._post_with_retry(endpoint, headers=headers, json=payload, timeout=120, label="DashScope sync")
        if not response.ok:
            raise ExternalProviderRequestError(
                f"DashScope request failed with status {response.status_code} for model '{model_id}': {response.text}"
            )

        data = response.json()
        request_id = data.get("request_id")
        return self._parse_sync_response(data, request, request_id)

    def _generate_async(
        self,
        request: ExternalGenerationRequest,
        base_url: str,
        headers: dict[str, str],
        model_id: str,
        size: str,
    ) -> ExternalGenerationResult:
        """Use the async image-generation endpoint (flat prompt format) with task polling."""
        endpoint = f"{base_url}/api/v1/services/aigc/image-generation/generation"
        async_headers = {**headers, "X-DashScope-Async": "enable"}

View on GitHub (pinned to 0b6a024f2f)

Solutions

  1. Read the status code and response text in the message — DashScope's body usually names the exact problem (e.g. InvalidApiKey, throttling)
  2. If 401/403, rotate/update external_alibabacloud_api_key
  3. If 400, validate request.width/height, model id, and parameters against the model's documented constraints
  4. If 429/5xx, retry later; the request already goes through _post_with_retry, so back off longer between attempts
Defensive patterns

Strategy: try-catch

Validate before calling

if not (0 < request.width <= 4096 and 0 < request.height <= 4096):
    raise ValueError("width/height outside DashScope-allowed range")  # plus verify key configured

Type guard

def is_transport_error(e: Exception) -> bool:
    return isinstance(e, ExternalProviderRequestError) and 'DashScope request failed with status' in str(e)

Try / catch

try:
    result = provider.generate(request)
except ExternalProviderRequestError as e:
    if 'status 401' in str(e) or 'status 403' in str(e):
        rotate_api_key()  # auth problem
    elif 'status 429' in str(e):
        schedule_retry(backoff=exponential())  # provider already retries internally; back off longer
    else:
        log.error("DashScope sync failure: %s", e)
        raise

Prevention

When it happens

Trigger: _generate_sync posts to the DashScope sync endpoint and receives a 4xx/5xx response — invalid API key (401), malformed payload or bad model/size params (400), throttling (429), or DashScope server errors (5xx). response.text is included in the message.

Common situations: Expired or revoked DashScope API key; image dimensions outside the model's allowed size set; account out of quota/credit; temporary DashScope outage; payload field mismatch after a DashScope API version change.

Related errors


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