Aller au contenu principal

Error Handling

Best practices for handling errors from YODI APIs.

Known Issues

Some services currently have known issues. If you encounter an error, check the service status or contact support for the latest information.

HTTP Status Codes​

CodeMeaningAction
200SuccessRequest completed successfully
201CreatedResource created successfully
400Bad RequestCheck request parameters
401UnauthorizedInvalid or missing API key
402Payment RequiredInsufficient credits
403ForbiddenAccess denied
404Not FoundResource doesn't exist
429Too Many RequestsRate limit exceeded, wait and retry
500Server ErrorTry again later

Error Response Format​

All API responses follow a standard envelope. On error, error is true:

{
"message": "INSUFFICIENT_CREDITS",
"error": true,
"data": null,
"status": 402
}

Common Errors​

401 Unauthorized​

{
"message": "INVALID_API_KEY",
"error": true,
"data": null,
"status": 401
}

Solutions:

  • Check API key is correct
  • Verify key hasn't been revoked
  • Check Authorization header format: Bearer YOUR_KEY

402 Payment Required​

{
"message": "INSUFFICIENT_CREDITS",
"error": true,
"data": null,
"status": 402
}

Solutions:

  • Top up your credits
  • Upgrade your subscription
  • Check credit balance

429 Rate Limited​

{
"message": "RATE_LIMITED",
"error": true,
"data": null,
"status": 429
}

Solutions:

  • Wait before retrying
  • Implement exponential backoff
  • Upgrade to higher tier plan

Error Handling Best Practices​

Implement Retry Logic​

import time
import requests

def retry_with_backoff(url, headers, data, max_retries=3):
for attempt in range(max_retries):
try:
response = requests.post(url, headers=headers, json=data)

if response.status_code == 429:
wait_time = 2 ** attempt
print(f"Rate limited. Waiting {wait_time}s...")
time.sleep(wait_time)
continue

return response
except Exception as e:
print(f"Error: {e}")
time.sleep(2 ** attempt)

raise Exception("Max retries exceeded")

Log Errors​

import logging

logger = logging.getLogger(__name__)

try:
response = requests.post(url, headers=headers, json=data)
response.raise_for_status()
except requests.exceptions.RequestException as e:
logger.error(f"API request failed: {e}", exc_info=True)
raise

Handle Timeouts​

import requests

try:
response = requests.post(
url,
headers=headers,
json=data,
timeout=30 # 30 second timeout
)
except requests.exceptions.Timeout:
logger.error("Request timed out")
# Retry or handle as needed

Next Steps​