Skip to main content

Error Handling

The Uberduck API uses standard HTTP status codes to indicate the success or failure of API requests. In addition to the status code, error responses include a JSON object with detailed information about what went wrong.

Error Response Format

All API errors return a JSON object with the following structure:

{
"error": {
"code": "error_code",
"message": "A human-readable error message",
"details": {
// Additional information about the error (optional)
}
}
}

HTTP Status Codes

Status CodeDescription
200OK - The request was successful.
400Bad Request - The request was invalid or cannot be served.
401Unauthorized - Authentication is required or failed.
403Forbidden - The authenticated user doesn't have permission.
404Not Found - The requested resource doesn't exist.
422Unprocessable Entity - The request was well-formed but contains semantic errors.
429Too Many Requests - Rate limit exceeded.
500Internal Server Error - Something went wrong on our end.
503Service Unavailable - The service is temporarily unavailable.

Common Error Codes

Authentication Errors

Error CodeDescription
missing_api_keyNo API key was provided.
invalid_api_keyThe provided API key is invalid.
expired_api_keyThe provided API key has expired.
insufficient_permissionsThe API key doesn't have permission for the requested operation.

Request Errors

Error CodeDescription
invalid_requestThe request contains invalid parameters.
missing_required_parameterA required parameter is missing.
invalid_parameter_valueA parameter has an invalid value.
unsupported_parameterAn unsupported parameter was provided.

Resource Errors

Error CodeDescription
voice_not_foundThe specified voice doesn't exist.
model_not_foundThe specified model doesn't exist.
voice_model_incompatibleThe specified voice is not compatible with the specified model.
resource_not_foundThe requested resource doesn't exist.

Rate Limiting Errors

Error CodeDescription
rate_limit_exceededYou've exceeded your rate limit.
quota_exceededYou've exceeded your quota for the current billing period.

Text-to-Speech Specific Errors

Error CodeDescription
text_too_longThe provided text exceeds the maximum length.
text_emptyThe provided text is empty.
unsupported_languageThe language is not supported by the specified voice.
tts_failedText-to-speech processing failed.

Error Handling Example

// JavaScript example
async function generateSpeech(text, voice, model) {
try {
const response = await fetch('https://api.uberduck.ai/v1/text-to-speech', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
text,
voice,
model
})
});

if (!response.ok) {
const errorData = await response.json();
throw new Error(`API error: ${errorData.error.code} - ${errorData.error.message}`);
}

return await response.json();
} catch (error) {
console.error('Speech generation failed:', error);
throw error;
}
}

Best Practices for Error Handling

  1. Always check HTTP status codes - The HTTP status code will give you a high-level indication of what went wrong.

  2. Parse the error response - The error response contains detailed information about what went wrong.

  3. Implement exponential backoff - When you encounter rate limiting errors (429), implement exponential backoff to retry the request.

  4. Log error details - Log the error code, message, and details for debugging.

  5. Handle specific errors appropriately - Different errors may require different handling strategies:

    • For text_too_long errors, you might want to split the text into smaller chunks.
    • For rate_limit_exceeded errors, you should wait before retrying.
    • For voice_not_found errors, you might want to suggest alternative voices.