BuyerAgent applies two independent spend controls that protect your account from runaway costs. These controls operate at the x402 client layer, which means they fire before a partially signed transaction is ever created — a payment that fails a limit is never submitted to Blocky402 or Hedera. Both limits are expressed as bigint atomic units (tinybars for HBAR, or the smallest denomination of your HTS token), so no floating-point conversion touches your budget math.
Per-Call Cap: maxPerCall
The per-call cap is a hard upper bound on any single payment. If a seller’s 402 Payment Required response carries an amount greater than your maxPerCall value, the x402 spend control rejects it immediately — the request is aborted and your balance is untouched.
- SDK: pass
maxPerCall(bigint) to theBuyerAgentconstructor. - CLI: pass
--max-call <HBAR>to any command (default0.05HBAR).
Session Budget: sessionBudget
The session budget is the total your agent may spend across all calls during a single process lifetime. Before signing any payment, the agent checks whether amount ≤ remaining, where remaining = sessionBudget − totalSpent. If the payment would exceed the remaining budget, the agent rejects the 402 and never signs.
- SDK: pass
sessionBudget(bigint) to theBuyerAgentconstructor. - CLI: pass
--budget <HBAR>to any command (default0.5HBAR).
BuyerAgent instance. For long-running agents you can create a new instance at the start of each job or conversation turn to get a fresh budget.
What Happens When a Limit Is Hit
When every payment option in a402 response exceeds your remaining session budget, the agent emits a failed event with the message:
PaidResult with amount: null, settlement: null, and status reflecting the seller’s original 402 status code. Your account is not charged.
Failed seller responses (4xx or 5xx after the payment was sent) are also never charged. Blocky402 only co-signs and submits the Hedera transfer after the seller returns a 2xx. If the seller’s handler throws an error, the partially signed transaction is discarded and no funds move.
Setting Budgets in Code
buyer-with-budgets.ts
Asset Filtering
By default,BuyerAgent only accepts payment requests denominated in HBAR (asset id 0.0.0). Any 402 response that asks for a different asset is silently filtered out before spend controls even run.
To use the TOLL settlement token instead, pass its HTS token id when constructing the agent:
toll-asset.ts