Skip to main content

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 HTTP 402 Payment Required status code to enable pay-per-request access:
  1. Client makes a request without authentication
  2. Server responds with 402 and a PAYMENT-REQUIRED header containing payment instructions
  3. 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
  4. Client retries the request with the signed payment in the PAYMENT-SIGNATURE header
  5. Server forwards the payment to the facilitator for on-chain verification and settlement
  6. Facilitator confirms the USDC transfer
  7. 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 the amount 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 402 and sign again.
  • No fee quote, no request. If the current network fee can’t be determined, the API returns 503 before 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-PAYMENT header instead of PAYMENT-SIGNATURE. If both are present, a non-empty PAYMENT-SIGNATURE takes precedence.

Endpoints Not Available via x402

x402 covers swap operations (tokens, quotes, exchanges, orders and related DEX helpers), plus GET /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.
The partner-id header is not a credential and does not bypass x402. Paid endpoints called with only partner-id still return 402.

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

Everything after this step is the same for both networks. Register both schemes on one client to let it pay on whichever offered network it supports.

3. Make Paid API Requests

4. Check Payment Receipt

Successful paid responses include a payment-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:
See Order Lifecycle for all status codes.
Each x402 payment is an on-chain USDC transfer. Allow sufficient time between rapid sequential requests to avoid transaction failures from nonce collisions. For high-frequency access, consider using API key authentication instead.

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

The PAYMENT-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: See the x402 Quickstart for Buyers for setup instructions in each language.

Error Handling

Further Reading