DevTools Logo

AI Token Boundary Colorizer

AI Token Boundary Colorizer

See BPE token boundaries and statistics locally in your browser

Tokenize text

Tokenizer boundaries are invisible in plain text but they decide cost, context limits, and even model behavior. This colorizer encodes your text with the OpenAI BPE tokenizers (o200k_base for GPT-4o-class models, cl100k_base for GPT-4/3.5) and renders every token with its own background color, plus token IDs from the vocabulary. Statistics show total tokens, characters, and the characters-per-token ratio so you can estimate prompt costs and see why unusual spellings or code fragments tokenize inefficiently. Tokenizer tables load lazily; all encoding happens locally and nothing is uploaded.

Examples

Known Hello world split

Input
await colorizeTokens("Hello world")
Output
{ segments: [{ 13225, "Hello" }, { 2375, " world" }], tokenCount: 2, charactersPerToken: 5.5 }

The greeting splits into two tokens with 11 characters over 2 tokens.

Cross-encoding comparison

Input
await colorizeTokens("Hello world", "cl100k_base")
Output
{ encoding: "cl100k_base", tokenCount >= 1, segments join to "Hello world" }

Counts may differ between encodings while decoded text always round-trips.

About this tool

AI Token Boundary Colorizer visualizes tokenization with colorizeTokens(text, encoding = o200k_base): the text encodes through gpt-tokenizer, each id decodes back to its surface text, and every segment pairs { id, text, color, index } with tokenCount, characterCount, and charactersPerToken.

Two encodings are supported: o200k_base loads gpt-tokenizer/model/gpt-4o while cl100k_base loads gpt-tokenizer, each cached after the first dynamic import so BPE tables stay out of the initial bundle — Hello world tokenizes as [{ 13225, Hello }, { 2375, world }] under o200k_base.

Rendering is deterministic: colors cycle TOKEN_COLORS in segment order so identical input always produces identical highlighting, empty input returns zero counts with no segments, and unsupported encodings or non-string input throw before any encoding work.

How to use this tool

  1. Paste the text

    Provide any string — segments join back to the exact input.

  2. Pick the encoding

    Use o200k_base for GPT-4o style counts or cl100k_base for older models.

  3. Read the segments

    Check each token id, surface text, and palette color in order.

  4. Use the stats

    Compare tokenCount and charactersPerToken when budgeting context windows.

Use cases

Budgeting context windows

Compare token counts across encodings before sending prompts to a model.

Teaching tokenization

Show how leading spaces merge into tokens like world.

Debugging truncation

Find which token boundary a cutoff lands on via segment order.

Common mistakes

Mistake:Assuming o200k_base and cl100k_base counts match.

Fix:Vocabularies differ, so always compare counts per encoding instead of mixing them.

Mistake:Reading segment text as pre-trimmed words.

Fix:Boundary spaces belong to the following token — join segments to recover exact input.

Mistake:Passing non-string input and expecting zero tokens.

Fix:Only strings tokenize; other types throw a TypeError before encoding.

Frequently asked questions

What does this tool do?

It runs colorizeTokens on text with o200k_base or cl100k_base, returning ordered { id, text, color, index } segments plus tokenCount, characterCount, and charactersPerToken.

How do encodings and colors work?

o200k_base loads the GPT-4o BPE table and cl100k_base loads the older table with per-encoding caching, and colors cycle TOKEN_COLORS in segment order so repeats render identically.

Is my text uploaded or stored?

No. BPE encoding, decoding, and highlighting run fully client-side after the tokenizer module loads.

Why do counts differ, or input throw?

Vocabularies differ between encodings so counts may not match — compare per encoding — and non-string input or unknown encodings throw before any encoding work.

References & standards