Error Handling
Authenticated API errors use a consistent JSON shape. Use the HTTP status code to decide what to do, and the error body for details. Unauthenticated x402 and MPP payment challenges carry their details in response headers; see the x402 and MPP guides.Error response shape
Authenticated API errors return this structure:code field is a stable, machine-readable string. The message field is human-readable and may change between versions — don’t match against it programmatically.
Optional fields inside error provide more context: param identifies an invalid parameter, and details contains structured error information. Read the HTTP response status even when error.status_code is absent.
Save the X-Request-Id response header when reporting a failed request to support. error.request_id is optional; your client should not require a request ID or timestamp in the JSON body.
Most authenticated 402 responses use payment_required and also include a reason_code and next_step. Branch on code first. For payment_required, then branch on reason_code when deciding which recovery action to show. Search can instead return insufficient_credits when remaining credits cannot cover the request; that body does not include reason_code or next_step.
Error code reference
Handling errors in code
Rate limit headers
Every response includes rate limit headers so you can track your budget before hitting 429. See Rate Limits & Tiers for the full header reference and trust tier table.Implementation advice
For production integrations, handle 429 and retryable 503 responses with exponential backoff. A simple strategy: wait2^attempt seconds, capped at 60 seconds, with jitter. If Retry-After is present, use it as the first delay.
Treat 429 as your API key’s account-level rate limit. Treat 503 service_unavailable from live data endpoints as temporary unavailability, not as your quota being exhausted. Honor Retry-After when present, including for Instagram post and transcript lookups.
For lookalike requests, treat 404 seed_not_found as a seed-level result rather than a temporary outage. Select another seed; don’t retry the same request with backoff.
Do not fold 502 upstream_contract_broken into your 503 retry path. A 503 indicates temporary unavailability; honor Retry-After when present and use bounded backoff. A 502 upstream_contract_broken means the API could not process the source data. Do not retry automatically; use your last cached value and contact support if the issue persists. Retrying an already-settled x402 or MPP request requires another payment.
Treat 402 as a billing issue that needs human intervention. Do not retry it automatically. Surface payment_required to your ops team or billing dashboard, and treat insufficient_credits as a prompt to add a payment method. Temporary failures while checking billing state return retryable 503 responses instead.