1

Success Responses

Successful API calls return a 200 OK status code with a simple response format:

{
  "success": true
}

All successful responses include a success: true flag.

2

Error Responses

When an error occurs, the API returns an appropriate HTTP status code and a simple error response:

{
  "success": false,
  "message": "The provided API key is invalid."
}

Error responses include a success: false flag and a message describing the error.

3

Common Error Types

{
  "success": false,
  "message": "The provided API key is invalid."
}

HTTP Status: 401 Unauthorized

4

Error Handling

Here’s how to handle common errors in your application:

try {
  const result = await suonora.audio.speech({
    input: "Hello, world!",
    voice: "axel"
  });

  if (!result.success) {
    console.error(result.message);
    return;
  }

  // Handle successful response
  console.log('Speech generated successfully');

} catch (error) {
  if (error.status === 429) {
    console.error('Rate limited. Please try again later.');
  } else if (error.status === 401) {
    console.error('Authentication failed. Check your API key.');
  } else {
    console.error('Request failed:', error.message);
  }
}

Always implement proper error handling in your application to gracefully handle API errors and provide a good user experience.


Best Practices

  1. Implement Retry Logic

    • Use exponential backoff for rate limit errors
    • Respect the Retry-After header
    • Set reasonable retry limits
  2. Handle Authentication

    • Store API keys securely
    • Rotate keys regularly
    • Monitor for unauthorized access
  3. Validate Input

    • Check parameters before sending
    • Handle validation errors gracefully
    • Provide clear error messages to users
  4. Monitor Usage

    • Track API call success rates
    • Monitor rate limit usage
    • Set up alerts for unusual patterns

For production applications, consider implementing a robust error handling system that includes logging, monitoring, and alerting.