@alguna/sdk is the official TypeScript client for the Alguna Public API. It exposes one typed method per endpoint — customers, products and plans, subscriptions and versions, usage events and metrics, credits and wallets, invoices, payments, checkout and portal sessions — with request and response types generated from the versioned OpenAPI spec. Use it from Node services where you would otherwise hand-write HTTP calls; it sets the Authorization and Alguna-Version headers, maps failed responses to typed errors, and accepts idempotency keys on every write. The objects it manipulates are described in How Alguna works.
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
- Create an API key in your dashboard (format
id.secret— a server secret). - Instantiate the client with the key. Every request it makes carries
Authorization: Bearerand pins the API version via theAlguna-Versionheader. - Call resources (
alguna.customers,alguna.subscriptions, …). Methods return typed response objects; failed requests throw typed errors.
Installation
Quick start: customer → subscription → portal session
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 exposes one field per API resource. Generation enforces parity with the versioned spec, so every public operation has a method. Highlights:
Plus
products, plans, bundles, creditNotes, payments, refunds, integrations, insights, revenueSchedules, merchants and tax. Every method name follows the operation it wraps; the full list is in the generated API reference.
Request and response types are exported from the package root:
Pagination & filtering
List endpoints acceptlimit, offset, sort (in field:order format), and the same filter parameters as the HTTP API:
Error handling
Failed requests throw typed errors, all extendingAlgunaError:
A
422 validation response surfaces as a generic ApiError, not ValidationError — check statusCode rather than relying on the class alone.
All errors expose statusCode, code, and requestId (the X-Request-Id of the failed response). Include the requestId when contacting support about a failed call. Status meanings and retry guidance are on the Errors page.
Idempotency
Mutating methods accept an optional trailingoptions 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. Which version am I on, and how does it relate to the API version? Two different things, deliberately decoupled. The package version is the npm release of@alguna/sdk — read it from your lockfile, npm ls @alguna/sdk, or npm view @alguna/sdk version for the latest published. The API version is the date you pass as apiVersion, and it is the only thing that decides request and response shapes. Upgrading the package never moves you to a different API version: a newer SDK still speaks the date you pinned. Upgrade the package to pick up new endpoints, types and fixes; change apiVersion deliberately, as its own change, following Versioning.
Is @alguna/checkout-sdk the same package?
No. @alguna/sdk is the server-side API client; @alguna/checkout-sdk is the browser package that mounts a checkout session in your page. They version independently and are installed separately.
How do I point it at a sandbox or local environment?
Pass baseUrl with the same path prefix the default carries — for example http://localhost:4000/beta for a local API, or the sandbox host api.sandbox.alguna.io with a sandbox API key. Everything else works identically. Sandbox and production are separate environments with separate keys; see Base URLs.
Is there a Python SDK?
Not yet. Every page in this documentation that shows a cURL request also shows the equivalent requests call, and the Developer quick start walks the whole flow in Python.
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.