To get the most out of the Sonna.ai API, we recommend following these best practices.

Request Optimization

Batching Text

The models work best when given complete sentences. Try to avoid splitting sentences across multiple API calls, as this can affect the prosody (natural rhythm) of the voice.

Character Limits

The maximum input length per request is 4096 characters. For longer texts, we recommend splitting the content at paragraph boundaries.

Error Handling

Implement robust error handling in your application. Common status codes to watch for:
CodeMeaningAction
400Bad RequestCheck your parameters (missing input/voice).
401UnauthorizedVerify your API key.
402Payment RequiredTop up your credits.
429Too Many RequestsImplement exponential backoff.
500Internal ErrorRetry after a short delay.

Latency Management

Since Sonna.ai returns a URL to the audio file, you can start pre-fetching or playing the audio as soon as the JSON response is received.
For a smoother user experience, consider:
  1. Showing a loading state during the generation (MISS cache).
  2. Using the built-in caching (HIT cache) for repetitive UI elements.