@monigo/sdk) is a thin, zero-dependency wrapper around the Monigo REST API. It follows a Stripe-style resource pattern — each API resource group is a typed service object hanging off the client. It ships as dual ESM and CommonJS bundles and works natively in Node.js (≥ 18), browsers, Cloudflare Workers, Bun, and Deno.
Installation
fetch support. For Node.js 16, pass a fetch polyfill via the fetch option — see Client configuration below.
Quick start
Client configuration
Custom base URL
For self-hosted deployments or a local development server:Polyfilling fetch (Node.js 16)
Testing
Thefetch option makes the client fully testable without a real server:
Idempotency
Every POST, PUT, and PATCH request to the Monigo API must include anIdempotency-Key header. The SDK handles this automatically — crypto.randomUUID() is called for each mutating request. To supply your own key (recommended for retryable operations), pass idempotencyKey in the optional options argument:
Error handling
All methods return aPromise. A 4xx or 5xx response throws a MonigoAPIError with a typed status code, message, and optional field-level details.
Static type-narrowing guards
Events
Theclient.events service handles usage event ingestion and event replay.
Ingest events
idempotency_key. A single call can include up to 1,000 events.
Replay events
Replay reprocesses all events in a time window to correct rollups after an outage or metric definition change.Customers
Metrics
A metric defines what gets counted and how raw event values are aggregated.Plans
A plan combines billing period, currency, and one or more prices. Each price links a metric to a pricing model.Pricing models
Plan types and billing periods
Subscriptions
A subscription links a customer to a plan and defines the current billing period.Payout accounts
Payout accounts are bank or mobile-money accounts scoped to a customer. All methods takecustomerId as the first argument.
Invoices
Invoices are generated from subscriptions and contain line items derived from the customer’s usage in the billing period.All monetary amounts (
subtotal, total, unit_price) are returned as decimal strings (e.g. "1500.00") to preserve precision across currencies.Usage
Query aggregated usage rollups to see how much a customer has consumed in a period.Portal tokens
Portal tokens grant an end-customer read-only access to their invoices, payout slips, subscriptions, and payout accounts in the Monigo hosted portal. Theportal_url on the returned token is what you share with your customer — embed it in an email, redirect the browser, or open it inside an iframe.
Create a portal link
expires_at (ISO 8601) for a time-limited link:
List tokens for a customer
customerId accepts either a Monigo UUID or the customer’s external_id.
Revoke a token
Wallets
Customer wallets hold prepaid balances. They are the foundation of Prepaid Billing and can also be used for any credit/debit workflow. See the full Wallet Management guide for details.Wallet constants
All wallet amounts (
balance, reserved_balance, ledger amount) are decimal strings to preserve precision.Example programs
The SDK ships with seven runnable example programs underexamples/:
Run any example:
MONIGO_API_KEY from the environment and accepts an optional MONIGO_BASE_URL to point at a local server.
Testing
The SDK ships 98 unit tests with zero external dependencies. Each test uses a mockfetch implementation injected via the fetch option:

