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 Base or Solana — 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 payment on one of the offered networks — no gas required:
- Base: a
transferWithAuthorization(EIP-3009) - Solana: a USDC transfer transaction whose network fee the facilitator pays
- Base: a
- 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
Every
402 lists the networks you can pay on in its accepts array — one entry per network, each with its own payTo address. Pay on any one of them. The price can differ by network, so read the list from the response rather than hard-coding it.
Pricing
Requests are priced by operation type in USDC. The prices below are minimums — see Gas Coverage for when the amount can be higher.GET /v2/status and GET /v2/openapi.json are always free and do not require payment or authentication. See Get system health for the health response.Gas Coverage
Because the facilitator pays the network fee for your payment, the price of a request can be higher than the minimum in the pricing table when network fees rise. The exact amount for each network is always in theamount field of the 402 response.
- Signed payments stay valid while they cover the cost. If the current price rises above the amount you signed before the payment is verified, request a new
402and sign again. - No fee quote, no request. If the current network fee can’t be determined, the API returns
503before running the request. Retry later or use API key authentication. - Rejected settlements aren’t charged. If the facilitator rejects a settlement, you don’t get a successful response and the payment is not broadcast.
- Header alias. The signed retry can use the
X-PAYMENTheader instead ofPAYMENT-SIGNATURE. If both are present, a non-emptyPAYMENT-SIGNATUREtakes precedence.
Endpoints Not Available via x402
x402 covers swap operations (tokens, quotes, exchanges, orders and related DEX helpers), plusGET /rateLimits so a payer can see the limits applied to them.
Partner account endpoints — /me, /commissions, /stats/volume, /stats/chart, /withdrawals — require full API key authentication via the Authorization header and cannot be paid for per request. Without credentials they return 401 Invalid API credentials, not 402 Payment Required. The partner-id header is not a credential and does not change this.
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), the x402 payment flow is bypassed entirely.
Quick Start
Prerequisites
- A wallet with USDC on Base (any EVM wallet) or on Solana. No ETH or SOL is needed for the payments themselves
- Node.js 20.18+ (for the JavaScript client)
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 on Base. To pay on Solana, swap in the Solana client from step 2: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 the aliases the x402 SDK uses internally. 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) on both networks. 100 = $0.0001 USDC. On Solana, feePayer is the account that pays the network fee for your transfer — the x402 client handles it for you.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