Error Handling
The Open Pay API uses conventional HTTP status codes and a consistent error response format. This guide covers every error scenario and how to handle them.Error Response Format
All errors follow a standard JSON structure:| Field | Type | Description |
|---|---|---|
error.code | string | Machine-readable error code (uppercase snake_case) |
error.message | string | Human-readable explanation of the error |
HTTP Status Codes
| Status | Meaning | When It Happens |
|---|---|---|
400 | Bad Request | Malformed JSON, missing required fields, invalid parameter values |
401 | Unauthorized | Missing or invalid API key / bearer token |
403 | Forbidden | Valid credentials but insufficient permissions (e.g., accessing another merchant’s data) |
404 | Not Found | Resource does not exist (e.g., invalid payment_id) |
409 | Conflict | Duplicate operation (e.g., payment already completed, idempotency key reused with different parameters) |
422 | Unprocessable Entity | Semantically invalid request (e.g., unsupported token, amount below minimum) |
429 | Too Many Requests | Rate limit exceeded |
500 | Internal Server Error | Unexpected server error. Retry with backoff. |
Common Error Codes
- Authentication Errors
- Payment Errors
- Webhook Errors
- Settlement Errors
| Code | Status | Description | Fix |
|---|---|---|---|
INVALID_API_KEY | 401 | API key is malformed or revoked | Check your API key in the Merchant Portal |
EXPIRED_TOKEN | 401 | JWT bearer token has expired | Refresh your token via POST /v1/auth/refresh-token |
MISSING_AUTH_HEADER | 401 | No Authorization header provided | Add Authorization: Bearer <token> header |
INSUFFICIENT_PERMISSIONS | 403 | API key lacks required scope | Generate a new API key with the correct permissions |
TWO_FA_REQUIRED | 403 | Operation requires 2FA verification | Complete 2FA challenge first |
Rate Limiting
The API enforces rate limits to ensure fair usage. When you exceed the limit, you receive a429 response.
Rate limit headers are included in every response:
| Header | Description |
|---|---|
X-RateLimit-Limit | Maximum requests allowed in the current window |
X-RateLimit-Remaining | Requests remaining in the current window |
X-RateLimit-Reset | Unix timestamp when the window resets |
| Tier | Rate Limit |
|---|---|
| Standard | 100 requests / minute |
| Pro | 500 requests / minute |
| Enterprise | Custom |
Handling Rate Limits
Retry Strategies
Identify Retryable Errors
Only retry on these status codes:
- 429 - Rate limit exceeded (wait for
X-RateLimit-Reset) - 500 - Internal server error (transient)
- 502/503/504 - Gateway errors (transient)
400, 401, 403, 404, 409, or 422 errors. These require fixing the request.Set a Maximum Retry Count
Limit retries to 3-5 attempts. If the request still fails, log the error and alert your monitoring system.
Use Idempotency Keys
For
POST requests (especially payment creation), include an Idempotency-Key header so retries don’t create duplicate resources:Idempotency keys are scoped to your merchant account and expire after 24 hours. Using the same key with the same parameters returns the original response without creating a new resource.