Skip to main content
The official TypeScript SDK (@alguna/sdk) wraps the Alguna Public API with a fully typed client — customers, products, subscriptions, invoices, and payment links, with request and response types generated from the versioned OpenAPI specification.
The SDK is server-side only. API keys are secret — never ship them to a browser. For embedding a purchase flow in your frontend, use Embedded Checkout (@alguna/checkout-sdk) instead: your server mints the session with this SDK’s API key, your frontend mounts it.

How it works

  1. Create an API key in your dashboard (format id.secret — a server secret).
  2. Instantiate the client with the key. Every request it makes carries Authorization: Bearer and pins the API version via the Alguna-Version header.
  3. Call resources (alguna.customers, alguna.subscriptions, …). Methods return typed response objects; failed requests throw typed errors.

Installation

Requires Node.js 18 or later.

Subscriptions are created in draft status. Pass auto_activate: true (as above) or call alguna.subscriptions.activate(id) when you are ready to go live. See Creating a Subscription for the full set of patterns — plans, overrides, and bundles all work the same way through the SDK.

Resources

The SDK covers every public API operation, one field per resource. Highlights: Plus products, plans, bundles, creditNotes, credits, wallets, walletGrants, metrics, events, payments, refunds, integrations, insights, revenueSchedules, and tax — the resource layer is generated from the versioned spec, and generation enforces parity: it fails if any API operation is missing from the SDK. Request and response types are exported from the package root:

Pagination & filtering

List endpoints accept limit, offset, sort (in field:order format), and the same filter parameters as the HTTP API:

Error handling

Failed requests throw typed errors, all extending AlgunaError:
All errors expose statusCode, code, and requestId. Include the requestId when contacting support about a failed call.

Idempotency

Mutating methods accept an optional trailing options argument. Pass idempotencyKey to make retries safe — the API returns the original result instead of repeating the action (see Idempotency):

Configuration

apiVersion is required: pin the version your integration is written against, so upgrading the SDK package never silently moves you to a different API version — see Versioning.

FAQ

Can I use the SDK in the browser? No. It authenticates with your secret API key. For browser purchase flows, mint a checkout session server-side and mount it with Embedded Checkout. Does the SDK cover every endpoint? Yes. The resource layer is generated from the versioned OpenAPI spec, and generation fails if any operation in the API reference is missing from the SDK. How do I point it at a sandbox or local environment? Pass baseUrl — for example http://localhost:4000/beta. Everything else works identically. What happens on rate limits? The SDK throws RateLimitError with retryAfter (seconds). It does not retry automatically — wrap calls in your own retry logic if you need it.