Skip to main content
Give customers a live balance and an Add credits button without building a billing screen. The Locus Pro Enterprise widget opens hosted Stripe Checkout, then refreshes the balance when payment completes. Use @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
Derive currentUser.id from your server session. Never send the secret key to the browser.
Tokens last at most one hour; use renewUserToken to refresh them.

Add the widget

Install the React package
Billing.tsx
The default top-up is $5. Set topupUsd or topupCredits to change the amount.

Show transaction history

Set showPerCallPricing 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
See Own transaction history for pagination and response fields.

Render the provider catalog

Show customers which tools they can use and what they cost:
Load the customer catalog
The helper loads the pages for you. Results include provider names, logos, allowed endpoints, and final credit prices. Variable-price tools are marked as dynamic.

Build your own balance UI

Custom balance hook
Render the loading and error states alongside the balance.

Customization

The widget also supports checkout lifecycle callbacks, top-up metadata, and session binding.

Next steps