Exception Hierarchy
Common Exceptions
APIConnectionError
Raised when the SDK is unable to connect to the API (network issues, timeouts):AuthenticationError
Raised when API key is missing or invalid (401):RateLimitError
Raised when rate limit is exceeded (429):APIStatusError
Base class for all HTTP status errors. Containsstatus_code and response properties:
APITimeoutError
Raised when a request times out:Error Code Reference
| Status Code | Error Type | Description |
|---|---|---|
| 400 | BadRequestError | Invalid request parameters |
| 401 | AuthenticationError | Missing or invalid API key |
| 403 | PermissionDeniedError | Insufficient permissions |
| 404 | NotFoundError | Resource not found |
| 409 | ConflictError | Request conflicts with current state |
| 422 | UnprocessableEntityError | Request validation failed |
| 429 | RateLimitError | Rate limit exceeded |
| >=500 | InternalServerError | Server error |
| N/A | APIConnectionError | Network/connection error |
| N/A | APITimeoutError | Request timed out |
Generic Error Handling
Handle all errors with a generic catch:Error Response Details
API errors include detailed information:Retry Logic
The SDK automatically retries certain errors by default (2 times with exponential backoff):- Connection errors (network issues)
- 408 Request Timeout
- 409 Conflict
- 429 Rate Limit
-
=500 Internal Server errors
Manual Retry Logic
For more control, implement your own retry logic:Timeout Handling
Configure timeouts for requests:Best Practices
Handle Specific Exceptions
Catch specific exception types rather than generic Exception for better error handling.
Log Errors
Log errors with context (job_id, request_id) for debugging.
Retry Transient Errors
The SDK automatically retries transient errors, but you can customize retry behavior.
Provide User Feedback
Show meaningful error messages to users, not raw exceptions.
Check Connection Errors
For
APIConnectionError, check e.__cause__ to see the underlying exception.Handle Rate Limits
Rate limit errors are automatically retried, but you can also handle them manually.
Complete Example
Next Steps
- Learn about job management for async operations
- Check out the async client for concurrent processing