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

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

说明与用途

x402 通过 HTTP 402 和头部实现 AI 代理每次请求支付微量 USDC 费用。

问题

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