Skip to main content

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:
Solutions:
  • Verify API key is correct
  • Check key hasn’t been revoked
  • Ensure Authorization: Bearer format is correct
  • Verify using live key (oc_live_...) not test key

invalid_request_error (400)

Cause: Request parameters are invalid Example:
Common causes:
  • Missing required parameters
  • Invalid parameter values
  • Wrong parameter types
  • Malformed request body
Solutions:
  • 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:
Solutions:

insufficient_quota (402)

Cause: Not enough prepaid credits Example:
Solutions:
  • 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:
Solutions:
  • 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:
Solutions:
  • 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:
Solutions:
  • 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