Batch TTS

Error Handling

Common exceptions raised by the TTS SDK and how to handle them.


Exception types

ExceptionHTTP StatusDescription
AuthenticationError401Invalid or missing API key.
PermissionDeniedError403API key lacks required permissions.
RateLimitError429Rate limit exceeded. Back off and retry.
SynthesisError422Invalid text or configuration.
ServerError5xxTransient server error. Safe to retry.
TimeoutErrorRequest exceeded configured timeout.
ConnectionErrorNetwork 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}")