The x402 protocol lets clients pay for HTTP resources (APIs, endpoints, content) via blockchain transactions (with fiat support in progress). A server responds with HTTP 402 (“Payment Required”), the client pays, and the server grants access. No subscription, API key, or manual onboarding is required. Polygon facilitators on mainnet and Amoy run x402 v2. See Migration: V1 to V2 if you have an existing V1 integration.Documentation Index
Fetch the complete documentation index at: https://docs.polygon.technology/llms.txt
Use this file to discover all available pages before exploring further.
1. Components
| Component | Role | Example / note |
|---|---|---|
| Client | Requests a resource and pays | Browser, AI agent, mobile SDK |
| Resource Server | Protects endpoint, issues 402, verifies payment | API or web service |
| Facilitator | Optional verification and settlement layer | Polygon: x402.polygon.technology |
| Payment Scheme | Defines chain, token, network, and format | e.g., USDC on Polygon via exact scheme |
2. Payment Flow Sequence
The typical sequence for one request:- Client → Resource Server: HTTP GET /endpoint
- Resource Server → Client: HTTP 402 Payment Required, body includes
PaymentRequirementswithx402Version: 2and anacceptsarray. - Client selects a requirement, builds a payment payload, and retries with
header
PAYMENT-SIGNATURE. - Resource Server verifies the payload (locally or via the Facilitator).
- Facilitator / Resource Server settles payment onchain (if not already).
- Resource Server → Client: HTTP 200 OK, body includes the requested
resource, header
PAYMENT-RESPONSEcontains receipt details.
3. Implementation Snapshot
Server (Seller Side)
Protect endpoints with v2 middleware using anx402ResourceServer, a
facilitator client, and route config with an accepts array.
On first unauthorized request, respond 402 with JSON like:
PAYMENT-SIGNATURE header: verify using the facilitator, then
return 200 OK and include:
Client (Buyer Side)
- Send initial request → get 402 + payment info.
- Create an
x402Client, registerExactEvmSchemefor"eip155:*", and usewrapFetchWithPaymentorwrapAxiosWithPayment. - Retry request with header:
- Receive 200 OK and read
PAYMENT-RESPONSEviax402HTTPClient.getPaymentSettleResponse().
Facilitator (optional)
Provides endpoints such as/verify and /settle for payment payloads.
- Amoy:
https://x402-amoy.polygon.technology - Mainnet:
https://x402.polygon.technology
Key Design Goals and Benefits
- HTTP-native: Uses standard HTTP codes and headers. No additional protocol layer.
- Chain and token agnostic: Works across any chain or stablecoin (e.g., USDC).
- Minimal integration: Middleware on the server side; a few client calls on the buyer side.
- Micropayments: Low friction and low cost, suitable for per-request pricing.
- Autonomous agents: AI systems can transact without per-transaction human approval.
Known Limitations and Future Directions
- Use CAIP-2 network IDs (
eip155:80002for Amoy,eip155:137for mainnet). V1 strings like"polygon-amoy"cause payment failures on Polygon facilitators. - The protocol is still evolving. Some paid endpoints may require settlement delays.
- For high-volume usage, consider deferred payment flows: aggregate many calls, then settle in batch.
- Protocol governance is managed by an open community to prevent vendor lock-in.