API
Errors and rate limits
Error object format, HTTP status codes, error codes and how to handle rate limits and retries safely.
Errors use conventional HTTP status codes and a consistent JSON body. Your code should branch on error.code, not on the human-readable message.
Error body json
{
"error": {
"type": "invalid_request_error",
"code": "invalid_amount",
"message": "amount must be a positive decimal with at most 2 decimals, e.g. \"25.00\"."
}
} Status codes
| Status | Meaning |
|---|---|
| 200 / 201 | Success / created. |
| 400 | Invalid parameters or JSON. |
| 401 | Missing, malformed or revoked API key. |
| 403 | Account suspended, or action not allowed (for example simulating a live invoice). |
| 404 | Object not found, or it belongs to the other mode (live vs test). |
| 409 | Conflict with the current state (for example canceling a paid invoice). |
| 413 | Request body too large (32 KB limit). |
| 429 | Rate limited. Back off and retry. |
| 500 / 502 / 503 | Temporary problem on our side or with an upstream data source. Safe to retry with the same Idempotency-Key. |
Common error codes
| Code | Fix |
|---|---|
invalid_api_key | Check the Authorization header format and that the key is not revoked. |
invalid_amount | Send a positive decimal string with at most 2 decimals. |
unsupported_currency | Use USD, EUR, GBP, CAD or AUD. |
invalid_url | redirect_url and cancel_url must be public https URLs. |
invalid_metadata | Max 20 keys, key length 40, value length 500. |
invalid_idempotency_key | 1-128 characters from [A-Za-z0-9._:-]. |
invoice_not_open | The invoice is already paid, expired or canceled. |
rate_limited | Wait a few seconds; use exponential backoff. |
rates_unavailable | Exchange rates could not be fetched. Retry shortly. |
Retrying safely
Network errors and 5xx responses can be retried. When creating invoices, always send the same Idempotency-Key on retries so you never create duplicates. Use exponential backoff starting at 1 second, capped at about 30 seconds.