Skip to main content
The Cerebras Inference API uses standard HTTP response status codes to indicate the success or failure of an API request. When errors occur, the SDK throws specific exceptions that inherit from 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 from cerebras.cloud.sdk.APIError. The main categories of errors are:
  1. cerebras.cloud.sdk.APIConnectionError: The SDK raises this error when the library cannot connect to the API.
  2. cerebras.cloud.sdk.APIStatusError: The SDK raises this error when the API returns a non-success status code (4xx or 5xx).

HTTP Status Codes

Image Input Errors

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
You can configure or disable retry settings using the max_retries option:

Timeouts

Requests time out after 1 minute by default. You can configure this with a timeout option:
On timeout, the SDK throws an APITimeoutError. Note that the SDK retries requests that time out twice by default.