PlatformAPI documentation

Developer docs

12. Error handling

Version 1.0 · 2026-10-20

← Back to the API reference

Errors use the OpenAI format. Only 429, 502 and 503 are worth retrying; for any other status code, fix the request first.

Error format

json
{
  "error": {
    "message": "Rate limit exceeded (60/min) for this key.",
    "type": "rate_limit_error",
    "param": null,
    "code": null
  }
}
`type`Status codes
authentication_error401 (code is invalid_api_key)
permission_error403
invalid_request_error400, 402, 404, 409, 413
rate_limit_error429 (code may be sellable_capacity_exhausted when a model is at capacity)
server_error500 and above

A few errors use {"detail": ...} instead: validation errors from the speech and image backends, 401 from /dashboard/billing/*, unknown paths (404), wrong methods (405) and query-parameter type errors (422). In addition, when the request body is not a JSON object (an array, for example), some endpoints may return a plain-text 500. Handle both formats when parsing errors. Error message text may change, so base your logic on the status code and type.

Status codes

StatusCommon causesWhat to do
400Malformed JSON, invalid field, context exceeded, audio over 600 seconds, unknown voiceFix the request; do not retry
401Missing or invalid keyCheck the Authorization header
402Prepaid balance exhaustedAdd credit, then try again
403Restricted key used outside its scope or expiredCheck your key's scope with us
404Model does not exist or is not available, redeem code does not exist, or unknown pathCheck the model id and path
409Redeem code already used, disabled or expiredContact us
413Speech recognition upload over 25 MBCompress or split the file and upload again
429Rate, concurrency or daily quota exceeded, or the model is at capacityWait for Retry-After, then retry
500Unexpected server errorRetry once; if it persists, contact us
502Model backend unreachable (All replicas failed)Retry with exponential backoff; if it keeps failing, check the service status or switch models
503Model under maintenance or being switchedWait for Retry-After (usually 30 or 600 seconds)

Check order

When a request has several problems at once, the platform checks them in the order below and returns the first failure. When debugging, work down the table from the top.

OrderCheckOn failure
1Is the key valid?401
2Is the request valid JSON?400
3Is the key allowed to use this endpoint and model?403
4Does the model exist and is it available?404
5Is the model under maintenance or being switched?503
6Concurrent in-flight requests for the key429
7Prepaid balance402
8Requests per minute429
9Daily token quota429
10Overall model capacity429
11Model backend processing400 or 502

Field-validation 400s (for example, an unsupported image field) and the speech-recognition 413 may be returned earlier than this order suggests.

Retry strategy

  1. Retry only 429, 502 and 503, plus network-level connection errors.
  2. If there is a Retry-After, wait that long. Otherwise use exponential backoff (1, 2, 4, 8 seconds) with random jitter, up to 4 attempts.
  3. Use streaming for generations expected to take longer than 60 seconds; non-streaming requests longer than about 100 seconds may be disconnected. If a long non-streaming request times out, check your balance or usage to see whether it was charged before you resend it.
python
import random, time
from openai import APIStatusError

RETRYABLE = {429, 502, 503}

def with_retry(call, attempts=4):
    for i in range(attempts):
        try:
            return call()
        except APIStatusError as e:
            if e.status_code not in RETRYABLE or i == attempts - 1:
                raise
            wait = e.response.headers.get("retry-after")
            time.sleep(float(wait) if wait else 2 ** i + random.random())

resp = with_retry(lambda: client.chat.completions.create(
    model="glm-5.2-fp8",
    messages=[{"role": "user", "content": "Hello"}],
))

With the official OpenAI SDK, you can also set max_retries when you create the client and let the SDK handle retries.