Understand API error handling
error.code
, giving a request error if:
200
and any error occurred while the LLM is producing the output will be emitted in the response body or as an SSE data event.
Example code for printing errors:
400
: Bad Request (invalid or missing params, CORS)401
: Invalid credentials (OAuth session expired, disabled/invalid API key)402
: Your account or API key has insufficient credits. Add more credits and retry the request.403
: Your chosen model requires moderation and your input was flagged408
: Your request timed out429
: You are being rate limited502
: Your chosen model is down or we received an invalid response from it503
: There is no available model provider that meets your routing requirementserror.metadata
will contain information about the issue. The shape of the metadata is as follows:
error.metadata
will contain information about the issue. The shape of the metadata is as follows: