Exceptions
Exception classes for handling errors from the Moderately AI API.
Base Exceptions
- class moderatelyai_sdk.exceptions.ModeratelyAIError(message, details=None)[source]
Bases:
ExceptionBase exception class for all Moderately AI SDK errors.
All SDK-specific exceptions inherit from this class, making it easy to catch any SDK-related error with a single except clause.
- class moderatelyai_sdk.exceptions.APIError(message, status_code=None, response_data=None, request_id=None)[source]
Bases:
ModeratelyAIErrorRaised when an API request fails due to a server error or client error.
This is the most common exception you’ll encounter when using the SDK. It includes the HTTP status code and full response data for debugging.
- Parameters:
Authentication Exceptions
- class moderatelyai_sdk.exceptions.AuthenticationError(message='Authentication failed')[source]
Bases:
ModeratelyAIErrorRaised when authentication fails.
This typically means: - No API key was provided - The API key is invalid or expired - The API key doesn’t have permission for the requested operation
- Parameters:
message (
str)
HTTP Status Exceptions
- class moderatelyai_sdk.exceptions.NotFoundError(message='Resource not found')[source]
Bases:
APIErrorRaised when a requested resource is not found (HTTP 404).
- Parameters:
message (
str)
Rate Limiting and Timeouts
- class moderatelyai_sdk.exceptions.RateLimitError(message='Rate limit exceeded', retry_after=None)[source]
Bases:
APIErrorRaised when the API rate limit is exceeded.
Includes retry_after information when available, indicating how long to wait before making another request.
- class moderatelyai_sdk.exceptions.TimeoutError(message='Request timed out')[source]
Bases:
ModeratelyAIErrorRaised when a request times out.
This can happen due to network issues or when the server takes too long to respond. The SDK automatically retries timeout errors with exponential backoff.
- Parameters:
message (
str)
Validation Exceptions
- class moderatelyai_sdk.exceptions.ValidationError(message, details=None)[source]
Bases:
ModeratelyAIErrorRaised when request validation fails.
This includes detailed information about which fields failed validation and why, making it easy to fix the request.