Skip to main content
Use @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
Use a secret key for trusted server operations and a scoped Agent Connection for agent execution. This package runs on your server. For browser UI, use the widget.

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 both credentials:manage and credits:move:
Create a scoped connection
Save connection.credential securely. It is revealed only on creation or rotation. Use it in a separate runtime client:
Use the connection in your runtime
Use 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
Framework integrations covers OpenAI, Anthropic, Google, Vercel, LangChain, LlamaIndex, CrewAI, AutoGen, Mastra, and raw MCP.

balance()

Check pool and customer balances

searchTools()

Find enabled tools by describing a capability:
Search enabled tools
Results include the execution slug, input schema, example arguments, and pricing. Passing user also applies that customer’s tool policy.

ledger()

Read usage with customer and attribution filters:
Read customer usage
Read 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
Transfers cannot overdraw the source account. Supply an idempotencyKey when retrying the same transfer.

topup()

Create a hosted Stripe Checkout session:
Create a top-up session
Omit 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
Derive the user ID from your server session. Send the token to that user’s browser and keep the secret key on the server.

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

Configure the client
See the API reference for complete request and response contracts.