Skip to main content
The Locus Pro Enterprise widget gives customers a live balance and an Add credits button, so you don’t have to build a billing screen. Customers see their balance and your prices. Your costs and margins stay private.

How it works

Your server mints a short-lived token for the signed-in customer. The widget uses that token and your publishable key to load the customer’s balance. When the customer adds credits, hosted Stripe Checkout takes the payment, and the widget refreshes the balance once payment completes. Your secret key never reaches the browser. Use @withlocus/credits-react in React or @withlocus/credits-js in any web app.

Mint a token on your server

Authenticated server route
Derive currentUser.id from your server session. Never send the secret key to the browser.
Tokens last at most one hour. Pass a renewUserToken callback to fetch a fresh one.

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

In the plain JavaScript widget, set showPerCallPricing: true to show the customer’s five most recent charges, top-ups, allocations, and refunds. The history refreshes with the balance. The React package does not render history yet. For React or other custom UI, call Own transaction history with the same publishable key and user token.

Render the provider catalog

Show customers which tools they can use and what they cost:
Load the customer catalog
fetchCatalog loads every page of results 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

Other options hide the purchase button, change its label, set Checkout return pages, and style the React container. The widget also supports checkout lifecycle callbacks, top-up metadata, and session binding.

Next steps

Node SDK

Mint tokens and charge usage from your server.

Funding & billing

Choose how customer balances are funded.