Skip to content

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"
}
FieldTypeDescription
codestringMachine-readable error code
messagestringHuman-readable description
request_idstringUnique 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

StatusCodeDescription
400bad_requestMalformed request syntax or invalid parameters
401unauthorizedMissing or invalid API key
403forbiddenValid API key but insufficient permissions
404not_foundResource does not exist or is not accessible
409conflictResource conflict (e.g., duplicate idempotency key with different payload)
422validation_errorRequest body fails schema validation
429too_many_requestsRate limit exceeded. Check Retry-After header
500internal_server_errorUnexpected server error
501not_implementedEndpoint or feature not yet available
502bad_gatewayUpstream service error
503service_unavailableTemporary outage. Check Retry-After header

Handling Errors

SDK error handlingtypescript
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

ScenarioStatusFix
Missing Authorization header401Add Authorization: Bearer sk_... header
Using sandbox key in production401Use the correct key for the environment
Creating invoice without items422Include at least one item in the items array
Accessing another entity’s data404Ensure the resource belongs to your entity
Sending too many requests429Implement exponential backoff; respect Retry-After
Database temporarily down503Retry after the Retry-After interval