Gateway Error Codes & Troubleshooting
When calling LLMs via the API gateway, a failed response consists of an HTTP status code + a JSON error body. The external HTTP code is consistent with status_code in Console "Call Logs", making it easy to trace by log_id.
1. Unified Error Response Format
Platform Local Interception (Auth, Balance, Rate Limits, etc.)
{
"error": {
"message": "Insufficient account balance (below 0.5 CNY)",
"type": "api_error",
"code": "402"
}
}
| Field | Description |
|---|---|
error.message | Failure reason (upstream errors have URL domains and sk- keys redacted) |
error.type | api_error for platform interceptions |
error.code | HTTP status code string (e.g., "402"), not an OpenAI semantic error code |
Upstream Pass-Through
When the upstream returns valid JSON, the error body may be passed through verbatim (including vendor-specific type / code), while the HTTP status code still aligns with status_code in logs.
2. Status Code Quick Reference
| HTTP | Meaning | Typical message |
|---|---|---|
| 400 | Invalid parameters, model type mismatch, content moderation / copyright block | Parameter error; PolicyViolation / OutputVideoSensitiveContentDetected / copyright restriction |
| 401 | Authentication failed | Missing Authorization Header / Invalid Bearer Token Format / Invalid API Key |
| 402 | Insufficient available account balance | Insufficient account balance... / Insufficient balance |
| 403 | Insufficient permissions (token / IP / model whitelist, etc.) | API key disabled / Model xxx not allowed for this token / Daily quota exhausted / IP x.x.x.x not whitelisted |
| 404 | Model not found, no channel configured, no available channel, or upstream resource missing | Model not found: xxx / No channels configured for model: xxx / No available channels for model: xxx; message containing status 404 (e.g., input image download failure) |
| 429 | Rate limit or in-flight task cap | RPS limit exceeded / RPM limit exceeded / Balance too low, too many active tasks, please recharge |
| 500 | Gateway internal error | Internal server error |
| 502 | Upstream unavailable / connection failed | Upstream request failed or raw upstream message |
| 504 | Timeout / gateway interruption | Contains timeout, gateway, etc. |
Commonly Confused: Insufficient balance -> 402; content moderation/copyright -> 400; no token permission -> 403; 429 only means RPS/RPM or low-balance in-flight task gating.
3. Troubleshooting by Scenario
400 Bad Request (Malformed Request / Type Error / Content Block)
- Causes: Invalid JSON, missing required fields, calling an image/video model on the chat endpoint; or upstream content safety/copyright/sensitivity policy block (e.g.,
PolicyViolation). - Resolution: Check
modeland endpoint path; validate JSON. For content moderation blocks, adjust your prompt or reference assets—this is not a token permission issue (see 403 for permissions).
401 Unauthorized (Authentication Failed)
- Causes: Missing
Authorization, malformed Bearer header, or nonexistent Key. - Resolution:
Authorization: Bearer sk-xxx(with a single space). Disabled/expired tokens return 403.
402 Payment Required (Insufficient Balance)
- Causes: Available balance is insufficient to cover pre-deduction or minimum charge.
- Resolution: Top up in the Console. Async task GET polling / DELETE cancellation are still permitted when overdrawn, while POST submissions are blocked.
403 Forbidden (Permissions / Token Quota)
- Causes:
- Token disabled (
API key disabled), expired (API key expired) - Model not in token whitelist (
Model xxx not allowed for this token) - IP not in whitelist (
IP x.x.x.x not whitelisted) - Token daily/weekly/monthly/total quota exhausted (e.g.,
Daily quota exhausted) - Creation Center dedicated token invoked outside the Playground environment
- Token disabled (
- Resolution: Check token switch, model/IP whitelists, and quotas. Content moderation/copyright blocks return 400, not 403.
404 Not Found (Model / Channel / Resource Missing)
- Causes:
Model not found(no such ID in model table);No channels configured for model(model exists but no channel bound);No available channels for model(bound, but current group/quota/status/HA all unavailable); or upstream explicitly returnsstatus 404(e.g., input image URL cannot be downloaded). - Resolution: First inspect which error message was returned, then verify model ID, channel binding, and user group; check that image/video URLs in the request are accessible.
429 Too Many Requests (Rate Limit / In-Flight Limit)
- Causes: Token
rps_limit/rpm_limitexceeded; too many concurrent in-flight async tasks of the same type when balance is low. - Resolution: Retry with exponential backoff; top up or reduce concurrent async tasks.
500 / 502 / 504 (Gateway or Upstream Errors)
- 502: Upstream HTTP non-2xx or connection failure; non-standard business status codes are normalized to 502.
- 504: Connection or generation timeout.
- 500: Platform internal error (clients only see a generic message; details are in server logs).
- Resolution: Retry later; HA groups automatically switch sub-channels. Check
error_messagein Call Logs.
4. Special Notes for Async Tasks
For video and other long-running tasks: HTTP may be 200 when submission and polling succeed at the transport layer; check status in the body for business success/failure:
{
"id": "video_task_xxx",
"status": "failed",
"error": { "message": "Upstream failure reason" }
}
Logs record the inferred 4xx/5xx in status_code, while the polling endpoint itself may still return 200. Always rely on status and the logs.
5. Log Tracing & HA Behavior
- Logs: Every request records
log_id,status_code,error_message, latency, and billing; filter by timestamp andlog_idduring troubleshooting. The HTTP code matchesstatus_code. - HA Automatic Failover: Under multi-channel routing, 502/504 errors can trigger retries on backup channels, appearing to the caller as either a single success or a final unified error code.
- Processing Status: After a successful async submission, the log may briefly show
status_code=0(processing) and update to its terminal state once polling completes.
6. Capability-Specific Notes (Shared Across Example Pages)
The following scenarios also occur across "Common Usage Examples" articles and are maintained centrally here:
| Capability | Common Symptom | Code / Explanation |
|---|---|---|
| Chat | Context too long, invalid parameters | Upstream may pass through an OpenAI-style error; platform interceptions still return api_error + HTTP code |
| Image | Model type mismatch with /v1/images/generations | 400; same for invalid multi-image / reference image parameters |
| Qwen Image | Malformed size, invalid reference image URL | 400; 1024x1024 is accepted and auto-converted by the gateway to 1024*1024 |
| Video (Async) | Submit succeeds but polling returns status: failed | Polling HTTP 200; log status_code is 4xx/5xx, see Section 4 |
| Wan Video | Mixing start/end frames with reference assets, or audio-only without image/video | 400 |
| Wan Video | Mixing files / links with start/end frame roles | 400 |
| Video (Sync Block) | Balance, rate limit, no channel | 402 / 429 / 404 consistent with the table above |
| Native Routes | Misspelled DashScope / Volcengine path | 404 or upstream 400; verify the path and listed model name |
When adding error explanations for new providers or scenarios, edit only this page (slug: error-codes); example articles only keep link references at the bottom.