{"record":{"id":"5bbac32f6511f920","repo":"calesthio/OpenMontage","slug":"dashscope-api-error-http-http-status-code-cod","errorCode":null,"errorMessage":"DashScope API error: HTTP {http_status}, code {code}: {message}","messagePattern":"DashScope API error: HTTP (.+?), code (.+?): (.+?)","errorType":"http","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"tools/analysis/dashscope_asr.py","lineNumber":377,"sourceCode":"\n    @staticmethod\n    def _json_or_raise(response: Any) -> dict[str, Any]:\n        try:\n            return response.json()\n        except ValueError as exc:\n            raise RuntimeError(\n                f\"Non-JSON response from DashScope API: \"\n                f\"HTTP {response.status_code}\"\n            ) from exc\n\n    def _raise_for_error(\n        self, http_status: int, payload: dict[str, Any]\n    ) -> None:\n        if http_status < 400:\n            return\n        code = payload.get(\"code\")\n        message = payload.get(\"message\", \"unknown error\")\n        raise RuntimeError(\n            f\"DashScope API error: HTTP {http_status}, \"\n            f\"code {code}: {message}\"\n        )\n\n    @staticmethod\n    def _safe_error(exc: Exception) -> str:\n        return str(exc).replace(\n            os.environ.get(\"DASHSCOPE_API_KEY\", \"\"), \"[redacted]\"\n        )\n","sourceCodeStart":359,"sourceCodeEnd":387,"githubUrl":"https://github.com/calesthio/OpenMontage/blob/95e1c3d0ab93482159818560f6a8c8e866b9139f/tools/analysis/dashscope_asr.py#L359-L387","documentation":"Raised by _raise_for_error whenever a DashScope response has HTTP status >= 400, embedding the service's own code and message fields from the JSON error envelope. This is the generic API-error path covering auth failures, invalid parameters, quota exhaustion, and model-not-found, distinguished by the embedded code/message.","triggerScenarios":"Expired or missing DASHSCOPE_API_KEY (HTTP 401, code like InvalidApiKey); malformed request payload or unsupported parameter (HTTP 400); exceeding QPS/concurrency or free-quota limits (HTTP 429/400 with Throttling or Arrearage codes); referencing a model name not enabled for the account (HTTP 404).","commonSituations":"Key rotated on the console but stale in the environment; free tier quota exhausted mid-batch causing sudden 400s; passing audio URLs that require signed access; using a model ID only available in a different Bailian region (beijing vs shanghai workspace ids).","solutions":["Read the embedded code/message — InvalidApiKey means refresh DASHSCOPE_API_KEY, Throttling means back off and retry with jitter, quota errors mean top up or wait","For 429/throttling: wrap calls in exponential backoff retry (e.g. 1s/2s/4s, 3 attempts)","For 400: log the full request payload minus secrets and compare against the DashScope REST docs for the exact model","Confirm the workspace/model is enabled for the account in the Bailian console"],"exampleFix":"// before\nresp = self._post(url, payload)\n\n// after — retry on throttling codes only\nfor attempt in range(4):\n    resp = self._post(url, payload)\n    if resp.status_code == 429:\n        time.sleep(2 ** attempt)\n        continue\n    break","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"retryable = (\"Throttling\", \"Timeout\", \"ServiceUnavailable\")\nfor attempt in range(4):\n    try:\n        return self._request(url, payload)\n    except RuntimeError as e:\n        if not any(tok in str(e) for tok in retryable) or attempt == 3:\n            raise\n        time.sleep(2 ** attempt)","preventionTips":["Keep DASHSCOPE_API_KEY fresh — rotate on a schedule and fail fast on 401 codes","Respect rate limits with client-side throttling rather than relying on 429 feedback","Include the API's code field in logs so throttling vs parameter errors are distinguishable"],"tags":["dashscope","api","http","auth","rate-limit"],"backgroundTag":null,"analyzedSha":"95e1c3d0ab93482159818560f6a8c8e866b9139f","analyzedAt":"2026-08-15T06:31:20.014Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}