Constructor Options
{} creates a read-only instance (explore mode).
Credentials
Coinbase CDP (x402 protocol)
The three Coinbase fields must all be provided together. If any are missing, the SDK runs in explore mode:quote(), discover(), diagnose(), getBudget(), and getHistory() work normally, but fetch() will fail on paid endpoints.
@coinbase/cdp-sdk) is loaded lazily. It is only imported when the first payment is executed, not at construction time.
NWC (L402 protocol)
Adding an NWC connection string enables the L402 (Lightning) adapter alongside x402. The SDK auto-detects which protocol each endpoint uses.The NWC connection string must start with
nostr+walletconnect://. Get one for free from Coinos, Primal, or any wallet listed on nwc.dev. See Installation for step-by-step instructions.Wallets
Thewallets array configures multiple payment methods. Each wallet targets a specific protocol. The SDK selects the appropriate wallet based on endpoint protocol detection.
Legacy flat credentials (
coinbaseApiKeyId, nwcConnectionString at root level) still work for backward compatibility. The wallets array is preferred for new integrations.Registry URL
The registry is the source of truth fordiscover(). Points to the BoltzPay registry by default.
Session Deposit
Cap the maximum deposit per payment session. Useful for controlling exposure on long-running agents.min(available budget, sessionMaxDeposit, user-provided maxDeposit). Defaults to $10 if no constraints are set.
Budget
Set spending limits to protect against unexpected costs. All amounts are in USD.Configuration
Amounts accept both strings (
"5.00") and numbers (5). All fields are optional. If no budget is configured, payments proceed without caps.
How Enforcement Works
Budget checks run before every payment:- Checks
perTransaction: rejects if the amount exceeds the per-request cap. - Checks
daily: rejects ifdailySpent + amount > daily limit. - Checks
monthly: rejects ifmonthlySpent + amount > monthly limit.
BudgetExceededError is thrown and the payment is not executed. After a successful payment, the amount is recorded against both daily and monthly totals.
Checking Budget State
getBudget() returns a BudgetState:
Resetting Budget
Budget state is in-memory by default. Enable persistence to keep budget and history across restarts:When persistence is enabled, budget counters and payment history survive process restarts. Daily budgets auto-reset on calendar day change. Files are stored as
budget.json and history.jsonl in the configured directory.Events
Subscribe withagent.on(event, listener).
payment
Emitted after every successful payment.
budget:warning
Emitted when spending reaches the warningThreshold (default 80%) of a daily or monthly limit.
budget:exceeded
Emitted when a payment is blocked because it would exceed a budget limit.
error
Emitted on any error during payment (budget exceeded, protocol error, network error).
session:open
Emitted when a payment session channel is opened.
session:voucher
Emitted when a voucher is issued within a session.
session:close
Emitted when a session is closed and the channel is settled.
session:error
Emitted on session-level errors (channel failures, deposit errors).
mcp:payment
Emitted when a payment is triggered by an MCP tool call.
Payment History
The SDK keeps a history of payments (last 500 by default). When persistence is enabled, history survives restarts. Returnsreadonly PaymentRecord[] (same type as the payment event payload).
Multi-Chain
Supported Chains
All payments use USDC as the settlement currency, regardless of chain.Auto-Negotiation
When you callagent.fetch(url), the SDK probes the endpoint, receives one or more accept options (each specifying a chain, amount, and payment address), and selects the best match.
The selection algorithm (selectBestAccept):
- Filters out unsupported chains.
- If
preferredChainsis set, narrows to those (falls back to all supported if none match). - Picks the cheapest option among remaining candidates.
- On ties, EVM wins over SVM.
Chain Preferences
Set a default preference at construction time:preferredChains):