x402-api — pay-per-call DeFi data — x402 protocol v1
Pay-per-call DeFi & crypto data API · for AI agents · No API keys. No subscriptions. Just USDC on Base.
ONLINE
NETWORK Base (8453)
ASSET USDC
ENDPOINTS 8 LIVE
PROTOCOL x402 + EIP-3009
ERC-8004 AGENT #18763
BTC $── ── ETH $── ── SOL $── ── SUI $── ── HYPE$── ── LINK$── ── BTC $── ── ETH $── ── SOL $── ── SUI $── ── HYPE$── ── LINK$── ──
Agent Identity — ERC-8004
ERC-8004 Agent ID
#18763
Registry: base:0x8004A169FB4a3325136EB29fA0ceB6D2e539a432
View on BaseScan ↗
Payment Address (USDC on Base)
0x60264c480b67adb557efEd22Cf0e7ceA792DefB7
View on BaseScan ↗ · USDC contract: 0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913
Domain Verification
/.well-known/agent-registration.json
ERC-8004 · Trust model: reputation
View agent-registration.json ↗
Server Endpoint
https://x402-api.fly.dev
8 pay-gated endpoints · x402 protocol
Verifier: x402.org/facilitator ↗
How x402 Works
01
Request
Agent calls endpoint — no payment header yet
02
402 Response
Server returns payTo address, asset, amount required
03
Sign & Pay
Agent signs EIP-3009 transferWithAuthorization on Base
04
Retry
Agent retries with X-Payment: <base64 payload>
05
Verify + Serve
Server verifies via x402.org facilitator → 200 OK + data
Available Endpoints
Method Endpoint Price Description Data
GET /api/price-feed 0.001 USDC BTC, ETH, SOL prices + top 5 movers/losers by 24h change. 60s server cache. LIVE ✓
GET /api/gas-tracker 0.001 USDC Gas prices on Ethereum, Base, Polygon, Arbitrum — slow/normal/fast tiers + USD cost estimates. LIVE ✓
GET /api/dex-quotes 0.002 USDC Swap quotes across Uniswap V3, SushiSwap, 1inch. Price impact, fees, route. ?from=ETH&to=USDC&amount=1 LIVE ✓
GET /api/token-scanner 0.003 USDC Token security analysis: contract verification, honeypot check, liquidity lock, mint function, risk score. ?token=PEPE LIVE ✓
GET /api/whale-tracker 0.005 USDC Holder concentration: Gini coefficient, Herfindahl index, top 20 holders, large transfer alerts. ?token=ETH LIVE ✓
GET /api/yield-scanner 0.005 USDC Top DeFi yields across Aave, Compound, Morpho, Lido, Pendle, Ethena. Filter by chain, asset, TVL. LIVE ✓
GET /api/funding-rates 0.008 USDC Perp funding rates on Hyperliquid, dYdX v4, Aevo, GMX, Drift, Vertex + arb spread ranking. LIVE ✓
GET /api/wallet-profiler 0.008 USDC Wallet portfolio: holdings, DeFi positions, activity metrics, risk classification. ?address=0x… LIVE ✓
GET /health FREE Server health check · returns status, uptime, pay-to address FREE
Live Preview — /api/price-feed
BTC Loading…
ETH Loading…
SOL Loading…
Integration — x402-fetch

Use x402-fetch (the official Coinbase x402 client) to automatically handle the payment flow. No manual header wrangling — it intercepts 402s, signs USDC transfers on Base, and retries.

TypeScript · npm install x402-fetch viem
import { withPaymentInterceptor } from 'x402-fetch';
import { createWalletClient, http } from 'viem';
import { base } from 'viem/chains';
import { privateKeyToAccount } from 'viem/accounts';

// 1. Configure wallet with USDC on Base
const account = privateKeyToAccount(process.env.PRIVATE_KEY as `0x${string}`);
const walletClient = createWalletClient({
  account,
  chain: base,
  transport: http(),
});

// 2. Wrap fetch with x402 payment interceptor
const fetchWithPayment = withPaymentInterceptor(fetch, walletClient);

// 3. Call endpoints — payment happens automatically on 402
const res = await fetchWithPayment(
  'https://x402-api.fly.dev/api/price-feed'
);
const { data } = await res.json();

console.log('BTC:', data.core[0].price_usd);   // e.g. 98000
console.log('ETH:', data.core[1].price_usd);   // e.g. 2750

// Other endpoints — same pattern, different prices
const gas = await (
  await fetchWithPayment('https://x402-api.fly.dev/api/gas-tracker')
).json();
console.log('ETH gas (normal):', gas.data.ethereum.gas_price_gwei.normal, 'gwei');

const yields = await (
  await fetchWithPayment(
    'https://x402-api.fly.dev/api/yield-scanner?chain=base&min_tvl=1000000'
  )
).json();
console.log('Top yield:', yields.data[0].protocol, yields.data[0].apy + '%');
Python · pip install x402
from x402.client import X402Client
from eth_account import Account

# 1. Load your private key
account = Account.from_key(os.environ["PRIVATE_KEY"])

# 2. Create client (auto-handles 402 → pay → retry)
client = X402Client(
    account=account,
    chain_id=8453,   # Base mainnet
    rpc_url="https://mainnet.base.org",
)

# 3. Fetch prices — payment deducted automatically
data = client.get("https://x402-api.fly.dev/api/price-feed")
print(f"BTC: ${data['data']['core'][0]['price_usd']:,.0f}")

# Token security scan
scan = client.get(
    "https://x402-api.fly.dev/api/token-scanner",
    params={"token": "PEPE", "chain": "ethereum"}
)
print(f"PEPE risk: {scan['data']['risk_level']} ({scan['data']['risk_score']}/100)")
Shell — Manual 402 flow
# Step 1: Probe — get payment requirements (returns 402)
curl -s https://x402-api.fly.dev/api/price-feed | jq .

# Response: 402 Payment Required
{
  "x402Version": 1,
  "error": "Payment Required",
  "accepts": [{
    "scheme": "exact",
    "network": "base",
    "asset": "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
    "payTo": "0x60264c480b67adb557efEd22Cf0e7ceA792DefB7",
    "maxAmountRequired": "1000"
  }]
}

# Step 2: Sign EIP-3009 transferWithAuthorization on Base
# (use x402-fetch or Coinbase SDK — do not do this by hand in prod)

# Step 3: Retry with X-Payment header (base64 JSON payload)
curl -s https://x402-api.fly.dev/api/price-feed \
  -H "X-Payment: <base64-encoded-payment-payload>" | jq .data.core

# Response: 200 OK — live crypto prices
[
  { "id": "bitcoin",  "price_usd": 98000, "change_24h_pct": 2.1  },
  { "id": "ethereum", "price_usd": 2750,  "change_24h_pct": -0.8 },
  { "id": "solana",   "price_usd": 185,   "change_24h_pct": 4.2  }
]
TypeScript · Agent using multiple endpoints in one session
// DeFi scout agent — scans for arb opportunities using x402-api
const BASE_URL = 'https://x402-api.fly.dev';

async function defiScout() {
  // Pay 0.008 USDC — get funding rate arb opportunities
  const { arb_opportunities } = await (
    await fetchWithPayment(`${BASE_URL}/api/funding-rates?asset=ETH`)
  ).json();

  const strong = arb_opportunities.filter(o => o.signal === 'STRONG');
  if (!strong.length) return console.log('No strong arb opportunities.');

  const best = strong[0];
  console.log(`🎯 ${best.asset}: long ${best.long_venue}, short ${best.short_venue}`);
  console.log(`   Spread: ${best.spread_bps}bps · APR: ${best.annualized_arb_pct}%`);

  // Pay 0.008 USDC — check gas before execution
  const { data: gas } = await (
    await fetchWithPayment(`${BASE_URL}/api/gas-tracker`)
  ).json();
  console.log(`⛽ Arbitrum gas: ${gas.arbitrum.gas_price_gwei.fast} gwei fast`);
}

defiScout();
// Total cost per run: 0.001 + 0.008 = 0.009 USDC (~$0.009)
Request / Response Flow
Step 1 — Initial Request (→ 402)
GET /api/price-feed HTTP/1.1
Host: x402-api.fly.dev
Response 402 Payment Required
{
  "x402Version": 1,
  "error": "Payment Required",
  "accepts": [{
    "scheme": "exact",
    "network": "base",
    "asset": "0x833589fC...",
    "payTo": "0x60264c48...",
    "maxAmountRequired": "1000",
    "extra": { "chainId": 8453 }
  }]
}
Step 2 — With Payment (→ 200)
GET /api/price-feed HTTP/1.1
X-Payment: eyJ4NDAyVmVyc2lvbiI6MSwidHlwZSI6...
Response 200 OK
{
  "timestamp": "2026-02-22T09:35:00Z",
  "source": "CoinGecko",
  "payment": {
    "verified": true,
    "amount": "1000"
  },
  "data": {
    "core": [
      { "id": "bitcoin",
        "price_usd": 98000,
        "change_24h_pct": 2.1 }
    ]
  }
}