x402-trinity Adds Local, Budget-Limited USDC Payments for Autonomous AI Agents
Summary
x402-trinity is a drop-in fetch replacement for autonomous AI agents that need to access paid HTTP resources. When a server returns HTTP 402, the library reads the payment challenge, checks it against configured limits, signs an EIP-3009 USDC authorization, and retries the request locally. It does not use a hosted wallet service or third-party API, and the private key remains in the application process; the package has zero runtime dependencies and is about 7 KB gzipped. The TypeScript implementation supports both buyers and sellers, while Python provides a buyer client using only the standard library. Buyers must set a maximum amount per request and a total budget, and can restrict payments by host and recipient. The project warns that an in-memory total budget resets after restarts and across Cloudflare Worker isolates, so mainnet use requires a durable budget store or an explicit acknowledgment of an ephemeral budget. Sellers specify the recipient, price, network, facilitator, and a persistent nonce store; the nonce store prevents a settled authorization from being replayed after a process restart. The seller does not hold a private key or custody funds: a facilitator verifies and settles payment directly from buyer to seller. Base mainnet with USDC is the default, while other EVM chains can be configured through custom chain definitions. The library detects x402 protocol versions 1 and 2, declines unknown versions and MPP challenges, and runs on Node, Bun, Deno, and Cloudflare Workers. It also exposes an MCP server with price checking, paid fetching, and wallet-status tools, allowing an AI assistant to invoke payments while limits remain controlled by the environment. The project reports microsecond-scale warm-path timings, offers local, additive-shard, or remote-signing custody options, and includes timing-hardening measures while acknowledging that pure JavaScript arithmetic is not constant-time. It is released under Business Source License 1.1, with a stated conversion to MIT on August 25, 2029, and charges a 0.1% convenience fee plus one cent per 100 transactions.