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 supported EVM chains — 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 transferWithAuthorization (EIP-3009) — no gas required
  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

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 a payment-response header:

Full Exchange Flow Example

This example demonstrates a complete swap flow using x402 payments:
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 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

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

Error Handling

Further Reading