Core concepts
Creating a wallet
UsegetOrCreate to ensure a wallet exists for a customer + currency pair. If one already exists, it is returned; otherwise a new wallet with zero balance is created.
Listing wallets
All wallets
The org is inferred from your API key.Filter by customer
You can pass an optionalcustomer_id query parameter to filter wallets:
Getting a wallet
Fetching a single wallet also returns its virtual accounts.Crediting a wallet
Credit adds funds to the wallet. Every credit creates two ledger entries (debit provider, credit wallet) and fires acustomer.wallet.topped_up webhook.
Entry types for credits
Debiting a wallet
Debit removes funds from the wallet. Returns a 402 Payment Required error if the balance is insufficient.Entry types for debits
Transaction history
List paginated ledger entries for a wallet.Virtual accounts
Virtual accounts are dedicated bank accounts (via Paystack, Flutterwave, or Monnify) that automatically credit the wallet when a customer deposits funds. This enables self-service top-ups without requiring API calls from your backend.Create a virtual account
List virtual accounts
Prepaid billing integration
Wallets are the foundation of Prepaid Billing. When a customer subscribes to a prepaid plan:- Monigo auto-creates a wallet in the plan’s currency
- At period-end, Monigo debits the wallet atomically and creates a
paidinvoice - If the balance is insufficient, the subscription is paused and a
subscription.prepaid_balance_insufficientwebhook fires - When you credit the wallet and the balance covers the outstanding invoice, Monigo auto-resumes the subscription
Real-time billing
A plan withbilling_mode: "realtime" debits the wallet in near-real-time (within ~5 seconds) as usage accrues, rather than once at the end of the period. It supports every pricing model (per_unit, tiered, volume, package, cap): as events arrive, Monigo recomputes the cumulative charge for the period and debits the wallet for the marginal difference.
- Continuous metering — each new batch of usage triggers a reconcile that charges only the incremental amount, so the wallet always reflects what the customer owes so far.
- Pause on empty — when the wallet can no longer cover the next marginal charge, the subscription is paused, metering stops, and a
subscription.prepaid_balance_insufficientwebhook fires. - Auto-resume on top-up — crediting the wallet reactivates the subscription, reconciles any usage that accrued while paused, and resumes metering automatically.
- One paid summary invoice per period — at period-end Monigo emits a single
paidinvoice that itemizes the period’s usage per metric, with the total equal to what was already debited in real time. No additional debit happens at close — the invoice is purely a reporting artifact.
collection plans (a realtime payout plan is rejected). As with prepaid, you only need to handle wallet top-ups — metering, pausing, resuming, and the period-end invoice are all automatic.
Inline funding session
When a customer wants to top up their own wallet directly in your portal UI (without a server-side redirect), set"inline": true in the funding request. Monigo returns a WalletFundingSession containing only publishable credentials — no secret keys are ever exposed.
Request
Response — WalletFundingSession
Using the session in the browser
Pass the session fields directly to your provider’s inline SDK. Only the fields relevant to the activeprovider will be populated.
Drop-in wallet widget (inline funding + live balance)
The<WalletWidget> component is a self-contained UI that shows the customer’s live
balance and opens the configured payment provider’s inline checkout when they click
Fund wallet. Drop it anywhere inside a <MonigoProvider> — no extra state
management required.
Installation
Usage
Minting a portal token (server-side)
MonigoProvider expects the raw token string (PortalToken.token) — not the
full object returned by the SDK. Mint it on the server so your secret API key is never
exposed to the browser.
TypeScript (SvelteKit server load)
Props
What the widget does
- Live balance — polls
/portal/wallets/{walletId}everypollIntervalMsmilliseconds and formats the balance withIntl.NumberFormat. - Inline checkout — calls the portal funding endpoint to get a
WalletFundingSessionand launches Paystack, Stripe, Flutterwave, or Monnify inline. Only the relevant provider fields are populated (see Inline funding session). - Auto-refresh — after a successful payment, the widget immediately polls for the updated balance, so the customer sees the new total without a page reload.
- Usage debits — as your backend debits the wallet for metered usage (via
wallets.debit()), the polling loop picks up the reduced balance automatically.
Full working example
Seeplatform/samples/ai-agent-wallet for a complete
SvelteKit app that mints a portal token on the server, renders the widget, and
includes a form action that debits the wallet to simulate agent token usage.
Webhook events
Related
- Prepaid Billing — end-to-end prepaid subscription flow
- Invoice Lifecycle — invoice states and transitions
- Subscription Lifecycle — pause, resume, and cancel behavior
- Webhooks — receiving billing events

