Errors
One error envelope, stable codes, and what to do about each.
Every failing API response uses the same shape. Branch on code, which is stable, rather than on message, which is written for humans and may change.
Error response
{
"error": {
"code": "validation_error",
"message": "Validation failed",
"details": { "messages": ["Array must contain at least 1 element(s)"] }
}
}Codes
Errors mid-stream
A request that has already returned 200 cannot change its status. If generation fails after the stream opens, an
error event arrives inside the stream, followed by done with finishReason: "error".