cerebras.cloud.sdk.APIError. This documentation outlines the error types, how to handle them, and provides examples for effective error management.
Error Types
All errors in the Cerebras Inference API inherit fromcerebras.cloud.sdk.APIError. The main categories of errors are:
cerebras.cloud.sdk.APIConnectionError: The SDK raises this error when the library cannot connect to the API.cerebras.cloud.sdk.APIStatusError: The SDK raises this error when the API returns a non-success status code (4xx or 5xx).
HTTP Status Codes
| Status Code | Error Type |
|---|---|
| 400 | BadRequestError |
| 401 | AuthenticationError |
| 402 | PaymentRequired |
| 403 | PermissionDeniedError |
| 404 | NotFoundError |
| 413 | ContentTooLarge |
| 422 | UnprocessableEntityError |
| 429 | |
| 500 | InternalServerError |
| 503 | ServiceUnavailable |
| N/A | APIConnectionError |
Image Input Errors
| Status | Condition | Error Detail |
|---|---|---|
| 413 Content Too Large | Total image payload exceeds the configured request limit | "Total request size exceeds maximum" |
| Number of image inputs exceeds the configured request limit | "Number of image inputs exceeds maximum" | |
| Decompressed RGB bytes exceed 350 MB for an individual image | "Image decompression exceeds maximum memory limit" | |
| 400 Bad Request | image_url.url is not a valid data: URI | "Invalid image_url: expected base64 data URI" |
image_url.url is an HTTPS URL | "HTTPS image URLs are not supported. Use a base64-encoded data URI instead." | |
| Base64 payload is corrupt or image cannot be decoded | "Image data could not be decoded" | |
image_url content part on a non-user role | "image_url content parts are only supported on user messages" | |
| Image sent to a model without multimodal support | "Model {model} does not support image inputs" |
Handling Errors
Here’s an example of how to handle different types of errors:Retries
By default, the SDK automatically retries certain errors two times with a short exponential backoff. These include:- Connection errors
- 408 Request Timeout
- >= 500 Internal errors
max_retries option:
Timeouts
Requests time out after 1 minute by default. You can configure this with atimeout option:
APITimeoutError. Note that the SDK retries requests that time out twice by default.
