@withlocus/credits to call tools and build usage billing in Locus Pro Enterprise. The SDK handles idempotency, retries, and cost headers so your application can work with the result.
Make a call
1
Install the SDK
The current release of
@withlocus/credits is 0.5.2.Terminal
2
Call an enabled tool
Enable
tavily/search in your workspace and fund the balance, then:Search and read the cost
call()
Pass a provider/endpoint slug and the provider’s request body.
Every method returns
cost.credits and cost.balance as exact decimal strings. Secret-key calls also include cost.baseUsd.
To bill an end user and tag the call:
Charge a customer
The SDK generates one idempotency key per call and reuses it during retries. If your application retries after a restart, supply the original key.
Agent connections
Create an execution credential on your trusted backend using a secret key with bothcredentials:manage and credits:move:
Create a scoped connection
connection.credential securely. It is revealed only on creation or rotation. Use it in a separate runtime client:
Use the connection in your runtime
mode: "end_user" with externalUserId to bind a connection to one customer. Account and tool scope are fixed at creation. The API and dashboard also support per-connection pricing overrides, which the 0.5.2 typed helper does not expose.
The lifecycle methods are list(), get(id), rotate(id), and revoke(id).
Rotation needs both scopes above; listing, reading, and revoking need
credentials:manage. See Connect an agent for setup
and budgets.
Framework MCP presets
Presets turn a connection into the configuration your framework expects:Framework presets
balance()
Check pool and customer balances
searchTools()
Find enabled tools by describing a capability:
Search enabled tools
user also applies that customer’s tool policy.
ledger()
Read usage with customer and attribution filters:
Read customer usage
page.entries and pass page.nextCursor as cursor for the next page.
allocate() / deallocate()
Move credits between the platform pool and a customer:
Move credits
idempotencyKey when retrying the same transfer.
topup()
Create a hosted Stripe Checkout session:
Create a top-up session
externalUserId to fund the platform pool; include it to fund a customer. Send either usd or credits as an exact decimal string.
Use topupConstraints() for current limits and topupStatus(session.sessionId) to confirm that payment has completed. See Funding & billing for funding options.
endUserToken()
Mint a short-lived token for the widget from an authenticated server route:
Mint a browser token
End-user catalog
The browser packages@withlocus/credits-js and @withlocus/credits-react export fetchCatalog for customer-facing tool lists. It returns allowed tools and final prices without exposing your costs or margins. See Render the provider catalog.
Errors
Handle insufficient credits
Constructor
Client options and defaults
Client options and defaults
Configure the client