Make an initial HTTP request to the resource endpoint; the server responds with 402 Payment Required and a payment descriptor in the response body or a WWW-Authenticate / X-Payment header describing what is owed: amount, currency, payment destination, and a nonce or invoice reference.
Parse the payment descriptor; validate that the requested amount is within your agent's authorized spend policy before proceeding — treat a 402 from an unknown endpoint as untrusted until validated.
Construct a payment using a method the server accepts (commonly a blockchain micropayment, a signed payment channel update, or a pre-authorized PSP token — the descriptor specifies the mechanism); sign or authorize the payment proof.
Retry the original request with the payment proof attached (typically in an X-Payment or Authorization header, or as a query parameter per the server's specification); include the original nonce to bind the payment to this specific request.
If the server returns 200 with the resource, record the payment proof and response in your audit log; if it returns 402 again (e.g., proof rejected or nonce expired), do not retry more than once without human review.
Track cumulative spend per endpoint across agent sessions to enforce budget caps; a 402-enabled API can drain a budget if the agent calls it in a tight loop.
Known gotchas
The x402 protocol is not yet a finalized standard — implementations vary significantly between providers; treat each 402-enabled endpoint as having its own dialect and validate the descriptor schema carefully before sending funds.
A malicious or compromised server can return a 402 with an inflated amount or a fraudulent payment destination; always validate the payment descriptor against an out-of-band trust registry or allowlist before paying.
Payment proofs are often one-time-use and tied to a specific nonce; caching or replaying a proof from a previous request will typically result in a rejection, not a free ride.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp