Skip to main content
The @velobaseai/billing package wraps the Velobase control-plane: customer deposits, balances, ledgers, the freeze / consume / deduct primitives, usage queries, and billing receipts. It ships ESM and CommonJS builds with full TypeScript types.
The SDK is for the billing control-plane. To make model calls, point the OpenAI SDK at the gateway, see OpenAI-Compatible Gateway.

Install

Initialize

Deposit credits to a customer

amount is a positive integer number of credits. 1 credit = 1 micro-USD, so 1 USD = 1,000,000 credits.
Pass idempotencyKey so a retry never double-credits (use your payment event id in production):

Read a balance

get() returns the customer with their wallets, each broken down by source:

Read the ledger

Billing primitives

For metering work you price yourself (not model calls, which bill automatically), use freeze → consume for unknown-cost work, or deduct for fixed-cost work. All amounts are integer credits.

Usage and receipts

Query per-call gateway usage and fetch the billing receipt for a single call:

Gateway helpers

The package also exports a GATEWAY_HEADERS constant naming the billing headers the gateway returns on each billed call (X-Velobase-Cost-Credits, X-Velobase-Balance-Credits, and friends), and parseGatewayInsufficientBalance(), which parses a gateway 402 response so you can drive a paywall from the required / available credit amounts:

Errors

All failures throw a VelobaseError (check with isVelobaseError(err)), carrying the HTTP status, error type, and server request_id. See Errors.