Error Handling

Learn how to handle API errors and edge cases

Error Responses

401

Unauthorized

Missing or invalid API key

Response: {"error": "missing_api_key"}

402

Payment Required

Insufficient credits to complete the request

Response: {"error": "insufficient_credits"}

429

Too Many Requests

Rate limit exceeded. Check Retry-After header

Response: {"error": "rate_limit_exceeded"}

500

Internal Server Error

Something went wrong on our end. Try again later

Response: {"error": "server_error"}

Best Practices

Always check the status code

Implement logic to handle different error codes appropriately

Implement retry logic

Retry failed requests with exponential backoff, respecting Retry-After headers

Log errors

Keep detailed logs of errors for debugging and monitoring

Monitor credit usage

Track credit consumption to avoid running out unexpectedly