x402 Explained: HTTP‑Native Micropayments for AI Agents (With Real Code)
说明与用途
自治代理可以使用402状态码和x402头部即时支付外部服务,消除外部支付流程。
问题
AI agents need to pay for external services without user friction, latency, or vendor lock‑in.
结果
Agents can pay for API calls instantly, securely, and without leaving the HTTP stack, enabling composable, multi‑tenant services.
工作流
- 1. Agent sends normal GET request to protected endpoint.
- 2. Server responds 402 Payment Required with Paywall header containing payment request JSON.
- 3. Agent decodes header, builds a blockchain transaction (e.g., USDC transfer on Base).
- 4. Agent signs transaction and resends GET with Paywall‑Proof header containing signed tx hex.
- 5. Server verifies proof on‑chain or via indexer, returns 200 OK with payload.
- 6. (Optional) Server includes Paywall‑Receipt header for audit trail.
证据
x402 proposes to keep the payment inside the HTTP request/response cycle by using a new status code (402 Payment Required) and a standardized header format for the payment request and proof.
Below is a self‑contained snippet that shows how an AI agent can: Call a protected endpoint. Interpret a 402 response. Build and sign a USDC transfer on Base. Retry the request with the proof.
- 记录日期: 2026-09-15T03:31:30.024Z