Token count · Token Count

by Token count

POSTBaseSolanaArbitrumPolygonMonadAvalancheeip155:1329OptimismFraxtaleip155:42220stellar:pubnetalgorand:wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=

$0.001

per call · USD Coin on Base

Count exact LLM tokens for a string using the real OpenAI BPE (o200k_base for gpt-4o/o-series, cl100k_base for gpt-4/gpt-3.5). Deterministic, offline - budget context windows without calling a model.

Endpoint

POST https://agent402.tools/api/token-count

8

Calls / 30d

2

Unique payers / 30d

Aug 31

Last called

exact

Payment scheme

Call this service

TypeScript · @x402/fetch
import { wrapFetchWithPayment } from "@x402/fetch";
import { privateKeyToAccount } from "viem/accounts";

const account = privateKeyToAccount(process.env.PRIVATE_KEY);
const fetchWithPay = wrapFetchWithPayment(fetch, account);

const res = await fetchWithPay("https://agent402.tools/api/token-count", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    "model": "gpt-4o",
    "text": "hello world"
  }),
});
const data = await res.json();
cURL
curl -X POST \
  "https://agent402.tools/api/token-count" \
  -H "Content-Type: application/json" \
  -d '{"model":"gpt-4o","text":"hello world"}' \
  -H "X-PAYMENT: <signed x402 payment>"

Example response

{
  "characters": 11,
  "encoding": "o200k_base",
  "model": "gpt-4o",
  "tokens": 2
}

Payment details

Pay to0xabf4fabd7c416fb67202e5f9002389fc75e2a9d0
AssetUSD Coin · 0x833589fcd6edb6e08f4c7c32d4f71b54bda02913
NetworksBase, Solana, Arbitrum, Polygon, Monad, Avalanche, eip155:1329, Optimism, Fraxtal, eip155:42220, stellar:pubnet, algorand:wGHE2Pwdvd7S12BL5FaOP20EGYesN73ktiC1qzkkit8=
Schemesexact, upto

Is this your API?

Pin it to the top of AI & Inference and the homepage with a featured placement.

Get featured →

More from Token count & similar services