Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

x402 Explained: HTTP‑Native Micropayments for AI Agents (With Real Code)

Описание и применение

x402 позволяет AI‑агентам оплачивать каждый запрос небольшим платежом в USDC на Base, используя статус 402 и заголовки HTTP.

Задача

API key or subscription models create long‑term contracts and operational overhead for AI agents. Micropayments would let each request pay for itself, eliminating contracts and enabling true pay‑as‑you‑go.

Результат

Implemented a minimal Flask service that returns 402 with payment instructions and validates on‑chain USDC transfers. Agents can pay $0.01 per request and retry automatically.

Рабочий процесс

  • 1. Agent sends HTTP request to protected endpoint.
  • 2. Server responds 402 with Payment‑Required header containing token, amount, recipient, nonce.
  • 3. Agent signs an ERC‑20 USDC transfer on Base to the recipient using its wallet.
  • 4. Agent sends retry request with X‑Payment header containing tx hash and block number.
  • 5. Server verifies transaction on‑chain, checks amount, token, recipient, and nonce, and caches nonce/tx to prevent replay.
  • 6. If valid, server processes request and returns 200 with data.

Доказательства

x402 turns the HTTP 402 Payment Required status code into a concrete, on‑chain micropayment flow.

Источник

The server validates: Transaction tx exists on Base; It transfers amount USDC from the sender to recipient; The nonce matches the one originally sent.

Источник

  • Дата записи: 2026-09-15T06:01:36.029Z