x402: Pay-Per-Request API Access
HoudiniSwap Partner API v2 supports the x402 payment protocol as an alternative to traditional API key authentication. With x402, you pay for each API request using USDC on supported EVM chains — no account registration or API key required.How It Works
The x402 protocol uses the HTTP402 Payment Required status code to enable pay-per-request access:
- Client makes a request without authentication
- Server responds with
402and aPAYMENT-REQUIREDheader containing payment instructions - Client signs a USDC
transferWithAuthorization(EIP-3009) — no gas required - Client retries the request with the signed payment in the
PAYMENT-SIGNATUREheader - Server forwards the payment to the facilitator for on-chain verification and settlement
- Facilitator confirms the USDC transfer
- Server returns the requested data
Supported Networks
Additional EVM networks (Ethereum, Polygon, Arbitrum) can be enabled — contact us for availability.
Pricing
Requests are priced by operation type in USDC:GET /v2/health and GET /v2/openapi.json are always free and do not require payment or authentication.Rate Limits
x402 payers are rate-limited to 60 requests per minute per payer address. This is separate from API key rate limits.x402 vs API Key Authentication
When both are available, API key authentication takes priority. If a request includes an
Authorization header (full API key access) or a partner-id header (public read-only partner access), the x402 payment flow is bypassed entirely.
Quick Start
Prerequisites
- An EVM wallet with USDC on a supported network
- Node.js 18+ (for the JavaScript client)
- USDC on Base (amounts are tiny — a full exchange flow costs ~$0.012 total)
1. Install Dependencies
2. Create a Payment Client
3. Make Paid API Requests
4. Check Payment Receipt
Successful paid responses include apayment-response header:
Full Exchange Flow Example
This example demonstrates a complete swap flow using x402 payments:Headers
x402 Protocol Headers
These headers are set by the x402 SDK and carry the payment data:CORS Headers
HoudiniSwap adds the x402 headers to CORS allow/expose lists so browser-based clients can access them:The CORS header names (
X-PAYMENT, X-PAYMENT-RESPONSE) are SDK-level aliases. The actual protocol headers your code reads/writes are PAYMENT-REQUIRED, PAYMENT-SIGNATURE, and payment-response as listed above.Payment Required Response Format
ThePAYMENT-REQUIRED header decodes to:
The
amount field is in USDC atomic units (6 decimals). 100 = $0.0001 USDC.Other Languages
The x402 protocol has official client libraries for multiple languages:- Python:
x402withhttpxorrequests - Go:
github.com/coinbase/x402/go - Axios (Node.js):
@x402/axios
Error Handling
Further Reading
- x402 Protocol Overview — Official protocol specification
- x402 Quickstart for Buyers — Client setup in all languages
- x402 Network Support — Supported chains and assets