Gemini token counter

Google exposes a free countTokens endpoint that returns the exact number the Gemini API bills. This counter uses it, so the count matches your invoice rather than approximating it.

Why the exact count matters more on Gemini

Gemini 2.5 Pro has a pricing tier boundary at 200,000 input tokens: prompts above it bill at double the input rate and a higher output rate. An estimate that is off by 15% around that line does not just misprice your request, it can put you on the wrong side of a 2x price step without you noticing. If your prompts run long, count before you send. The tier mechanics are laid out on the Gemini API pricing page.

Counting notes

Other counters: Claude · OpenAI · methods in how we count