@boltzpay/sdk package. Every public class, method, type, and error is documented here with exact TypeScript signatures.
Installation
BoltzPay class
The main entry point. Instantiate once and reuse across requests.Constructor
Methods
fetch(url, options?)
Fetch data from a paid API endpoint. Automatically detects the payment protocol, pays the required amount, and returns the response. If no payment protocol is detected, the request passes through as a normal fetch. Concurrent calls are serialized internally to prevent double-spend.
Returns:
BoltzPayResponse
Throws: ProtocolError, BudgetExceededError, NetworkError
quote(url)
Check the cost of a paid endpoint without paying. Probes the URL and returns pricing information.
Returns:
QuoteResult
Throws: ProtocolError with code protocol_detection_failed if the endpoint is free.
getBudget()
Get the current budget state, including limits, spending, and remaining amounts.
BudgetState
resetDailyBudget()
Reset the daily spending counter to zero. Call this at the start of each day if you manage budget resets manually.
getHistory()
Get all payment records. When persistence is enabled, history survives restarts (stored as history.jsonl, last 500 entries by default).
PaymentRecord, ordered chronologically.
getMetrics()
Compute aggregate metrics from payment history.
PaymentMetrics
exportHistory(format)
Export payment history as CSV or JSON string.
getCapabilities()
Return the configured network, supported protocols, payment readiness, chain namespaces, and cached wallet addresses.
getBalances()
Query USDC balance per chain from the wallet manager. Degrades gracefully: returns an empty object if credentials are missing or the query fails.
getWalletStatus()
Comprehensive wallet health check. Probes Coinbase CDP connectivity, fetches on-chain balances, checks Lightning (NWC) wallet connectivity and balance, and reports credential and budget status. This is the only method that actively tests connections — other methods use cached data.
WalletStatus
discover(options?)
Query the BoltzPay registry for paid API endpoints. Returns scored entries with health and protocol metadata. All filtering is server-side.
openSession(url, options?)
Opens a streaming MPP session with a payment channel. Requires a Tempo wallet.
Returns:
BoltzPaySession
Throws: ProtocolError, MppSessionBudgetError, ConfigurationError
wrapMcpClient(client)
Wraps a standard MCP Client with automatic MPP payment handling for -32042 errors. Requires at least one MPP wallet (tempo or stripe-mpp).
Returns:
WrappedMcpClient
Throws: ConfigurationError if no MPP wallet is configured
diagnose(url)
Run a full diagnostic on any API endpoint in under 2 seconds. Checks DNS resolution, HTTP reachability (GET and POST), protocol detection (x402/L402), format version, pricing, and latency. No credentials required.
Returns:
DiagnoseResult with url, dns, get, post, protocol, version, price, network, health ("paid" | "free_confirmed" | "dead" | "ambiguous"), and totalMs.
close()
Close open connections (NWC WebSocket, etc.). Call when done using the SDK instance.
on(event, callback)
Subscribe to SDK events. Returns this for chaining.
off(event, callback)
Unsubscribe from SDK events. Returns this for chaining.
Types
BoltzPayConfig
Configuration object passed to theBoltzPay constructor. All fields are optional.
BudgetConfig
"10.50") and number (10.50) for convenience. Strings must match the pattern ^\d+(\.\d{1,2})?$. The warningThreshold controls when the budget:warning event fires (e.g. 0.8 = 80% of the limit).
The satToUsdRate converts L402 satoshi payments to USD for budget accounting. At the default rate of 0.001 (1 sat = 100K/BTC), a 100-sat payment counts as $0.10 in the budget.
WalletConfig
All wallet types accept an optional
networks array to restrict which networks they can be used on.
FetchOptions
BoltzPayResponse
Returned byfetch(). Wraps the HTTP response with payment metadata.
QuoteResult
Returned byquote().
PaymentDetails
Attached toBoltzPayResponse.payment after a successful payment.
PaymentRecord
Stored in payment history. ExtendsPaymentDetails with additional fields.
PaymentMetrics
Returned bygetMetrics().
DryRunResult
Returned byfetch() when dryRun: true. Simulates the full payment flow without spending.
BudgetState
Returned bygetBudget().
undefined and spent values are Money.zero().
DiscoverOptions
DiscoveredEntry
BoltzPaySession
SessionEvent
VoucherInfo
SessionReceipt
BoltzPaySessionOptions
WrappedMcpClient
WrappedCallToolResult
McpPaymentReceipt
WalletStatus
Returned bygetWalletStatus().
Where
ConnectionStatus is:
LightningStatus is:
BoltzPayEvents
Event map for theon() method.
BudgetWarningEvent
BudgetExceededEvent
Re-exported types from @boltzpay/core
The SDK re-exports commonly used types so you do not need to install@boltzpay/core separately.
Money
Immutable value object representing a USD amount. Usesbigint internally for precision.
ChainNamespace
AcceptOption
A single payment option from a multi-chain endpoint.Other re-exports
Errors
The SDK wraps all internal errors. You only need to catch
BoltzPayError subclasses.Error hierarchy
All subclasses extend the abstractBoltzPayError, which adds code and statusCode to the native Error.