How to Use x402 Pay-Per-Call Crypto APIs (With Code Examples)
The x402 protocol enables machine-to-machine payments for API calls. No subscriptions, no API keys — just pay per call with USDC on Base.
Step 1: Discover Available Services
curl http://169.58.38.67:8090/bazaar.json
This returns a JSON catalog of 93 API endpoints with prices, descriptions, and methods.
Step 2: Make an API Call (Get 402)
curl http://169.58.38.67:8090/api/funding-rates
Response:
HTTP/1.1 402 Payment Required
X-Payment: <payment-required-header>
The 402 response includes payment instructions in the X-Payment header.
Step 3: Pay and Retry
Use the x402 SDK to handle payment automatically:
from x402 import Client
client = Client(
server_url="http://169.58.38.67:8090",
wallet_private_key="YOUR_PRIVATE_KEY",
network="base-sepolia"
)
# This automatically handles the 402 -> pay -> retry flow
response = client.get("/api/funding-rates")
print(response.json()) # Funding rates data
Available Endpoints
Trading (High Value)
-
POST /api/mev-liquidate— MEV Liquidation Detection ($0.50) -
POST /api/hft-market-maker— High-Frequency Market Maker ($0.50) -
GET /api/funding-rates— Funding Rates Aggregator ($0.05) -
GET /api/dex-arb— DEX Arbitrage Scanner ($0.10)
Security
-
POST /api/phishing-scan— Phishing Detection Web3 ($0.05) -
POST /api/contract-audit— Smart Contract Audit ($0.20)
Data
-
POST /api/rag-markdown— Web Page to Markdown ($0.02) -
POST /api/sentiment— Crypto Sentiment Analysis ($0.05) -
POST /api/osint— OSINT Profile Enricher ($0.10) -
POST /api/stealth-fetch— Anti-Bot Web Scraper ($0.10)
AI/ML
-
POST /api/llm-inference— LLM Inference ($0.05) -
POST /api/tts— Text-to-Speech ($0.05)
Full Catalog
Visit http://169.58.38.67:8090/bazaar.json for all 93 services.
Pricing
Payments are in USDC on Base Sepolia testnet. Each endpoint has its own price per call, ranging from $0.02 to $0.50.
Top comments (0)