@withlocus/credits-react in React or @withlocus/credits-js in any web app. Customers see their balance and your prices; your costs and margins stay private.
Mint a token on your server
The widget needs your publishable key and a short-lived token for the signed-in user:Authenticated server route
renewUserToken to refresh them.
Add the widget
- React
- Plain JavaScript
Install the React package
Billing.tsx
topupUsd or topupCredits to change the amount.
Show transaction history
SetshowPerCallPricing to display the five most recent charges, top-ups, allocations, and refunds. The history refreshes with the balance and shows only the signed-in user’s activity.
For custom React UI, use fetchLedger:
Load transaction history
Render the provider catalog
Show customers which tools they can use and what they cost:Load the customer catalog
Build your own balance UI
Custom balance hook
Customization
Widget options and defaults
Widget options and defaults
The widget also supports checkout lifecycle callbacks, top-up metadata, and session binding.
Next steps
- Funding & billing: choose how customer balances are funded.
- SDK reference: mint tokens and charge usage from your server.