{"record":{"id":"6330af936c13b679","repo":"invoke-ai/InvokeAI","slug":"dashscope-request-failed-with-status-response-sta","errorCode":null,"errorMessage":"DashScope request failed with status {response.status_code} for model '{model_id}': {response.text}","messagePattern":"DashScope request failed with status (.+?) for model '(.+?)': (.+?)","errorType":"exception","errorClass":"ExternalProviderRequestError","httpStatus":null,"severity":"error","filePath":"invokeai/app/services/external_generation/providers/alibabacloud.py","lineNumber":115,"sourceCode":"        if request.seed is not None:\n            parameters[\"seed\"] = request.seed\n\n        payload: dict[str, object] = {\n            \"model\": model_id,\n            \"input\": {\n                \"messages\": [\n                    {\n                        \"role\": \"user\",\n                        \"content\": content,\n                    }\n                ]\n            },\n            \"parameters\": parameters,\n        }\n\n        response = self._post_with_retry(endpoint, headers=headers, json=payload, timeout=120, label=\"DashScope sync\")\n        if not response.ok:\n            raise ExternalProviderRequestError(\n                f\"DashScope request failed with status {response.status_code} for model '{model_id}': {response.text}\"\n            )\n\n        data = response.json()\n        request_id = data.get(\"request_id\")\n        return self._parse_sync_response(data, request, request_id)\n\n    def _generate_async(\n        self,\n        request: ExternalGenerationRequest,\n        base_url: str,\n        headers: dict[str, str],\n        model_id: str,\n        size: str,\n    ) -> ExternalGenerationResult:\n        \"\"\"Use the async image-generation endpoint (flat prompt format) with task polling.\"\"\"\n        endpoint = f\"{base_url}/api/v1/services/aigc/image-generation/generation\"\n        async_headers = {**headers, \"X-DashScope-Async\": \"enable\"}","sourceCodeStart":97,"sourceCodeEnd":133,"githubUrl":"https://github.com/invoke-ai/InvokeAI/blob/0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06/invokeai/app/services/external_generation/providers/alibabacloud.py#L97-L133","documentation":"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.","triggerScenarios":"_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.","commonSituations":"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.","solutions":["Read the status code and response text in the message — DashScope's body usually names the exact problem (e.g. InvalidApiKey, throttling)","If 401/403, rotate/update external_alibabacloud_api_key","If 400, validate request.width/height, model id, and parameters against the model's documented constraints","If 429/5xx, retry later; the request already goes through _post_with_retry, so back off longer between attempts"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"if not (0 < request.width <= 4096 and 0 < request.height <= 4096):\n    raise ValueError(\"width/height outside DashScope-allowed range\")  # plus verify key configured","typeGuard":"def is_transport_error(e: Exception) -> bool:\n    return isinstance(e, ExternalProviderRequestError) and 'DashScope request failed with status' in str(e)","tryCatchPattern":"try:\n    result = provider.generate(request)\nexcept ExternalProviderRequestError as e:\n    if 'status 401' in str(e) or 'status 403' in str(e):\n        rotate_api_key()  # auth problem\n    elif 'status 429' in str(e):\n        schedule_retry(backoff=exponential())  # provider already retries internally; back off longer\n    else:\n        log.error(\"DashScope sync failure: %s\", e)\n        raise","preventionTips":["Keep the DashScope key valid and rotated before expiry","Validate sizes/parameters against model docs before calling","Respect rate limits; don't bypass the built-in retry with tight loops","Log response bodies (already embedded in the message) for diagnosis"],"tags":["network","http-error","dashscope","alibabacloud","api-response"],"backgroundTag":"http-4xx-error","analyzedSha":"0b6a024f2ff6a86bfb953dcdb9cc504ef7397a06","analyzedAt":"2026-08-29T04:46:49.967Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}