Error Codes
The API uses standard HTTP status codes and returns structured JSON error responses.
Error Response Format
All errors follow this structure:
{ "code": "not_found", "message": "Not Found", "request_id": "req_abc123"}| Field | Type | Description |
|---|---|---|
code | string | Machine-readable error code |
message | string | Human-readable description |
request_id | string | Unique request identifier for support |
Validation Errors
Validation errors (422) include a cause field with per-field details from schema validation:
{ "code": "validation_error", "message": "Validation error", "cause": { "name": { "_errors": ["Required"] }, "price": { "_errors": ["Expected number, received string"] } }, "request_id": "req_abc123"}Each key in cause is a field name, with _errors containing an array of validation messages.
Error Codes Reference
| Status | Code | Description |
|---|---|---|
| 400 | bad_request | Malformed request syntax or invalid parameters |
| 401 | unauthorized | Missing or invalid API key |
| 403 | forbidden | Valid API key but insufficient permissions |
| 404 | not_found | Resource does not exist or is not accessible |
| 409 | conflict | Resource conflict (e.g., duplicate idempotency key with different payload) |
| 422 | validation_error | Request body fails schema validation |
| 429 | too_many_requests | Rate limit exceeded. Check Retry-After header |
| 500 | internal_server_error | Unexpected server error |
| 501 | not_implemented | Endpoint or feature not yet available |
| 502 | bad_gateway | Upstream service error |
| 503 | service_unavailable | Temporary outage. Check Retry-After header |
Handling Errors
try {
const invoice = await sdk.invoices.create({
items: [{ name: "Widget", quantity: 1, price: 9.99 }],
});
} catch(error) {
if (error.status === 422) {
// Validation error — check error.body.cause for field details
console.log("Validation failed:", error.body.cause);
} else if (error.status === 429) {
// Rate limited — retry after delay
const retryAfter = error.headers.get("Retry-After");
console.log(`Rate limited. Retry after ${retryAfter}s`);
} else if (error.status >= 500) {
// Server error — safe to retry
console.log("Server error:", error.body.message);
}
}Common Errors
| Scenario | Status | Fix |
|---|---|---|
Missing Authorization header | 401 | Add Authorization: Bearer sk_... header |
| Using sandbox key in production | 401 | Use the correct key for the environment |
| Creating invoice without items | 422 | Include at least one item in the items array |
| Accessing another entity’s data | 404 | Ensure the resource belongs to your entity |
| Sending too many requests | 429 | Implement exponential backoff; respect Retry-After |
| Database temporarily down | 503 | Retry after the Retry-After interval |