Brave lets agents pay $0.005 per search. I built a gate that stops yours from paying 500 times.
On 12 November 2026, Brave made its Search API payable over x402: $0.005 per search, USDC on Base, no account or API key (Brave blog, 12/11/2026). A no-payment probe the next day confirmed the shape: a 402 response with a base64 payment-required header, amount 5000 base units USDC = $0.005, EIP-3009, expiry 300 seconds, exactly one payment option (Frank Chu, dev.to, 13/11/2026).
That price is the trap. $0.005 is cheap per call, and nothing in the default setup stops an agent from paying it 500 times. 500 x $0.005 is $2.50, and every single payment is valid, under the cap, and to the right address.
The x402 client default cap is $1 per payment (set 18/08/2026, after a V12 audit published 22/10/2026 found the default client had no spending limit at all - a malicious server could demand a wallet's whole balance of a supported token). A $1 per-call cap does not stop 500 x $0.005. And a survey of 12 agent frameworks published 09/10/2026 found that 0 of 12 can cap what an agent spends in dollars on tool calls (survey). Token budgets cap model cost, not money the agent pays out.
I built a small tool that closes that hole from the buyer's side. It is called spendgate, and it is a local, zero-dependency TypeScript CLI. MIT licensed. No network, no wallet, no signing, no on-chain verification, no billing API. Before your agent signs any x402 payment, spendgate judges the request against a policy file you wrote, and every decision lands in an append-only, hash-chained receipt ledger.
The problem: a per-call cap cannot see a loop
The failure mode is not one big payment. It is many small valid ones. A search loop that runs 500 times costs $2.50 and nothing stops it, because each payment passes the $1 per-call cap on its own. The seller states a price per call; the buyer's cumulative budget is out of scope for the protocol itself.
So the question is not "is this one payment too big". It is "how much has this agent already paid today, to this vendor, for this tool, and does one more payment break the budget". That question needs a memory of past payments and a policy that adds them up. That is what spendgate is.
What it does
Five commands, one policy file, one ledger:
spendgate init # scaffold spendgate.json + empty ledger (refuses to overwrite)
spendgate simulate # dry-run one payment request against the policy, touch nothing
spendgate record # judge the request, then append the decision to the ledger
spendgate check # CI gate: replay the ledger, exit 1 on any violation
spendgate report # totals by vendor, tool and day, from the local ledger only
The policy file (spendgate.json) is plain data, not code: per-call max ($1.00 in the sample), per-day cap ($2.50), per-vendor and per-tool caps, a payee allowlist/denylist by wallet address and host, a require-approval threshold ($0.25), and lookalike detection (Levenshtein distance 1-2 on the address hex).
Verdict rules, in order, with every firing rule listed in the output:
- Payee or host on the denylist - DENY.
- Amount over the per-call max - DENY.
- Per-day cumulative + amount over the per-day cap - DENY.
- Per-vendor cumulative over the per-vendor cap - DENY.
- Per-tool cumulative over the per-tool cap - DENY.
- Payee is a lookalike of an allowlist address (1-2 characters different) - REVIEW.
- Allowlist non-empty and neither payee nor host is on it - REVIEW ("unknown payee").
- Amount over the require-approval threshold - REVIEW.
- Otherwise ALLOW.
Exit codes are made for scripts and CI: 0 ALLOW, 1 DENY, 3 REVIEW, 2 input error (check uses 0 OK / 1 violation / 2 input error). Amounts are compared in integer micro-dollars, so 500 x $0.005 is exactly $2.50 with no float drift.
Every decision is appended to a JSONL ledger with a SHA-256 hash chain (each line carries the previous line's hash). check recomputes every link and re-checks every ALLOW entry against the policy as of its own day, so a later edit or deletion is detectable. simulate never touches a wallet or signs anything.
The demo: 500 valid payments, then a DENY
The GIF above is a real terminal session, not a mockup. It runs against a synthetic Brave 402 fixture (payee address invented, amount 5000 base units USDC = $0.005 on eip155:8453, expiry 300s, one payment option - the exact public Brave shape). The date is pinned to 2026-11-14 so the cap accounting is reproducible.
One search is ALLOW:
$ spendgate simulate --file examples/brave-402.json
verdict: ALLOW
amount: $0.005 USDC (5000 base units, eip155:8453)
payee: 0xb1a9e00000000000000000000000000000000001
vendor: brave-search
tool: search
host: search.agent.s.brave.app
A payee one character off the allowlist is REVIEW, not a silent ALLOW:
$ spendgate simulate --file examples/brave-402.json --payee 0xb1a9e00000000000000000000000000000000002
verdict: REVIEW
reasons:
- payee 0xb1a9e00000000000000000000000000000000002 looks like allowlisted 0xb1a9e00000000000000000000000000000000001 (edit distance 1) - confirm the address before paying
exit: 3
A denylist payee is DENY. Then the loop:
$ for i in $(seq 1 500); do spendgate record --file examples/brave-402.json > /dev/null; done
500 payments recorded (each $0.005, ledger total $2.50)
$ spendgate simulate --file examples/brave-402.json # the 501st identical payment
verdict: DENY
reasons:
- per-day cap $2.50 would be exceeded ($2.50 spent + $0.005 = $2.51)
- per-vendor cap for brave-search ($2.50) would be exceeded ($2.50 spent + $0.005 = $2.51)
- per-tool cap for search ($2.50) would be exceeded ($2.50 spent + $0.005 = $2.51)
exit: 1
$ spendgate report
spend report (500 ledger entries; 500 ALLOW, 0 DENY, 0 REVIEW)
total spent (ALLOW only): $2.50 across 500 payments
by vendor:
brave-search $2.50
by tool:
search $2.50
by day:
2026-11-14 $2.50
$ spendgate check
check OK: 500 ledger entries, hash chain intact, no policy violations
That is the whole point: a per-call cap cannot see a loop. A cumulative cap can. The full transcript (93 lines, real CLI output) and the GIF are in demo/ in the repo.
The test suite is 40/40 passing (29 unit + 11 e2e, including the real-CLI 500-payment loop, a tampered ledger failing check, and a deleted middle line breaking the chain). CI is green on Node 20 and 22.
Install (from source only)
The npm package is not published yet, so for now install from source:
git clone https://github.com/techdevfun/spendgate.git
cd spendgate
npm install
npm run build
Requires Node.js 20 or newer, zero runtime dependencies. A clean install from source was measured on 14 November 2026 at 31 seconds (npm install + build + unit tests). Run it from the repo root, or npm link to make spendgate available everywhere.
How it compares
| Tool | What it does | Where it is weak (the wedge for spendgate) |
|---|---|---|
| x402 default client (Coinbase, since 18/08/2026) | $1 per-payment cap, USD stablecoins only | Per-call only. No cumulative budget (per-day / per-vendor / per-tool), no allowlist/denylist payee, no ledger, no CI gate. |
Stripe purl (CLI wallet, named by Brave) |
curl for paid endpoints; --max-amount caps one call |
One-call cap only. No cumulative sum, no policy file, no decision log, no lookalike blocking. A 500-search loop still settles $2.50 unopposed. |
| agent402-mcp |
AGENT402_MAX_PER_CALL (default $4) + opt-in session budget |
Tied to their MCP server; no per-vendor/per-day caps, no payee allowlist, no hash-chain ledger, no CI gate, no report. |
| sra-riskgate 0.10.1 (PyPI, closest rival) | Python SDK: check_payment() verdict before paying; per-payment cap, session budget, blocklist, new-payee hold, OFAC SDN snapshot (01/10/2026), depeg hold, lookalike detection, framework hooks |
Python SDK tied to frameworks, not a zero-dep framework-agnostic CLI; config lives in code, no declarative policy file with per-vendor/per-tool/per-day caps; no append-only hash-chain receipt ledger, no simulate dry-run CLI, no check CI gate, no report. Sources: PyPI and the Grok paying-agent test, dev.to 14/11/2026. |
| aibill (own tool, 02/11) | CLI that measures token/USD attribution per MCP tool/model call AFTER spending | Attribution after the fact, LLM/MCP cost only. It does not parse 402/payment requests, does not block before signing, and has no wallet/payee concept. Different axis: attribution vs pre-execution enforcement. |
Where rivals beat us
Honesty first: spendgate owns a narrow slice, and the rivals are real.
- sra-riskgate does OFAC sanctions screening, depeg detection, and framework hooks (AgentKit, LangChain, CrewAI) that spendgate will never do. If you need sanctions screening or a gate inside your framework code, it is the better tool for that job. Its lookalike detection and blocklist overlap with spendgate directly - spendgate only wins on the cumulative-cap slice, the audit trail, and the zero-dependency CLI form.
-
The x402 default client and
purlare the tools the payment actually flows through. spendgate sits beside them, not inside them - see Honest limits below. - agentbudget / TokenFence cap LLM token spend, which is a different budget from x402 payment money, but if your burn is model cost rather than vendor payments, they solve your actual problem and spendgate does not.
Honest limits
- A local gate only enforces payments routed through it. An agent that calls the payment client directly bypasses spendgate entirely. spendgate is a policy + audit layer, not an unbypassable enforcement boundary. It works when you make it the single choke point (a wrapper script, a team SOP) and when you reconcile the ledger against real balances. There is no "unbypassable" claim anywhere in the README or the help text, and there should not be.
- No on-chain verification, no billing API, no key custody, no sanctions/KYC screening. spendgate reads 402 JSON and a local ledger. It never verifies settlement on-chain, never reads a billing API, never holds a key, and never signs on your behalf. OFAC screening is sra-riskgate's job; spendgate only enforces an allowlist/denylist you declare yourself.
- The demo is fixture-only. The 402 fixture matches the public Brave shape exactly (5000 base units, EIP-3009, 300s expiry), but no live 402 was fetched from a real endpoint to cross-check the shape, and no real payment was ever made. The demo numbers come from the fixture and the sample ledger.
-
Display rounding: 2-decimal display rounds $0.005 to $0.01, so a report can show $0.02 for 3 x $0.005 ($0.015 exact). Correct rounding, but worth knowing if you check the math by hand. Exact amounts are shown in
simulateoutput. -
A failed
checkis noisy: one tampered ledger line produces 250+ violations because every later hash link breaks. The first violation names the root cause, but the log is long for a CI gate. - No savings percentage is promised anywhere. spendgate stops overspend against caps you set; it does not claim to save you any amount.
Why this shape
Brave's $0.005 per search is genuinely cheap, and that is exactly why the failure mode is invisible: no single payment looks wrong. The x402 default $1 cap protects you from one bad invoice, not from a loop of good ones. A cumulative budget, a payee policy, and a receipt ledger you can audit later are the missing pieces, and they fit in a zero-dependency CLI you can read in one sitting.
If your agent can pay for tools, give it a budget before it starts paying:
github.com/techdevfun/spendgate
Feedback welcome in the repo issues. The roadmap (grouped check output, exact-amount column in reports, a live no-payment probe to cross-check the fixture shape) is in the README.

Top comments (2)
nice build, the cumulative cap idea is clever
Thanks, Paras - glad that part landed. That was the whole bet behind the build: a per-call cap can't see a loop, so the budget has to remember what already got paid, per day, per vendor, and per tool. The Brave demo in the repo shows it concretely - 500 searches pass, the 501st gets denied at $2.51. If you try it on one of your own tools, I'd be curious which cap you'd set first - per-day, or per-vendor?