Toolman 100% local

AI Tools

Utilities for working with large language models.

More detailsTools for working with language models · What the token counter is for · Rules of thumb · Related

Tools for working with language models

Building anything on top of an LLM means dealing in tokens: they determine the cost of every API call, whether a prompt fits the context window, and how long a response takes to start. But tokens are invisible — you cannot count them by looking at text, and the relationship to characters shifts with the language and content type.

What the token counter is for

The AI token counter estimates how many tokens a piece of text costs across GPT, Claude, Gemini and Llama, and what that works out to per API call. It is useful when you are:

  • Trimming a system prompt. A prompt that runs on every single request is where cost savings compound fastest.
  • Debugging a context-length error. The number in the error message means nothing until you can measure your own input against it.
  • Sizing chunks for retrieval. Knowing the character-to-token ratio for your actual content lets you pick a chunk size that fits.
  • Estimating a bill before you run a batch. Multiplying one document's token count by the batch size is a five-second sanity check that has saved a lot of surprises.

Rules of thumb

ContentApproximate ratio
English prose~4 characters per token
Source code~3–3.5 characters per token
Chinese, Japanese, Korean~1–1.5 characters per token
Base64 or random stringsclose to 1 token per 2 characters

Output tokens usually cost several times more than input tokens, which is why capping response length is often the fastest way to cut a bill. Note that images and audio count too — a vision model converts an image into a block of tokens based on its resolution.

Related

For counting plain words and characters rather than tokens, use the word counter. To inspect the JSON going in and out of an API, the JSON formatter reports the exact position of a syntax error.