Error Handling
Every error raised by the SDK inherits from dhivehigpt_sdk.DhivehiGPTError, which carries a message, a status_code (when the error came from an HTTP response), and the raw response payload.
from dhivehigpt_sdk import DhivehiGPT, DhivehiGPTError, NotFoundError
client = DhivehiGPT()
try:
client.voices.get("does-not-exist")
except NotFoundError as e:
print(e.status_code, e.message)
except DhivehiGPTError as e:
print("Something else went wrong:", e)
Exception reference
| Exception | HTTP status | Cause |
|---|---|---|
dhivehigpt_sdk.AuthenticationError | 401 | The X-Api-Key header is missing, invalid, or revoked. |
dhivehigpt_sdk.PermissionDeniedError | 403 | E.g. the team does not have enough credits to generate audio. |
dhivehigpt_sdk.NotFoundError | 404 | The requested resource does not exist. |
dhivehigpt_sdk.ValidationError | 422 | The request body or parameters failed validation. |
dhivehigpt_sdk.RateLimitError | 429 | More than 60 requests per minute were sent with this API key. |
dhivehigpt_sdk.ServerError | 5xx | An upstream/server-side error occurred. |
dhivehigpt_sdk.APIError | other 4xx | Any other non-2xx response. |
dhivehigpt_sdk.APIConnectionError | — | The request could not reach the DhivehiGPT API at all. |
Validation errors
ValidationError additionally exposes an errors dict with field-level messages, mirroring the API's errors object:
from dhivehigpt_sdk import ValidationError
try:
client.tasks.calculate(task="not-a-real-task", units=1000)
except ValidationError as e:
print(e.errors)
# {"task": ["The selected task is invalid."]}