🤖💸 How an AI Agent Pays for an API Without an API Key (x402 in Practice)
说明与用途
代理可以通过使用 x402 协议在不使用 API 密钥的情况下为单个 API 调用付款,协议返回价格和支付地址,代理转账 USDC 并使用支付凭证重试请求。
问题
Autonomous agents cannot use traditional API key workflows because they cannot create accounts, accept terms, or enter credit cards for pay‑per‑call services.
结果
Agents can autonomously pay for individual API calls without storing or rotating API keys, enabling pay‑per‑call, zero‑tier, and composable machine‑to‑machine interactions.
工作流
- Send GET request to endpoint without authentication
- Receive HTTP 402 with X‑PAYMENT header containing price, network, and pay‑to address
- Build an on‑chain USDC transfer for the exact amount on the specified network
- Retry the same request with X‑PAYMENT header containing the payment proof
- Server verifies on‑chain payment, settles, and returns signed data
证据
HTTP/1.1 402 Payment Required
X-PAYMENT: version=2, chain=base, max-total=10000 (0.01 USDC),
pay-to=0x4ff893...a4D5e9, resource="crypto-price"
The server verifies the payment on-chain, settles it, and returns the data. On xynaptic.io every response is also signed with Ed25519, and every proof is auditable at api.xynaptic.io/trust.
- 记录日期: 2026-10-18T16:11:02.034Z