Budget Accounts
Budget Accounts solve the number one problem with autonomous agent payments: trust. Nobody wants to hand an AI agent a private key without guardrails. Budget Accounts wrap the x402 client with spending controls so agents can pay for APIs within limits you define.
Best Fit
Use Budget Accounts when:
- an AI agent needs to spend money autonomously
- you want hard limits on total spend, per-request cost, or hourly rate
- you need a domain allowlist to restrict which APIs the agent can pay
- you want a payment ledger for auditing agent spending
Minimal Example
What This Does
- Wraps
wrapFetchwith budget enforcement viaonPaymentRequired - Before signing any payment, checks: total budget, per-request cap, hourly limit
- If any limit is exceeded, throws
X402Errorwith codeamount_exceeds_max - After payment, records amount, domain, network, and timestamp in the ledger
- Exposes real-time spend tracking via
spent,remaining,payments,hourlySpend
Full Configuration
Spend Tracking
Error Handling
When a budget limit is hit, the SDK throws before signing — no money is spent:
Domain Allowlist
When allowedDomains is set, the agent can only pay APIs on those domains. Subdomains are included automatically.
Combining with Other Features
Budget Accounts work with all SDK features:
When To Use Something Else
- If you don't need spending limits, use wrapFetch directly
- If you need UI-level payment controls, use useX402Payment with
onPaymentRequired - If you want per-request approval (not automated), use Pre-Payment Inspection