Overview
x402 is a payment protocol for HTTP resources. When a client requests a payment-gated endpoint, the server responds with HTTP 402 and payment requirements. The client includes a payment proof in theX-Payment header, and the server verifies it via a facilitator before granting access.
In aixyz, AixyzServer extends x402ResourceServer, providing built-in payment gating for agent and tool endpoints.
How It Works
- Client requests a gated endpoint (e.g.,
POST /agent) - Server returns HTTP 402 with payment requirements (price, network, payTo address)
- Client constructs payment proof and retries with
X-Paymentheader - Server verifies payment via a facilitator and grants access
The accepts Export
Define payment requirements by exporting accepts from your agent or tool:
With Overrides
"$0.005", "$0.01", "$0.0001".
Per-Agent and Per-Tool Pricing
Agents and tools can each declare their ownaccepts export, enabling granular pricing:
- Agent
acceptsgates the A2A/agentendpoint - Tool
acceptsgates the tool on the MCP/mcpendpoint - Agents and tools without
acceptsare not registered on protocol endpoints
Facilitators
Payment verification is handled by a facilitator service:| Facilitator | Activation | URL |
|---|---|---|
| Default | Always available | https://www.x402.org/facilitator |
| Coinbase CDP | When CDP_API_KEY_ID is set | Auto-configured |
| Custom | Set X402_FACILITATOR_URL | Your custom URL |
Custom Facilitator
Createapp/accepts.ts to provide a custom facilitator:
Server Integration
In a custom server, usewithX402Exact() to add payment middleware: