Errors
Error model, status codes, and recommended handling.
Below is a common error shape for OpenAI-compatible endpoints: a non-2xx status and JSON containing error. Native protocols and upstream errors may differ; retain the original status and tolerate missing error fields.
{
"error": {
"message": "Invalid API key.",
"type": "invalid_api_key",
"code": "unauthorized"
}
}HTTP status codes
| Status | Meaning | Typical cause |
|---|---|---|
| 400 | Bad Request | Malformed JSON, missing required fields, invalid parameters. |
| 401 | Unauthorized | Missing, invalid, expired, or disabled key, or disallowed source IP |
| 402 | Payment Required | Insufficient available account balance; inspect the error body |
| 403 | Forbidden | Model/scope permission denied or key spending cap exhausted |
| 404 | Not Found | Unknown endpoint or model. |
| 408 | Request Timeout | Client took too long to send the request. |
| 409 | Conflict | Idempotency or state conflict. |
| 413 | Payload Too Large | Request body or context exceeds limits. |
| 422 | Unprocessable Entity | Validation error on a structurally valid request. |
| 429 | Too Many Requests | Request throughput or upstream capacity limit, not a spending-cap error |
| 500 | Internal Server Error | Server error; assess whether the operation produced results before retrying |
| 502 / 503 / 504 | Bad Gateway / Service Unavailable / Gateway Timeout | Upstream provider problem — retry with backoff. |
Error fields
error.message— human-readable description (do not string-match on it in production code).error.type— broad category, e.g.invalid_request_error,rate_limit_error,api_error.error.code— machine-readable code; interpret it alongside the status anderror.type, since it may not distinguish every failure.
code can be either an OpenAI-style string (invalid_api_key, rate_limit_exceeded, …) or a numeric platform error code.
Platform error-code ranges
When the error originates from the CanalAPI platform (rather than the upstream model), code is numbered into ranges so you can quickly identify the failing domain:
| Range | Numbers | Domain |
|---|---|---|
| 1xxx | 1000 – 1099 | Auth / account / API key / quota (e.g. key revoked, account disabled, quota exhausted) |
| 2xxx | 2000 – 2199 | Gateway / channel / adapter (e.g. model not found, upstream unreachable) |
| 3xxx | 3000 – 3099 | Billing / balance / pricing (e.g. insufficient balance, missing price) |
| 4xxx | 4000 – 4099 | Top-up / payment orders (e.g. order timeout, webhook validation failed) |
| 5xxx | 5000 – 5099 | Log query / export |
| 6xxx | 6000 – 6099 | Invoice generation / billing profile |
| 7xxx | 7000 – 7099 | Referrals / withdrawals |
| 8xxx | 8000 – 8099 | Notifications / announcements |
| 11xxx | 11500 – 11599 | Subscription plans / orders |
On the API call path you'll typically see 1xxx, 2xxx, and 3xxx; 4xxx and above mostly appear during console flows (top-up, invoice, withdrawal, subscription).
Retryable vs non-retryable
429and temporary server errors may be suitable for backoff, with both a total deadline and an attempt limit.- For
400,401,402,403,404,413, and422, first fix the request, credentials, permissions, or credit. Waiting does not fix configuration or balance issues. - A timeout, disconnection, or partial stream can leave the outcome uncertain. Replaying may duplicate charges or tool actions; a status code alone cannot establish retry safety.
Honor a valid Retry-After; otherwise, an example policy is roughly 1, 2, and 4 seconds with jitter and at most three additional attempts. Account for SDK retries rather than stacking them indefinitely. See rate limits and troubleshooting.
Reporting
When opening a support ticket, include:
- The request ID (
X-Request-Id) (from response headers and visible in Usage Logs) - A rough timestamp (UTC or local timezone)
- The model and endpoint used
This drastically shortens diagnosis. CanalAPI never includes your prompt / completion content in tickets.