Token Studio

Phi-4 Token Counter

Count tokens for Microsoft's Phi-4 models and see how much of their context window your text fills. The real tokenizer runs in your browser.

Runs entirely in your browser Nothing is uploaded
Loading tokenizer…
4.3 MB · one-time
Est. cost
 
Tokens / word
 
Chars / token
 
Characters
327
58 words
Context window
Input text
327characters
270no spaces
58words
4sentences
Token breakdown
Phi-4 · phi-4 (cl100k)
Loading Phi tokenizer · 4.3 MB
Compare models — same text 2 of 55 · click to inspect
Model Tokens Cost
Phi-4
loading tokenizer…
—
Phi-4 Reasoning Plus
loading tokenizer…
—

Counts come from each model's real tokenizer, running entirely in your browser. Cost and context-window figures are estimates for guidance and may vary by model version.

Counting tokens for Phi-4 models

Microsoft publishes Phi-4's tokenizer with the MIT-licensed weights, so the counts on this page are exact. Phi-4 and Phi-4 Reasoning Plus load by default and share one count. Phi-4 Mini uses a different, larger vocabulary, so add it from the compare table to see its own number. All three show as free: the weights are open and small enough to run on your own Mac, so the useful figure here is the context bar rather than the cost. Phi-4 has a 16K window, which a long document fills quickly.

Pricing and context windows

Phi-4 models with their tokenizer and context window. The weights are open under the MIT license, so they show as free.

ModelTokenizerPrice / 1M inputContext window
Phi-4phi-4 (cl100k)Free16K
Phi-4 Reasoning Plusphi-4 (cl100k)Free33K
Phi-4 Minio200k_baseFree131K

Prices and context windows are curated metadata refreshed periodically from the providers and OpenRouter, so treat them as guidance rather than a quote. Token counts are always produced by the real tokenizer.

How Phi-4 tokenization works

Phi-4 reuses OpenAI's cl100k_base vocabulary, the encoding behind GPT-4, padded to 100,352 entries. Microsoft's technical report says Phi-4 switched to the tiktoken tokenizer for better multilingual support. The 100,256 entries and the merge rules are those of cl100k_base; the remaining 96 slots hold Phi's own special tokens for chat formatting and reasoning, which never appear in pasted text. So Phi-4, Phi-4 Reasoning, Phi-4 Reasoning Plus, and Phi-4 Reasoning Vision all count exactly like GPT-4 Turbo: 574 tokens on our fixed 500-word sample.

The Phi-4 Mini line (Mini, Mini Reasoning, Mini Flash Reasoning, and Multimodal) uses o200k_base instead, the 200,000-entry vocabulary behind GPT-4o and GPT-5. It packs text a little tighter, especially code and non-English text, so this page loads that encoding for Phi-4 Mini and counts it separately.

Frequently asked questions

Is this Phi-4's official tokenizer?

Yes. It is the tokenizer file shipped with the weights on Hugging Face. The vocabulary is cl100k_base with Microsoft's special tokens appended, and the text is tokenized in your browser, so the count is exact and nothing is uploaded. Ollama and llama.cpp load the same vocabulary, so the number matches what you see when running the model locally.

Do Phi-4 and Phi-4 Mini tokenize the same way?

No. Phi-4 uses cl100k_base and Phi-4 Mini uses o200k_base. Ordinary English lands close on both, but Mini's larger vocabulary usually needs fewer tokens on code and other languages. Add Phi-4 Mini from the compare table to see both counts for your text.

How much of Phi-4's 16K context will my text use?

The context bar above the editor shows the share of the window your text fills. Phi-4 has a 16,384-token window and Phi-4 Reasoning Plus 32,768, so a few pages of text is a meaningful fraction. A reasoning model also spends part of the window on its thinking trace before it answers, so leave room for the reply.

Which Phi models does this cover?

Phi-4, Phi-4 Reasoning Plus, and Phi-4 Mini, plus the variants that share their tokenizers. Phi-4 Reasoning and Phi-4 Reasoning Vision count like Phi-4; Phi-4 Mini Reasoning, Mini Flash Reasoning, and Phi-4 Multimodal count like Phi-4 Mini. The older Phi-3 models use a different 32,000-entry vocabulary and are not covered.