Why budget control matters
An AI agent calling paid APIs in a loop can rack up costs fast. Budget control lets you:- Cap total spend per session
- Set per-domain limits (e.g., max 100 sats/session on
api.weather.com) - Receive a callback before each payment
- Get a full spending report at any time
Global budget
- TypeScript
- Python
priceSats field and it would exceed the remaining budget, the client throws BudgetExceededError before paying — no satoshis are spent.
Per-domain budget
- TypeScript
- Python
Callbacks
- TypeScript
- Python
onBudgetExceeded / on_budget_exceeded is called just before BudgetExceededError is thrown — useful for logging or alerts.
Spending report
- TypeScript
- Python
spendingReport() returns null / None when no budget is configured.
Handling BudgetExceededError
- TypeScript
- Python