Token Analyzer
A small Streamlit tool that counts tokens and estimates the cost of a prompt across 8 LLMs from OpenAI, Google and Anthropic.
Overview
I kept guessing how many tokens my prompts were, so I made a one-page tool for it. Paste text (or a system + user prompt) and it shows the token count, the token IDs, how the text splits into tokens, and roughly what it would cost on each model.
Problem
Every provider tokenizes differently, and Gemini and Claude don't ship a local tokenizer, so you can't count their tokens exactly offline.
Approach
The 4 OpenAI models use tiktoken for exact counts. The 4 Gemini/Claude models use a ~4 characters per token estimate, and the app clearly says it's an estimate. Cost is tokens ÷ 1M × the price per 1M tokens.
Architecture / how it works
- One
MODEL_CONFIGdict holds each model's tokenizer, provider, price per 1M and an exact-or-estimate flag. get_tokenizer()picksget_encoding()orencoding_for_model()depending on the model.- The per-token breakdown is hidden for estimated models, since it would be made up.
- An optional side-by-side with the gpt-4o-mini tokenizer.
Tech stack
Outcomes
It does its job. The prices are hardcoded, though, so they go stale whenever a provider changes its pricing.