Error Handling
Learn how to handle errors gracefully when working with the Outcry AI API.Error Response Format
All API errors follow a consistent JSON structure:Error Object Fields
HTTP Status Codes
Error Types
authentication_error (401)
Cause: Invalid or missing API key Example:- Verify API key is correct
- Check key hasn’t been revoked
- Ensure
Authorization: Bearerformat is correct - Verify using live key (
oc_live_...) not test key
invalid_request_error (400)
Cause: Request parameters are invalid Example:- Missing required parameters
- Invalid parameter values
- Wrong parameter types
- Malformed request body
- Check API reference for required parameters
- Validate parameter values before sending
- Ensure correct data types (e.g., seconds as STRING)
permission_error (403)
Cause: API key missing required scope Example:- Check which scopes your API key has
- Create new key with required scopes
- See Authentication Guide
insufficient_quota (402)
Cause: Not enough prepaid credits Example:- Add credits to your account
- Check balance:
GET /v1/account/balance - Set up low-balance alerts in dashboard
rate_limit_error (429)
Cause: Too many requests in time window Example:- Implement exponential backoff
- Check rate limit headers
- Spread requests over time
- Upgrade to higher tier for more requests
api_error (500)
Cause: Server-side error Example:- Retry request with exponential backoff
- Check status page for incidents
- Contact support if persistent
service_unavailable_error (503)
Cause: Service temporarily down (maintenance or overload) Example:- Implement retry logic with exponential backoff
- Check status page
- Monitor for service restoration
Error Handling Best Practices
1. Always Use Try-Catch
Wrap all API calls in try-catch blocks:2. Implement Exponential Backoff
For retryable errors (429, 500, 503), use exponential backoff:3. Respect Rate Limit Headers
Check rate limit headers to avoid hitting limits:4. Validate Before Sending
Validate requests client-side to reduce API errors:5. Log Errors Comprehensively
Include context when logging errors:6. Handle User-Facing Errors
Show helpful messages to users:Common Error Scenarios
Scenario 1: Video Creation with Content Policy Violation
Scenario 2: Insufficient Credits
Scenario 3: Rate Limit with Retry-After
Scenario 4: Expired Video URL
Scenario 5: Webhook Signature Verification Failure
Testing Error Handling
Unit Test Example
Monitoring Errors
Error Rate Tracking
Track error rates to detect issues:Next Steps
Authentication
Prevent 401/403 authentication errors
Rate Limits
Avoid 429 rate limit errors
Webhooks
Handle webhook delivery errors
Best Practices
Follow production-ready patterns