Skip to main content

Install

Requires Node 20 or later.

Configure

Use the SDK only in server code. Never import it into browser code, or your key ships with it.

Create and send an invoice

Every method takes request options as its last argument: { idempotencyKey, timeout, maxRetries, signal, headers }.

Errors and retries

Failed calls are retried up to maxRetries times with exponential backoff. The SDK retries network errors, timeouts, 408, 409 conflict, 429 and 5xx. Every POST gets an Idempotency-Key that’s reused on retries, so a retried create never runs twice. On a 429, it waits for Retry-After when that’s 60 seconds or less.
API errors extend APIError and carry status, code, detail and requestId.

Pagination

Webhooks

See Verify signatures for full handlers.

Response headers

For an endpoint the SDK doesn’t wrap yet, call invoiceai.request('GET', '/business').

Testing

There’s no sandbox, so don’t point tests at your live account. Instead:
  • Pass a fake fetch to new InvoiceAI({ apiKey: 'inv_live_test', fetch }) and return canned responses.
  • Run a mock server from the spec, then set INVOICE_AI_BASE_URL:
  • Sign test webhook bodies with await new Webhooks(secret).sign(body), which returns the three signature headers.

Versioning

The SDK is in beta (0.x). A minor release can include breaking changes, so pin the minor version: "@horizonpay/invoice-ai": "~0.1.0". Release notes are on GitHub.