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": {
"items": {
"0": {
"gross_price": {
"_errors": ["Invalid input: expected number, received string"]
}
},
"_errors": []
},
"_errors": []
},
"request_id": "req_abc123"
}

Each key in cause identifies the field path, while _errors contains the validation messages. The top-level code is the machine-readable error code; the validation message describes the expected format and, where available, the received type. Do not parse human-readable text as a stable field error code.

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) {
  const apiError = error as Error & {
    status?: number;
    data?: { code?: string; message?: string; cause?: unknown; request_id?: string };
  };

  if (apiError.status === 422) {
    console.log("Validation failed:", apiError.data?.cause);
  } else if (apiError.status === 429) {
    console.log("Rate limited; retry using your backoff policy");
  } else if (apiError.status && apiError.status >= 500) {
    console.log("Server error:", apiError.data?.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