x402
Pay-per-use AgentMail with the x402 payment protocol
Pay-per-use AgentMail with the x402 payment protocol
x402 is an open payment protocol that enables HTTP-native payments. By integrating x402 with AgentMail, your agents can pay for API usage directly over HTTP without managing API keys or subscriptions.
Agents on X Layer can pay for API usage directly over HTTP via x402. X Layer is an Ethereum Layer 2 network built with Polygon CDK, offering high throughput and near-zero gas fees.
To authenticate with x402 instead of an API key, you must use the x402-specific base URLs below. These replace the default AgentMail base URLs and route requests through the x402 payment layer.
When you pass an x402 client to AgentMailClient, the SDK automatically handles payment negotiation for each API request. If the server responds with a 402 Payment Required status, the x402 client signs a payment using your wallet and retries the request with the payment attached.
This means your agent can use the full AgentMail API (inboxes, messages, threads, attachments) without needing a traditional API key. Payment happens per-request over HTTP.