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

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

说明与用途

x402 让自主 AI 代理通过 HTTP 头部使用 Base 上的 USDC 进行支付,无需中间服务。

问题

Autonomous AI agents need to pay for paid services without human intervention, but traditional payment flows require out‑of‑band setup or intermediaries.

结果

Implemented a stateless, HTTP‑native micropayment flow that allows AI agents to pay for a text‑summarizer microservice using USDC on Base, with minimal server code and no session storage.

工作流

  • 1. Agent sends request to protected endpoint.
  • 2. Server responds with 402 and X‑Payment‑Info header containing payment details.
  • 3. Agent constructs EIP‑712 typed data, signs it with its wallet, and sends X‑Payment header with signature on retry.
  • 4. Server verifies signature against nonce, amount, and payTo; if valid, returns 200 with resource.
  • 5. If proof invalid or missing, server returns 402 again or 400.
  • 6. Server stores nonce temporarily (e.g., Redis) for stateless verification.

证据

x402 is a lightweight extension to HTTP that turns the existing 402 Payment Required status code into a machine‑readable payment request.

来源

The flow is deliberately stateless: the server only needs to verify the signature against the nonce it issued.

来源

  • 记录日期: 2026-09-14T05:16:19.861Z