The x402 protocol handles HOW agents pay. x402-cfo handles WHETHER they should — with pre-payment anomaly detection (enforce/review/off), multi-agent budget pools with fleet policy inheritance, and proof metrics.
131 tests · Zero dependencies · Spend control plane for autonomous agents
import { AgentCFO, JsonFileStorage } from 'x402-cfo'; const agent = new AgentCFO({ wallet: myX402Wallet, budget: { hourly: 5, daily: 50, session: 200 }, policy: { maxPerRequest: 2.00, allowedCurrencies: ['USDC'] }, storage: new JsonFileStorage('./ledger.json'), // Survive restarts }); // React to financial events agent.events.on('budget:warning', ({ window, percentUsed }) => { console.warn(`⚠️ ${window} budget at ${(percentUsed * 100).toFixed(0)}%`); }); agent.events.on('anomaly:blocked', ({ amount, baseline, multiplier }) => { console.warn(`🛡️ Blocked: $${amount} (${multiplier.toFixed(1)}× baseline $${baseline.toFixed(2)})`); }); // Drop-in fetch — auto-handles 402 → policy → budget → pay → log const res = await agent.fetch('https://api.chaindata.xyz/v1/prices'); agent.estimateCost('https://api.chaindata.xyz/v1/prices'); // → { mean: 0.25, p50: 0.24, p95: 0.38, stddev: 0.05, samples: 47 }
Watch an AI agent make payments, hit a 40× price spike in enforce mode, then switch to review mode. Every decision has a structured reason — no mystery 402s.
Every 402 response triggers a controlled decision process — not a blind payment. No money moves until every gate passes.
Coinbase AW, the Bazaar, and ClawRouter handle payments. x402-cfo is the independent spend control layer.
| Coinbase AW | Bazaar | ClawRouter | x402-cfo | |
|---|---|---|---|---|
| Budget enforcement (multi-window) | Session only | — | — | ✓ |
| Cost policies (allowlist, blocklist) | Basic | — | — | ✓ |
| Pre-payment anomaly detection (EWMA + z-score) | — | — | — | ✓ |
| Anomaly modes: enforce / review / off | — | — | — | ✓ |
| Fleet policy inheritance (org defaults + per-agent overrides) | — | — | — | ✓ |
| Structured caller feedback (lastDecision) | — | — | — | ✓ |
| Proof metrics (protectedSpend, anomalyBlocks) | — | — | — | ✓ |
| Default safety cap ($2.00 maxPerRequest) | — | — | — | ✓ |
| Multi-agent budget pools (game theory) | — | — | — | ✓ |
| Cost-optimal payment routing | — | — | — | ✓ |
| Full audit ledger with export | — | — | — | ✓ |
| LangChain / CrewAI / MCP integrations | — | — | — | ✓ |
Zero runtime dependencies. 131 tests. Pre-payment anomaly blocking, fleet policy inheritance, and proof metrics.
The npm package works standalone forever. The dashboard gives you centralized control.
One line to connect:
const agent = new AgentCFO({ wallet: myWallet, budget: { hourly: 5, daily: 50 }, // Add this line to sync to the dashboard: sync: { apiKey: 'your-api-key' }, });
Install x402-cfo. Give your agent a budget, a policy, and a ledger.