Agent Spend Control Plane

Your AI agent
needs a CFO.

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

agent.ts
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 }

See the control plane in action.

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.

👋 Press Start to watch an AI agent make x402 payments.
Total Spent
$0.00
Protected Spend
$0.00
Anomaly Mode
enforce
Budget Left
$10.00
Decision Log — lastDecision() output
Press Start to begin the simulation…

Six-step decision pipeline.

Every 402 response triggers a controlled decision process — not a blind payment. No money moves until every gate passes.

1
402 Received
API requires payment
2
Policy Check
URL, currency, network, amount cap
3
Anomaly Gate
EWMA + z-score. Enforce blocks, review flags.
4
Budget Check
Hourly, daily, session limits
5
Pay & Retry
Wallet signs, request retries
6
Log & Analyze
Ledger + analytics + lastDecision()

The ecosystem pays.
Nobody watches the money.

Coinbase AW, the Bazaar, and ClawRouter handle payments. x402-cfo is the independent spend control layer.

Coinbase AWBazaarClawRouterx402-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

Spend control for autonomous agents.

Zero runtime dependencies. 131 tests. Pre-payment anomaly blocking, fleet policy inheritance, and proof metrics.

🛡️
Pre-Payment Anomaly Detection
EWMA + Welford's z-score. Three modes: enforce blocks, review flags, off bypasses. wallet.pay() never called during a block.
📡
lastDecision()
Structured caller feedback. Returns { gate, reason, url, amount }. Distinguishes server 402 from locally blocked.
👥
Fleet Policy Inheritance
Org-level defaults with per-agent overrides. Scalars replace, arrays replace entirely. checkPolicy() enforces the merge.
📊
Proof Metrics
protectedSpend, anomalyBlocks, anomalyFlags, policyDenials. Ledger-derived. Not deduplicated across retries.
🔒
Default Safety Cap
$2.00 maxPerRequest when you don't set one. Protects during anomaly warm-up. Easy to override.
🏦
Budget Enforcement
Per-request, hourly, daily, and session limits. Multi-agent pools with game-theoretic rebalancing.
📋
Cost Policies
URL allowlists, blocklists, currency restrictions, network filters, and per-request caps.
📒
Audit Ledger
Every decision logged with timestamp, amount, URL, status, reason, and anomaly context. JSON + CSV export.
Event System
Typed events: payment:success, payment:denied, budget:warning, anomaly:blocked, anomaly:flagged.
🛤️
Payment Routing
When x402 offers multiple options, pick the cheapest by asset price, network fees, and settlement speed.
📡
Event Sink
Structured event log with circular buffer. Transport stub for future hosted integration.
🔌
Framework Integrations
Drop-in tools for LangChain, CrewAI, MCP, and Express middleware with live dashboard.

Free to run. Paid to watch.

The npm package works standalone forever. The dashboard gives you centralized control.

Open Source
$0/forever
For developers and solo agents
  • Unlimited agents
  • Budget enforcement
  • Cost policies + default safety cap
  • Pre-payment anomaly detection (enforce/review/off)
  • Fleet policy inheritance
  • Proof metrics + lastDecision()
  • Local audit ledger + JSON/CSV export
  • Event sink (local buffer)
npm install
Enterprise
Custom
For regulated environments
  • Everything in Hosted
  • Compliance-grade audit reports
  • SSO / SAML integration
  • Custom retention policies
  • SLA and priority support
Contact us →

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' },
});

Your agent is spending money.
Shouldn't someone be watching?

Install x402-cfo. Give your agent a budget, a policy, and a ledger.