x402 Explained: HTTP‑Native Micropayments for AI Agents (With Real Code)
说明与用途
自主代理可以使用Base上的链上USDC按请求付费,消除每个客户端的余额管理。
问题
AI agents need to pay for external services per use, but traditional billing forces over‑provisioning or complex credential rotation.
结果
Agents can pay per request using on‑chain USDC, eliminating the need for per‑client balances and simplifying billing.
工作流
- 1. Agent sends normal request without payment data.
- 2. Service responds 402 Payment Required with Pay-Payload header (token, chainId, amount, receiver, nonce, signature).
- 3. Agent verifies signature, builds ERC‑20 transferFrom transaction, sends to Base RPC, waits for confirmation.
- 4. Agent retries original request adding Authorization: Bearer
<txHash>header. - 5. Service validates transaction, nonce, and returns 200 OK with resource.
证据
The x402 proposal does exactly that: it repurposes the HTTP 402 Payment Required status code to signal that a resource is behind a pay‑wall, then defines a minimal on‑chain handshake (USDC on Base) to settle the fee before the server returns the payload.
Minimal Server Implementation (Node.js + Express)
- 记录日期: 2026-09-15T01:00:42.062Z