Skip to content

How the protocol works

This page describes a typical x402-style flow on an EVM network with a stablecoin facilitator. Exact field names and encodings depend on your facilitator and the x402 specification version you target—always verify against your provider’s docs.

  1. Client calls your API (e.g. GET /api/premium/data).
  2. Server decides the caller has not yet paid for this resource.
  3. Server responds with 402 Payment Required and a body (and often headers) describing payment requirements: network, asset, payee, amount, scheme (e.g. “exact” payment), timeouts, etc.
  4. Client constructs a payment payload and signs or authorizes it with a wallet (human or automated).
  5. Client retries the same URL, attaching a payment-signature (or your stack’s equivalent) header carrying the signed payload.
  6. Server calls the facilitator verify (and then settle) with that payload.
  7. On success, server returns 200 and the protected response. On failure, server may return 402 or 4xx/5xx with an error body.

Implementations vary; common patterns include:

ConceptPurpose
402 statusSignals “payment needed before this resource.”
payment-required (or JSON body)Machine-readable requirements (amount, payee, chain, asset). Often base64-encoded JSON in a header for compactness.
payment-signatureClient’s signed payment authorization on retry.
x-trace-idOptional correlation ID for logs and observability (TallyPay uses this to stitch client + server events).

Your middleware should not invent a parallel protocol—align header names and encodings with your facilitator and the x402 version you support.

  • Never trust the client alone: your server (or edge worker) must verify via the facilitator or your own verifier.
  • Settlement may be asynchronous from the client’s perspective; your API should only release the resource when verify + settle succeed per your policy.

Networks and RPCs fail. Clients may retry the paid request; your route should be idempotent where possible (same payment proof should not double-charge for the same logical entitlement). How you enforce that (nonce, session, resource key) is application logic on top of x402.