API Reference
Errors

Errors

The API uses standard HTTP status codes and returns detailed error information.

Error Response Format

{
  "error": {
    "code": "invalid_request",
    "message": "avatar_id is required",
    "details": {
      "field": "avatar_id",
      "reason": "missing"
    }
  }
}

HTTP Status Codes

CodeDescription
200Success
400Bad Request - Invalid parameters
401Unauthorized - Invalid or missing API key
403Forbidden - Insufficient permissions
404Not Found - Resource does not exist
429Too Many Requests - Rate limit exceeded
500Internal Server Error
503Service Unavailable

Error Codes

Authentication Errors

CodeHTTPDescription
invalid_api_key401API key is invalid or revoked
missing_api_key401No API key provided
expired_api_key401API key has expired

Request Errors

CodeHTTPDescription
invalid_request400Request body is malformed
missing_parameter400Required parameter is missing
invalid_parameter400Parameter value is invalid

Resource Errors

CodeHTTPDescription
conversation_not_found404Conversation does not exist
avatar_not_found404Avatar does not exist
message_not_found404Message does not exist

Rate Limit Errors

CodeHTTPDescription
rate_limit_exceeded429Too many requests
quota_exceeded429Monthly quota exceeded

Provider Errors

CodeHTTPDescription
ai_provider_error503AI provider unavailable
tts_provider_error503TTS provider unavailable

Handling Errors

Always implement retry logic with exponential backoff for 5xx errors.

JavaScript Example

async function sendMessage(conversationId: string, content: string) {
  const maxRetries = 3;
 
  for (let attempt = 0; attempt < maxRetries; attempt++) {
    try {
      const response = await fetch(
        `https://api.avatarium.ai/v1/conversations/${conversationId}/messages`,
        {
          method: 'POST',
          headers: {
            'Authorization': `Bearer ${API_KEY}`,
            'Content-Type': 'application/json',
          },
          body: JSON.stringify({ content }),
        }
      );
 
      if (response.ok) {
        return response.json();
      }
 
      const error = await response.json();
 
      // Don't retry client errors
      if (response.status < 500) {
        throw new Error(error.error.message);
      }
 
      // Retry server errors with backoff
      await new Promise(r => setTimeout(r, Math.pow(2, attempt) * 1000));
    } catch (e) {
      if (attempt === maxRetries - 1) throw e;
    }
  }
}