errors
read ok, not the status
Every json body the api sends has ok, except the 422 for a missing parameter. Branch on that, not on the status code.
a failure
{
"ok": false,
"detail": "Insufficient credits. Please top up to your account."
}what each status means
| status | when |
|---|---|
| 200 | it worked |
| 400 | everything else, including running out of credits |
| 401 | the key is unknown |
| 422 | a required parameter is missing - this body has no ok |
| 429 | you are over your requests-per-minute limit |
| 500 | our bug - the body carries a request_id, send it to support |
| 503 | we are overloaded - retry after Retry-After (1 second), it costs nothing |
A 5xx without a json body comes from a proxy or from load shedding, not from the api. Treat it like a 503: wait, then retry.
noteOut of credits is a 400. There is no 402. Clients that special-case 402 will never see it.
A 400 we could not avoid still costs a fraction of a credit - the attempt was made. Credits lists it. A 429 costs nothing.