Docs · Input pipeline 01

Text and source-code token counting

Technical reference for browser-based text and source-code token counting, OpenAI BPE vocabularies, UTF-8 projections, and result accuracy labels.

Text remains in the browser. The calculator selects either a local tokenizer vocabulary or a disclosed deterministic provider-family projection, then reports the method next to the result.

Workflow mapBrowser text-counting path
01Text or codePaste or readable file
02Normalize inputUnicode and UTF-8
03Model methodBPE or projection
04Token resultAccuracy label included
The selected model determines whether the exact local BPE path or a disclosed provider-family projection is used.

Text pipeline

  1. Decode pasted or file text into a JavaScript Unicode string.
  2. Encode with the selected local BPE vocabulary, or measure UTF-8 bytes for the provider projection.
  3. Add extracted text across supported files.
  4. Apply the selected model's price and context limit.

Exact local BPE path

OpenAI-family raw text uses js-tiktoken with the model registry's configured encoding, including o200k_base where applicable. “Exact” describes segmentation of that raw string under that vocabulary. It does not include chat framing, tools, hosted file processing, or server instructions.

Provider-calibrated UTF-8 projection

When a provider does not distribute an equivalent offline production tokenizer, the calculator divides UTF-8 byte length by a versioned provider-family coefficient. This path is deterministic and reproducible, but it is a projection. Claude, Gemini, and DeepSeek API usage remains authoritative.

Why code behaves differently

Identifiers, punctuation, whitespace, escaped strings, hashes, and minified content change segmentation density. Count the real artifact rather than converting characters or words with a universal ratio. Supported source files enter the same text pipeline without remote upload.

Practical counting examples

InputWhat changes token densityRecommended check
Natural-language promptLanguage, punctuation, and repeated contextCount the final system and user text together.
JSON or tool schemaProperty names, braces, escaping, and examplesMeasure the exact serialized payload.
Source codeIdentifiers, indentation, comments, and minificationUpload the real source file instead of estimating from lines.
Logs or CSVRepeated timestamps, IDs, delimiters, and long valuesCount a representative production sample.

Exact count versus provider bill

An exact local BPE result describes segmentation of the supplied string. Provider usage can still include hidden instructions, message wrappers, tool definitions, cached prefixes, reasoning tokens, or generated output. Treat the local count as a reproducible preflight measurement and reconcile production billing with the API response.

Open the calculator · Read the complete methodology