Documentation/Integration guide/Errors and troubleshooting
Integration guide

Errors and troubleshooting

Standardized JSON error structures, HTTP status codes, and automated error recovery.

4 min read
•Updated October 21, 2026

Standard Error Object Schema

Errors use an error object with code, message and request_id. Keep the request ID when asking support to investigate. Validation errors may include field details.

Common Status Codes & Diagnostics

Common status codes: 401 missing/invalid credentials; 403 denied; 404 missing or inaccessible resource; 409 invalid state or idempotency conflict; 422 invalid payload; 429 rate limited; 502/503 provider or service failure.

Asynchronous Failure Inspection

For accepted asynchronous jobs, inspect the resource status and errorCode/errorMessage or the failure webhook. Provider failures should not expose private model names or credentials.

Code Implementation

import os
import time
import requests

BASE = "https://api.apimarketplace.com"
headers = {"Authorization": "Bearer " + os.environ["API_KEY"]}

def resilient_request(method: str, endpoint: str, max_retries: int = 3, **kwargs):
    """Executes requests with automated rate-limit recovery and validation error inspection."""
    url = f"{BASE}{endpoint}"
    for attempt in range(max_retries):
        resp = requests.request(method, url, headers=headers, timeout=300, **kwargs)
        
        if 200 <= resp.status_code < 300:
            return resp.json() if resp.content else None
            
        # 429 Rate Limiting: Back off respecting Retry-After
        if resp.status_code == 429:
            retry_after = int(resp.headers.get("Retry-After", 2 ** attempt))
            print(f"Rate limited (429). Retrying in {retry_after}s...")
            time.sleep(retry_after)
            continue
            
        # 422 Unprocessable Entity: Log specific field errors
        if resp.status_code == 422:
            detail = resp.json().get("error", {})
            raise ValueError(f"Payload validation failed (422): {detail}")
            
        # 401 / 403 Security Errors
        if resp.status_code in (401, 403):
            raise PermissionError(f"Access denied ({resp.status_code}): {resp.text}")
            
        resp.raise_for_status()
        
    raise RuntimeError("Maximum retries exceeded.")