calesthio/OpenMontage · error · RuntimeError

DashScope API error: HTTP {http_status}, code {code}: {messa

Error message

DashScope API error: HTTP {http_status}, code {code}: {message}

What it means

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.

Source

Thrown at tools/analysis/dashscope_asr.py:377

    @staticmethod
    def _json_or_raise(response: Any) -> dict[str, Any]:
        try:
            return response.json()
        except ValueError as exc:
            raise RuntimeError(
                f"Non-JSON response from DashScope API: "
                f"HTTP {response.status_code}"
            ) from exc

    def _raise_for_error(
        self, http_status: int, payload: dict[str, Any]
    ) -> None:
        if http_status < 400:
            return
        code = payload.get("code")
        message = payload.get("message", "unknown error")
        raise RuntimeError(
            f"DashScope API error: HTTP {http_status}, "
            f"code {code}: {message}"
        )

    @staticmethod
    def _safe_error(exc: Exception) -> str:
        return str(exc).replace(
            os.environ.get("DASHSCOPE_API_KEY", ""), "[redacted]"
        )

View on GitHub (pinned to 95e1c3d0ab)

Solutions

  1. 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
  2. For 429/throttling: wrap calls in exponential backoff retry (e.g. 1s/2s/4s, 3 attempts)
  3. For 400: log the full request payload minus secrets and compare against the DashScope REST docs for the exact model
  4. Confirm the workspace/model is enabled for the account in the Bailian console

Example fix

// before
resp = self._post(url, payload)

// after — retry on throttling codes only
for attempt in range(4):
    resp = self._post(url, payload)
    if resp.status_code == 429:
        time.sleep(2 ** attempt)
        continue
    break
Defensive patterns

Strategy: retry

Try / catch

retryable = ("Throttling", "Timeout", "ServiceUnavailable")
for attempt in range(4):
    try:
        return self._request(url, payload)
    except RuntimeError as e:
        if not any(tok in str(e) for tok in retryable) or attempt == 3:
            raise
        time.sleep(2 ** attempt)

Prevention

When it happens

Trigger: 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).

Common situations: 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).

Related errors


AI-assisted analysis of calesthio/OpenMontage@95e1c3d0ab (2026-08-15). Data as JSON: /api/errors/5bbac32f6511f920. Report an issue: GitHub.