x402 payment protocol
x402 defines a machine-readable payment handshake over standard HTTP. An agent and a server can negotiate, settle, and verify an on-chain payment without any out-of-band coordination.
How x402 works
x402 extends HTTP with two message components:
HTTP 402 Payment Required response: When a resource requires payment, the server returns a 402 response with a machine-readable payment payload. The payload specifies the amount, accepted token or currency, the payment network, and the destination address.
PAYMENT-REQUIRED response header: When a resource requires payment, the gateway returns a HTTP 402 response with the payment requirement in the PAYMENT-REQUIRED header. The client makes the required on-chain payment and attaches the signed payment proof in the payment proof header on a retry of the original request.
sequenceDiagram
participant A as Agent
participant G as Gateway
participant B as Blockchain
A->>G: GET /tool
G-->>A: 402 PAYMENT-REQUIRED: {amount, network, address}
A->>B: Pay on-chain
B-->>A: Confirmed
A->>G: GET /tool + payment proof header
G-->>A: 200 + responseThe protocol is transport-agnostic and works over any standard HTTP endpoint. No dedicated payment intermediary is required between the two parties.
Networks
x402 payments settle on-chain. The Agent Gateway supports the following networks:
- Base: the default network for x402 payments in the gateway.
- Ethereum: Ethereum mainnet and standard testnets.
- Solana: Solana mainnet.
Network support and accepted tokens are configured per gateway deployment in x402.json.
Related
- AP2 protocol: Agent Payments Protocol: the surface-level payment protocol for agent-initiated commerce flows.
- MCP protocol: Model Context Protocol: how the gateway serves and proxies MCP tool servers.
Glad to hear it! Please tell us how we can improve more.
Sorry to hear that. Please tell us how we can improve.
Thank you for sharing your feedback so we can improve your experience.