The exchange, minimally
- Client requests a resource with no proof of payment.
- Server responds
402 Payment Requiredwith aPaymentRequiredheader describing what is owed. - Client reads the header, signs a payment authorization, and retries with an
X-Paymentheader. - Server hands the payload to a facilitator to verify (and later settle) the payment.
- Server returns the resource.
The 402 response
PaymentRequired header is a base64-encoded JSON object. Its full schema is documented in the API reference, but the fields you care about are:
The retry
X-Payment payload carries the signed authorization entries and identifies the client. See PaymentPayload.
What 402 is not
- Not authentication. A 402 says “you have not paid,” not “we do not know who you are.” It is compatible with API keys and OAuth, but does not replace them.
- Not rate limiting. Rate limits use 429. If your server wants to slow a paid caller down, return 429, not 402.
- Not a redirect. The client is expected to retry the same request against the same URL with an
X-Paymentheader, not follow aLocation.
Where next
- Client / Facilitator / Server explains who does what in the exchange.
- Payment Schemes covers
exactandupto. - Error & Rejection Codes is where you go when a 402 (or a subsequent verify) rejects a payment for a reason you have not seen before.