Skip to content
Rapid Router
← API reference

Token counting

Part of the Rapid Router API reference. One OpenAI-compatible endpoint, https://rapidrouter.ai/api/v1, in front of every model in the catalog.

33Token counting

POST /v1/tokenize counts the tokens in a string or a chat messages array without calling a model. It is unauthenticated on purpose, counting tokens reveals nothing about an account, and rate limited to 30 requests a minute per IP with at most 1,000,000 characters of input per request.

curl https://rapidrouter.ai/api/v1/tokenize \
  -H "Content-Type: application/json" \
  -d '{ "model": "openai/gpt-4o", "text": "How many tokens is this?" }'

# -> { "ok": true, "data": { "tokens": 6, "exact": true, "encoding": "o200k_base" } }

OpenAI-family models count exactly via tiktoken and report exact: true with the encoding used. Every other family gets a characters divided by 3.6 estimate, rounded up and clearly labelled exact: false with encoding: null: a made-up exact count for a tokenizer we do not have would be worse than an honest estimate.