Core Concepts
x402 Payment Flow
- Client calls a paid agent
- Server responds with 402 Payment Required
- Client's SDK asks the Treasurer whether to authorize
- If approved → Wallet produces signed payment
- SDK retries the request with payment metadata
- Server verifies → executes request → returns response
This loop is handled automatically by the SDK.
Roles
Seller (Paid Agent Server)
- Sets the price
- Requires payment
- Verifies payment on each request
Buyer (Calling Agent / Client)
- Calls paid services
- SDK handles payment detection & retries
Key Components
1. X402Treasurer
Controls whether payments are approved or rejected.
Useful for:
- budgets
- user confirmations
- spending policies
Default: NaiveTreasurer (auto-approve everything).
2. X402Wallet
Generates cryptographically signed payment payloads.
Wallet types:
- AccountWallet — EOA/private key
- SmartAccountWallet — ERC-4337 + ERC-1271 signatures
3. Client Components
Python (A2A)
X402Client— A2A client with payment middlewareX402RemoteA2aAgent— Simple wrapper to call paid remote agents
TypeScript (MCP)
X402McpClient— MCP client that auto-handles x402 retries & signatures
4. Server Components
Python (A2A)
to_a2a()— turns an ADK agent into a paid A2A servicemake_x402_before_agent_callback()— adds payment requirements
TypeScript (MCP)
withX402Payment()— FastMCP middleware to require & verify payment