x402 Explained: HTTP‑Native Micropayments for AI Agents (With Real Code)
Описание и применение
Автономные агенты могут автоматически оплачивать API‑запросы, используя протокол x402, который интегрирует оплату в HTTP‑трафик.
Задача
Autonomous agents need to consume paid services without human intervention, but traditional billing methods add coupling and require pre‑provisioned balances.
Результат
Agents can autonomously pay for API calls using on‑chain micropayments, reducing coupling and manual billing.
Рабочий процесс
- 1. Agent sends normal GET/POST to protected endpoint.
- 2. Server responds with 402 and headers (X-Amount, X-Currency, X-Chain-ID, X-Payment-Request, X-Pay-To).
- 3. Agent builds and sends on‑chain transaction per X-Payment-Request.
- 4. After mining, agent extracts txHash and retries original request with X-Payment-Proof header or body field.
- 5. Server verifies txHash, amount, recipient, and nonce; if valid, processes request and returns 200.
Доказательства
The x402 specification repurposes the HTTP 402 Payment Required status code to turn every request into a self‑contained payment negotiation.
Server verifies that the txHash corresponds to a transaction on the correct chain and that the transaction sent the expected amount to the payee.
- Дата записи: 2026-09-15T04:16:41.920Z