Pay-per-call crypto data for AI agents with x402: a working example
Описание и применение
AI‑агенты могут запрашивать криптовалютные данные по оплате за вызов, используя протокол x402, который автоматически обрабатывает платежи в USDC и возвращает данные без необходимости регистрации и ключей.
Задача
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