Batch TTS
Error Handling
Common exceptions raised by the TTS SDK and how to handle them.
Exception types
| Exception | HTTP Status | Description |
|---|---|---|
AuthenticationError | 401 | Invalid or missing API key. |
PermissionDeniedError | 403 | API key lacks required permissions. |
RateLimitError | 429 | Rate limit exceeded. Back off and retry. |
SynthesisError | 422 | Invalid text or configuration. |
ServerError | 5xx | Transient server error. Safe to retry. |
TimeoutError | — | Request exceeded configured timeout. |
ConnectionError | — | Network connectivity failure. |
Handling example
python
from shunyalabs.exceptions import (
AuthenticationError, RateLimitError,
SynthesisError, ServerError, ShunyalabsError
)
try:
result = await client.tts.synthesize("Hello!", config=config)
except AuthenticationError:
print("Invalid API key — check SHUNYALABS_API_KEY")
except RateLimitError:
print("Rate limit hit — back off and retry")
except SynthesisError as e:
print(f"Synthesis failed: {e}")
except ServerError:
print("Server error — safe to retry")
except ShunyalabsError as e:
print(f"SDK error: {e}")