Skip to main content
Complete API reference for the @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

See BoltzPayConfig for the full configuration type.
Coinbase credentials are optional at construction time. Read-only methods (quote, getBudget, getHistory, getCapabilities, discover) work without them. Payment methods (fetch) require credentials and will throw at execution time if missing.

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.
Returns: 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).
Returns: Array of PaymentRecord, ordered chronologically.

getMetrics()

Compute aggregate metrics from payment history.
Returns: 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.
Returns: 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.
See BoltzPayEvents for the complete event map.

off(event, callback)

Unsubscribe from SDK events. Returns this for chaining.


Types

BoltzPayConfig

Configuration object passed to the BoltzPay constructor. All fields are optional.

BudgetConfig

Budget amounts accept both string ("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 = 0.001, 0.001, ~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 by fetch(). Wraps the HTTP response with payment metadata.

QuoteResult

Returned by quote().

PaymentDetails

Attached to BoltzPayResponse.payment after a successful payment.

PaymentRecord

Stored in payment history. Extends PaymentDetails with additional fields.

PaymentMetrics

Returned by getMetrics().

DryRunResult

Returned by fetch() when dryRun: true. Simulates the full payment flow without spending.

BudgetState

Returned by getBudget().
When no budget is configured, limits and remaining values are undefined and spent values are Money.zero().

DiscoverOptions


DiscoveredEntry


BoltzPaySession


SessionEvent


VoucherInfo


SessionReceipt


BoltzPaySessionOptions


WrappedMcpClient


WrappedCallToolResult


McpPaymentReceipt


WalletStatus

Returned by getWalletStatus().
Where ConnectionStatus is:
And LightningStatus is:

BoltzPayEvents

Event map for the on() 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. Uses bigint 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 abstract BoltzPayError, which adds code and statusCode to the native Error.

Error codes

Catching errors

By class (instanceof)

By code (switch)


Constants