Errors and limits
What the status codes mean, how many requests you can make, and how to retry.
Status codes
| Status | Meaning | What to do |
|---|---|---|
| 400 | The request is wrong: messages is not a list of objects, max_tokens is missing, the body is not JSON. | Fix the request. Do not retry it as it is. |
| 401 | No key, or a key that does not work (revoked, expired, mistyped). | Check the key. Make a new one if it was revoked. |
| 403 | The key may not be used for that account or path. | Use a key of the account the request is for. |
| 409 | A request with the same session_id is already being answered. | Wait for it, or use another session_id. |
| 429 | Too many requests (or, if a token limit is in force, the limit was reached). | Wait until X-RateLimit-Reset and try again. |
| 502, 503 | The model did not answer or is busy. | Try again after a moment, with a pause that grows. |
The shape of an error
Errors from the Messages endpoint come as {"error": {"type": "...", "message": "..."}} with a type such as invalid_request_error, overloaded_error or rate_limit_error. Errors from the layer in front of it (a missing key, a rate limit) have {"error": {"message": "...", "status": 401, "request_id": "..."}}. Look at the status code first, and quote the request_id (also in the X-Request-Id header) if you write to us about a request.
Limits
Requests are counted per minute for each account. Every response carries X-RateLimit-Limit, X-RateLimit-Remaining and X-RateLimit-Reset so that you can see where you stand. The default is 60 requests a minute, and it can change.
Tokens are counted and shown with your usage. No token limit is enforced right now. If one is introduced, going over it is a 429 with the type rate_limit_error on the Messages endpoint.
Kiwi writes one answer at a time. When several requests arrive together they wait in line, so under load a request is slower, not refused. The OpenAI-shaped endpoint answers 503 when it has waited four minutes without getting its turn.
Retrying
Retry 429, 502 and 503 only, wait longer each time (one second, two, four), and stop after a few tries. Do not retry 400, 401 or 403: the same request gives the same answer. A request that timed out may still have been answered, so do not resend something that must happen once without checking.