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

Pay-per-call crypto data for AI agents with x402: a working example

说明与用途

AI 代理可以通过 x402 以按调用计费的方式请求加密数据,x402 自动处理 USDC 支付并返回数据,无需注册或 API 密钥。

问题

Crypto data APIs require accounts, keys, and monthly plans, which is inconvenient for AI agents that need a single price per call.

结果

Agents can pay per data call in USDC, avoiding monthly plans and key management, with a simple JavaScript wrapper.

工作流

  • 1. Call the endpoint and receive HTTP 402 with price details.
  • 2. Use x402-fetch to sign an EIP‑3009 USDC authorization and retry with X‑PAYMENT header.
  • 3. Receive the paid response and optional receipt.
  • 4. Wrap the fetch call as a tool for the agent.
  • 5. Optionally set a spending cap in the agent loop.

证据

Most crypto data APIs want an account, an API key and a monthly plan. That's awkward when the caller is an AI agent that needs one price, once.

来源

x402 fixes this by reusing the HTTP 402 Payment Required status: the server answers with a price, the client pays in USDC and retries, and the data comes back. No signup, no key.

来源

The wallet needs a little USDC on Base. It doesn't need ETH: the facilitator submits the transfer.

来源

  • 记录日期: 2026-10-21T08:41:04.920Z