x402 Pay-Per-Request

Beta

Access derivatives data with instant USDC micropayments via the HTTP 402 protocol. No API key needed. Pay only for what you use.

How It Works

1

Request Data

Call any derivatives endpoint without an API key. The server responds with HTTP 402 and payment details.

2

Pay with USDC

Your wallet signs a USDC payment on Base or Solana. The transaction is verified by the x402 facilitator.

3

Get Data

Payment verified instantly. Your data is returned in the same HTTP response. No waiting, no accounts.

The x402 Protocol

x402 brings the HTTP 402 Payment Required status code to life. Originally reserved in the HTTP spec in 1997 for "future use," it was never standardized — until now. Built by Coinbase, x402 turns every API call into a pay-as-you-go transaction using USDC stablecoins.

x402 Protocol Flow — Client, Resource Server, and Facilitator interaction

The client sends a request, the resource server responds with 402 and payment requirements, the client signs a USDC payment, and the facilitator verifies & settles on-chain before the server returns the data.

Why We Bundle 100 Calls, Not Pay Per Request

The economics of on-chain micropayments make per-request settlements impractical. Here's why credit bundles are the right design.

The Per-Request Problem

Every on-chain transaction — no matter how small — carries a fixed gas cost. On Base L2, this is roughly $0.001–$0.01 per transaction. Our API charges $0.001 per request. That means the gas fee alone can be equal to or greater than the data you're paying for.

If a quant needs 100 OHLCV candles to backtest a strategy, naive per-request x402 would mean 100 separate blockchain transactions — each with its own gas fee, each adding 2–5 seconds of on-chain settlement latency. The gas overhead alone could exceed the total cost of the data by 5–10x.

100 calls × $0.005 gas = $0.50 in gas to access $0.10 worth of data. That's a 5x overhead.

Beyond cost, there's latency. Each settlement takes 2–5 seconds for the facilitator to verify and submit on-chain. For a trading bot that needs to poll data every few seconds, waiting for a blockchain confirmation per call is a non-starter.

Our Solution: Prepaid Credit Bundles

Instead of settling every single request on-chain, we batch payments into credit bundles. You pay once for a bundle of 100 API calls ($0.10 in USDC), and the server credits your wallet with 99 prepaid requests. Those 99 subsequent calls are served instantly from an in-memory credit ledger — no blockchain, no gas, no latency.

1
On-chain transaction
per 100 calls
~1ms
Credit deduction latency
(Redis atomic op)
99%
Less gas overhead
vs per-request

Credits are tracked server-side in Redis for speed (atomic DECRBY, cross-pod), with ClickHouse as the persistent audit trail. If the server restarts, credits are restored from ClickHouse on startup. Your balance is never lost.

Solana support: On Solana, transaction costs are even lower (~$0.00025) with 400ms finality — but bundles still save 99% of on-chain interactions and eliminate all settlement latency for credit calls.

Cost Breakdown: 100 API Calls

Metric Per-Request Bundle (100)
Data cost 100 × $0.001 = $0.10 100 × $0.001 = $0.10
Gas fees 100 × ~$0.005 = $0.50 1 × ~$0.005 = $0.005
Total cost $0.60 $0.105
Effective cost per call $0.006 $0.00105
Latency per call 2–5 seconds ~1ms (99 of 100 calls)
On-chain transactions 100 1
Gas savings ~$0.495 saved (99%)

Comparative Analysis: API Access Methods

How does x402 with credit bundles compare to traditional API access models?

Feature API Key x402 Per-Call x402 + Bundles
Signup required Yes (email, account) No No
Payment model Monthly subscription USDC per request USDC per bundle
Latency overhead ~0ms 2–5s per call ~1ms (after first call)
Privacy Email, identity Wallet only Wallet only
Gas overhead None High (per call) Minimal (per bundle)
AI agent friendly Needs key management Native wallet signing Native + fast credits
Cost for 1,000 calls Plan-dependent ~$6.00 ~$1.05
Best for High-volume production One-off queries Regular usage, bots, agents

What x402 Unlocks

Autonomous AI Agents

AI agents can access market data by paying directly from their wallet. No API key provisioning, no human in the loop. An agent with a funded wallet can discover endpoints, pay for data, and make trading decisions — all programmatically.

Zero-Identity Access

No email, no signup, no API key management. Your wallet address is your only identity. Perfect for privacy-conscious traders and researchers who want data without creating accounts.

True Pay-As-You-Go

No monthly minimums, no unused quota. You pay for exactly what you consume. Need 10 calls this month and 10,000 next month? The cost scales linearly — no plan upgrades or downgrades.

Instant Onboarding

Go from zero to live data in seconds. Fund your wallet with USDC on Base or Solana, call the endpoint, and you're in. No approval process, no email verification, no waiting for API keys to be provisioned.

Prepaid Credit Bundles

Pay once for multiple API calls. After the first on-chain payment, subsequent requests are served instantly from prepaid credits (~1ms, no blockchain transaction).

1

First call without API key

Server responds with 402 Payment Required and payment details

2

Client signs USDC payment

Wallet signs an EIP-712 message authorizing the USDC transfer. Sent as PAYMENT-SIGNATURE header.

3

Server verifies and settles on-chain

Coinbase facilitator settles the payment. Wallet is credited with N-1 prepaid calls.

4

Response includes credit token

Headers: x-credit-token (JWT) + x-credits-remaining

5

Subsequent calls: send credit token

Set X-Credit-Token header. Instant access (~1ms), credits decremented in Redis.

6

Credits exhausted?

Next call returns 402 again. Pay for a new bundle and repeat.

Quick Start

Install the x402 client libraries and pick your chain. The @x402/fetch wrapper handles the entire 402 flow automatically — payment signing, retry, and credit token management.

1. Install dependencies

# EVM (Base) — uses viem for wallet signing
npm install @x402/fetch @x402/evm viem

# Solana — uses @solana/kit for keypair signing
npm install @x402/fetch @x402/svm @solana/kit @scure/base

2. Choose your chain

import { x402Client, wrapFetchWithPayment } from '@x402/fetch';
import { registerExactEvmScheme } from '@x402/evm/exact/client';
import { privateKeyToAccount } from 'viem/accounts';

// Your EVM private key (0x-prefixed hex)
const EVM_PRIVATE_KEY = process.env.EVM_PRIVATE_KEY;

const client = new x402Client();
const signer = privateKeyToAccount(EVM_PRIVATE_KEY);
registerExactEvmScheme(client, { signer });

console.log(`Wallet: ${signer.address}`);

const fetchWithPayment = wrapFetchWithPayment(fetch, client);

// First call pays on-chain ($0.10 for 100-call bundle)
const response = await fetchWithPayment(
  'https://apiv2.laevitas.ch/api/v1/perpetuals/catalog?exchange=deribit'
);
const data = await response.json();

// Save the credit token for subsequent calls (instant, no gas)
const creditToken = response.headers.get('x-credit-token');
const remaining = response.headers.get('x-credits-remaining');
console.log(`Credits remaining: ${remaining}`);

// Subsequent calls — use credit token (no on-chain tx, ~1ms)
const next = await fetch(
  'https://apiv2.laevitas.ch/api/v1/perpetuals/catalog?exchange=deribit',
  { headers: { 'X-Credit-Token': creditToken } }
);

3. cURL (manual flow)

# Step 1: Request without auth — get 402 + payment details
curl -i https://apiv2.laevitas.ch/api/v1/perpetuals/catalog \
  -G -d "exchange=deribit"
# Response: 402 with payment-required headers

# Step 2: After payment, use the credit token for instant access
curl https://apiv2.laevitas.ch/api/v1/perpetuals/catalog \
  -H "X-Credit-Token: eyJhbGciOi..." \
  -G -d "exchange=deribit"
# Response: 200 with data + x-credits-remaining header

Pricing

Price per request $0.001 USDC
Currency USDC (USD Coin)
Bundle example 100 calls = $0.10 per payment
Networks Base (eip155:8453) + Solana (solana:mainnetBeta)
Testnets Base Sepolia + Solana Devnet
Tx cost (gas) Base ~$0.005 · Solana ~$0.00025
Facilitator Coinbase x402 (Base + Solana)
Credit token lifetime 24 hours
Eligible endpoints /futures/* /perpetuals/* /options/*

Response Headers

Header When Description
x-credit-token After on-chain payment JWT identifying your wallet. Send as X-Credit-Token header for subsequent calls.
x-credits-remaining Every credit-spend call Number of prepaid credits remaining in your wallet.
x-402-* 402 response Payment requirements including amount, network, and receiving wallet address.

Supported Networks

Base Mainnet

PRODUCTION

Primary EVM network for production payments.

Network: eip155:8453
Currency: USDC (ERC-20)
Tx cost: ~$0.001–$0.01

Base Sepolia

TESTNET

EVM testing with testnet USDC.

Network: eip155:84532
Currency: USDC (testnet)

Solana Mainnet

PRODUCTION

Ultra-low fees, 400ms finality.

Network: solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp
Currency: USDC (SPL)
Tx cost: ~$0.00025

Solana Devnet

DEVNET

Solana testing with devnet USDC.

Network: solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1
Currency: USDC (devnet)

Frequently Asked Questions

x402 is an open payment protocol built on the HTTP 402 "Payment Required" status code. Developed by Coinbase, it enables instant, programmatic stablecoin payments over HTTP. Instead of API keys or subscriptions, clients pay per request using USDC from their crypto wallet.

For Base (EVM): any wallet that can sign EIP-712 typed data — MetaMask, Coinbase Wallet, Rainbow, or programmatic wallets using viem / ethers.js. For Solana: any wallet that can sign transactions — Phantom, Solflare, or @solana/web3.js. You need USDC on whichever chain you choose.

Your next API call returns a 402 Payment Required response. If you're using @x402/fetch, it handles this automatically — a new payment is signed and submitted, and you receive a fresh bundle of credits.

Yes. x402 is an alternative authentication method. If you send a valid apikey header, the request is authenticated normally and no payment is required. x402 only activates when no API key is present on derivatives endpoints.

You are not charged. The server verifies the payment signature before settling on-chain. If settlement fails, the payment is not debited from your wallet. You can retry the request.

Credits are tracked server-side in Redis (fast, cross-pod) with ClickHouse as the persistent source of truth. When you send a payment signature, the server extracts your wallet address and checks for existing credits before settling on-chain. If you already have credits, the payment is skipped and a credit is deducted instead.

Yes. We support both Base (EVM) and Solana for USDC payments. The server advertises both networks in the 402 response, and your client library chooses which chain to pay on based on your wallet type. Credit bundles work identically on both chains.

Solana offers the lowest transaction fees (~$0.00025) and fastest finality (~400ms), ideal for high-frequency or cost-sensitive use cases. Base is best if you're already in the EVM ecosystem and prefer using EVM wallets and tooling. Both chains use USDC and support the same credit bundle system.

Resources