x402 Explained: HTTP‑Native Micropayments for AI Agents (With Real Code)
Описание и применение
Автономные агенты могут автоматически оплачивать вызовы внешних API, используя HTTP‑статус 402 и подписанные заголовки, без ручного выставления счетов.
Задача
AI agents need to pay for external API calls automatically without manual invoicing or custom payment layers.
Результат
Agents can autonomously pay for API calls using HTTP 402 and signed headers, eliminating manual invoicing and custom payment logic.
Рабочий процесс
- 1. Agent sends normal GET/POST to protected endpoint.
- 2. Server responds 402 with Payment header (base64url JSON) and optional WWW‑Authenticate.
- 3. Agent signs the payment request using EIP‑712 and its wallet, adding Authorization: Bearer
<signature>and same Payment header. - 4. Server verifies signature, checks nonce, processes request, returns 200 OK.
Доказательства
The server validates the signature, checks that the nonce hasn’t been reused (prevents replay)
Node.js/Express server protects /data endpoint with x402 payment of 0.01 USDC
- Дата записи: 2026-09-15T01:00:24.396Z