Home / Guides / How to count LLM tokens and estimate cost

How to count LLM tokens and estimate cost

Count tokens for OpenAI, Claude, and Gemini models offline, then estimate what a batch of texts will cost before you send them to an API.

You are about to send a pile of texts to an AI model. You want to know how many tokens that is, and roughly what it will cost, before the bill arrives. This page shows a free way to check, and a pay-per-use cloud option when you have many files.

What a token is (short version)

A token is a piece of a word. Models bill by tokens, not by characters. One English word is often about 1.3 tokens, but code, other languages, and long numbers can be different. The only honest count is the one the model's own tokenizer would use.

Free ways that do not need our tools

OpenAI's own tokenizer page. For OpenAI models, paste a short sample into OpenAI's tokenizer. That is fine for a quick check of one message. It is awkward for hundreds of rows in a spreadsheet.

tiktoken on your computer. OpenAI publishes a free Python library called tiktoken. You can run it locally and get exact OpenAI counts. Claude and Gemini use different tokenizers, so a count from tiktoken is only an estimate for those models unless you use their own libraries.

If you only need OpenAI counts for a few strings, either of those is enough. You can stop here.

Offline Apify option: LLM Token Counter

LLM Token Counter & Cost Estimator runs on Apify. You paste texts or give links to text files. It counts tokens offline. It does not call OpenAI, Anthropic, or Google, so your text never leaves the run for those APIs.

What it does

  • Exact token counts for common OpenAI models (tiktoken).
  • Clear estimates for Claude and Gemini (those are labeled as estimates).
  • A cost estimate from a dated public price list you can check.
  • Files and paste both work.

What it does not do

  • It does not send your text to any model.
  • It does not guarantee a provider's future prices. Prices change; the Actor notes the price-list date.
  • Claude and Gemini counts are estimates unless you later verify with that provider's own tokenizer.

Price (November 2026): $0.0005 per unique text, for all the models you select in that run. Repeats are free. Failed files are free. Apify also adds a small start fee per run.

1. Open the Actor page.

2. Paste a few sample texts, or give file links.

3. Pick the models you care about.

4. Click Start.

5. Export the dataset. You will see token counts and estimated costs per text.

A short way to choose

Your situationWhat to use
One short OpenAI sampleOpenAI tokenizer (free)
Many texts, offline, OpenAI + estimate for othersApify LLM Token Counter
You already write Python and only need OpenAIFree tiktoken on your own machine

Related guides

These tools are made by Tidy Byte Tools.