💳 Pay‑per‑call with x402

Use your crypto wallet to pay per API call using x402. No API key is required when using x402.

📺 Integration Tutorials & Demos

How it works

  • Set up an x402 client by following the official Quickstart for Buyers guide: x402 Quickstart for Buyers
  • Call any endpoint and add these headers:
    • x-coinbase-402: true (required) — tells our API to handle this as an x402 payment flow
    • x-payment-token: usdc | tmai (optional) — choose the token to pay with. Defaults to usdc. Using tmai applies a 10% discount to the charge amount
  • Do not send x-api-key when using x402 — your wallet and x402 handle payment and access

Minimal examples

Node.js (Axios + x402)

import axios from "axios";
import { withPaymentInterceptor } from "x402-axios";
import { createWalletClient, http } from "viem";
import { privateKeyToAccount } from "viem/accounts";
import { baseSepolia } from "viem/chains";

// Create a wallet account per the x402 Quickstart
const account = privateKeyToAccount(process.env.PRIVATE_KEY);

// Wrap axios instance with x402 payment handling (pass your wallet account)
const api = withPaymentInterceptor(
  axios.create({ baseURL: "https://api.tokenmetrics.com" }),
  account,
);

const res = await api.get("/v2/trading-signals", {
  headers: {
    "x-coinbase-402": "true",
    "x-payment-token": "usdc", // or "tmai" for 10% discount
  },
});
console.log(res.data);

Python (HTTPX + x402)

from x402.clients.httpx import x402HttpxClient
from eth_account import Account
import asyncio
import os

async def main():
    # Create a wallet account per the x402 Quickstart
    account = Account.from_key(os.environ["PRIVATE_KEY"])

    # Use x402 HTTPX client with your wallet account
    async with x402HttpxClient(account=account, base_url="https://api.tokenmetrics.com") as client:
        r = await client.get(
            "/v2/trading-signals",
            headers={
                "x-coinbase-402": "true",
                "x-payment-token": "tmai",  # 10% discount
            },
        )
        print(await r.aread())

asyncio.run(main())

For full x402 client setup and additional samples, see the official docs: x402 Quickstart for Buyers.

Spending limit for TMAI payments (important)

When paying with tmai, please set a maximum amount your wallet is allowed to spend for the request in your x402 client. tmai uses 18 decimals, so values are represented in very small units. To make this simple: set the max to the equivalent of up to 200 TMAI.

  • Node.js (BigInt in wei, the smallest unit):
// 200 TMAI in base units (wei): 200 * 10^18
const maxTmaiWei = 200n * 1000000000000000000n;

// Pass this as the max/spend limit to your x402 client options
// Example (option name may vary by client):
// const api = withPaymentInterceptor(axios.create({ baseURL }), account, { maxPayment: maxTmaiWei });
  • Python:
# 200 TMAI in base units (wei): 200 * 10^18
max_tmai_wei = 200 * (10 ** 18)

# Pass this as the max/spend limit to your x402 client options
# Example (option name may vary by client):
# async with x402HttpxClient(account=account, base_url=base_url, max_payment=max_tmai_wei) as client:

This simply means “allow up to 200 TMAI to be chargeable for this call.” You can pick a different limit if you prefer. If you don’t set this for TMAI, the payment may fail if your client’s default max is too low. For usdc (6 decimals) this is typically not required, but you may still set a limit if you want.

API Endpoints Pricing for Pay-per-call

🆓 Free Endpoints (No Payment Required)

EndpointDescription
/v2/tokensToken metadata and IDs
/v2/priceLive price streams
/v2/top-market-cap-tokensTokens ranked by market cap

💡 $0.017 USDC / $0.0153 TMAI

EndpointDescription
/v2/trading-signalsEntry/exit signals
/v2/hourly-ohlcvHourly historical prices
/v2/daily-ohlcvDaily historical prices

💼 $0.034 USDC / $0.0306 TMAI

EndpointDescription
/v2/resistance-supportPrice levels & volatility
/v2/market-metricsBullish/Bearish indicators
/v2/indicesAI-powered crypto indices
/v2/indices-holdingsIndex components
/v2/indices-performanceIndex returns
/v2/hourly-trading-signalsFrequent short-term signals
/v2/tm-gradeGets the latest TM Grade for a token—including quant grade, buy/sell signals, momentum, and 24-hour percentage changes.
/v2/tm-grade-historyHistorical TM Grade with buy/sell signal trends and momentum changes over time.
/v2/technology-gradeLatest technology grade covering development activity, security, and innovation.
/v2/technology-grade-historyLatest technology grade covering development activity, security, and innovation.
/v2/fundamental-gradeLatest fundamental grade based on project quality, adoption, and market potential.
/v2/fundamental-grade-historyHistorical fundamental grade trends over time.

🚀 $0.068 USDC / $0.0612 TMAI

EndpointDescription
/v2/correlationToken correlation analytics
/v2/price-predictionPrice prediction of a crypto asset under different market cap scenarios.
/v2/ai-reportsToken/market research
/v2/quantmetricsInvestor activity & ranking
/v2/crypto-investorsOn-chain investor tracking
/v2/moonshot-tokensAI-curated high potential tokens
/v2/tmaiToken Metrics AI Chatbot