agent-x402

Pay per API call in USDC on Base — with a spend policy a prompt injection cannot bypass.

x402 turns a 402 into a signed USDC transfer, which means an agent can buy inference without an account. It also means an agent can spend money. This is the client that pays, and the policy that decides whether it may.

View on GitHub npm README

What it does

x402 v2, exact schemeEIP-3009 transferWithAuthorization, USDC on Base, 15-minute validity window.
Spend policyDaily cap, per-request cap, payment count, payee allow-list, blocked contracts, per-network cap.
Policy outside the modelThe rules are enforced in code before anything is signed.
Any endpointThe client is protocol-level, not vendor-specific.
MCP serverx402-balance, x402-quote, x402-pay and x402-policy as agent tools.
Audit trailEvery payment is recorded with its amount, model and time.

Usage

Create a walletax402 new
See the balanceax402 balance
Price a callax402 quote https://api.venice.ai/api/v1/chat/completions
Pay for a callax402 pay https://api.venice.ai/api/v1/chat/completions '{"model":"claude-haiku-5-5","messages":[{"role":"user","content":"hi"}]}'
Read the spendax402 policy

How it works

  1. Request the endpoint: a 402 comes back with the price, the network and the payee.
  2. Check the policy: caps, allow-list and blocked contracts are evaluated before signing.
  3. Sign the transfer with EIP-3009 and retry with the payment attached.
  4. Record the spend so the daily budget stays honest.

Questions

(rows) => rows .map( ([q, a]) => `
${q}

${a}

`, ) .join("\n")