Token count API tester
Stop guessing token counts. This tool sends your text to OpenAI or Anthropic with your own API key and returns the exact token total the provider reports — the same number you are billed for — rather than a local heuristic estimate. It is the reliable way to verify a production prompt fits your context window and budget.
How it works
Each provider exposes the true tokenizer behind its API:
- Anthropic has a dedicated
count_tokensendpoint that returns input token count for a given model and message with no generation cost. - OpenAI does not expose a standalone counter, so the tool sends a minimal
request with a tiny
max_tokensand readsusage.prompt_tokensfrom the response, which is the exact tokenization of your input.
Your key never touches this site’s servers — the request goes straight from your browser to the provider over HTTPS.
When exact counts matter vs when estimates are fine
For most prompt sizing and cost-budgeting tasks, a local heuristic estimate (roughly 4 characters per token for English) is accurate enough. The gap between an estimate and the true count is typically 2–8% for ordinary prose, which is within acceptable budgeting margin.
Exact counts via API become worth the effort when:
- You are packing close to the context limit. If your assembled prompt is 127,500 tokens and the window is 128,000, a 3% estimation error means the difference between fitting and truncating. Getting the real count avoids guessing.
- You are building a production cost accounting system. If you are charging customers based on token usage or tracking spend precisely, billable-exact counts from the provider are the right input — not estimates.
- You are debugging tokenization. Code, unicode characters, emoji, and mixed-language text can tokenise very differently across model families. Seeing the real count confirms what the model actually sees.
- You are validating new model families. When a provider releases a new model that may use a different tokenizer, your existing estimates may be miscalibrated. A quick API count check tells you whether the estimates still hold.
API key security
Your key is held only in your browser’s memory for the duration of the request and sent directly to the provider over HTTPS. It is never transmitted to this site’s servers, stored in cookies, or logged.
Best practice: create a restricted API key with a low spending cap or a limited permission scope for testing, so that even if a browser session is compromised, the exposure is bounded. For OpenAI, you can create keys under “API keys” in the dashboard and set a per-key usage limit. For Anthropic, use a key scoped to your development project with an appropriate monthly budget cap.
Tips and notes
- Match the model. Tokenization differs slightly across model families, so pick the model you will actually call.
- Use it for context-window checks. Compare the returned count against the model’s context limit before shipping a long-document prompt to production.
- Keep keys safe. Use a restricted or low-quota key for testing, and rotate it if you ever paste it into a shared machine.