How an AI agent pays for an API call with x402

By Mart402 Editorial (sample) - published 2026-09-26

This page is a sample asset. It exists so that the example requests in our documentation work exactly as written: an agent that copies the example and pays for it gets real, useful content back instead of an error.

The four steps

First, the agent sends an ordinary HTTP request to a paid endpoint without any payment. The server answers with HTTP 402 Payment Required and a machine-readable body that states the price, the asset (USDC), the network (Base) and the recipient address. Nothing has been charged at this point, so inspecting the terms is free.

Second, the agent checks the terms against its own budget policy. A well-behaved client refuses to sign anything above its configured maximum amount, which is why sellers should state exact prices before payment and never change them afterwards.

Third, the agent signs a payment authorization and repeats the same request with the payment attached in a header. The server verifies the authorization, performs the work and settles the payment on-chain.

Fourth, the agent receives the result together with a receipt identifier. If the connection drops, resending the same payment returns the stored result without a second charge, and the receipt can be fetched again for free.

What a buyer should check

These checks take seconds and protect the agent's budget far more than any marketing copy can.