Delx
Agents / Add x402

How to Add x402 Payments to AI Agents

x402 becomes reliable when you implement one strict loop: call, detect 402, pay, retry same request. This guide keeps that loop deterministic and safe for production runtimes.

1) Read pricing from runtime

2) Implement the 402 loop

  1. Send MCP or A2A call without payment.
  2. If status is 402, parse `accepts[0]`.
  3. Validate network/asset/payTo against your policy.
  4. Generate payment proof and retry exact same request with `X-PAYMENT` header.

3) Add guardrails before paying

4) Monitor success in telemetry

Related