@unitpay/node is the server-side SDK for UnitPay — the billing engine where dollars and credits are both first-class. Use it from your backend to read customers, subscriptions, invoices, payment methods, and credit wallets, track usage, and mint the short-lived portal tokens that power your customer-facing UI.
Installation
Instantiate
Pass your secret key, or setUNITPAY_API_KEY and let the SDK read it:
new UnitPay() throws if no key is found. Passing a portalToken also throws — those belong in @unitpay/react.
The config accepts apiKey, baseUrl, timeout (ms, default 30000), retries (default 2), idempotencyKeyPrefix, and a custom fetch.
What it covers
UnitPayIngestion batches and flushes events. The customer-facing UI — subscribe, checkout, gates, and balances — lives in @unitpay/react.
Retries, idempotency & typed errors
Every request retries transient failures (429, 409, 5xx, and network errors) with jittered exponential backoff, honoring Retry-After. POST/DELETE requests carry an idempotency key so retries are safe. Failures throw a typed error (AuthenticationError, RateLimitError, ValidationError, …) you can discriminate with instanceof. Verify incoming webhooks with the static UnitPay.verifyWebhook(body, headers, secret).
Next steps
Quickstart
Track usage and run credits end to end.
Authentication
Secret keys, and sandbox vs live.
React SDK
Build the customer-facing billing UI.
How it works
The two paths and the two verbs.