Errors on /v1 keep OpenAI's shape, so OpenAI SDKs raise their usual errors:
CodeJSON
Branch on error.code. Some codes add fields inside error: accepts (how to pay) on a payable 402, spend_cap_wei on spend_cap_exceeded. A 429 carries a retry-after header. The OpenAI SDKs have no 402 class: a 402 arrives as a plain API error with status 402.OpenAI SDKs retry 429 and 5xx by themselves, up to their retry count. A retry is a new call: on a call paid per call, it signs and pays a new payment.
By code
Status
code
Means
What to do
400
null
The request is invalid: a missing field, an unsupported role or content type, or the last message is not the user's.
Fix the request; message says what is wrong.
400
context_length_exceeded
The system messages and the last turn alone don't fit one job (about 124 KiB once encrypted).
Shorten them. Older turns are dropped by themselves: see Limits.
PATCH on a revoked key: its cap no longer changes.
Mint a new key.
409
api_key_active
DELETE on an active key.
Revoke it first.
In a stream
Before the first chunk, a streamed call fails like any other: the status and body above. After the first chunk the status is already 200, so the stream ends with an error event instead of [DONE]:
CodeTEXT
code
Means
What to do
job_failed
The job failed after it started streaming.
Send the request again.
stream_diverged
The worker restarted its answer after the first chunks went out, so the text received is not the answer it committed on chain.