02 · Tokenizer Playground
Code Walkthrough
Six steps from "mock numbers" to counts that match the provider's own tokenizer — with no API, no key and no text leaving the browser.
js-tiktoken/lite is the encoder without any bundled vocabulary — you feed it the ranks yourself, which is what keeps the initial bundle small.
TypeScriptimport { Tiktoken } from "js-tiktoken/lite"; const ranks = (await import("js-tiktoken/ranks/o200k_base")).default; const encoder = new Tiktoken(ranks); encoder.encode("tokenizer"); // [30075, 3213]
Try it against the real thing
Paste the same string into the OpenAI tokenizer — the counts will agree.
tokenizer — playground
GPT-4o · GPT-4.1 · o-series
- Tokens
- —
- Characters
- 34
- Chars / token
- —
Loading o200k_base merge ranks…
Real GPT tokenizer (o200k_base, 199,998 tokens) running entirely in your browser — same BPE merges as the OpenAI tokenizer, no API calls and no keys.