How to Count DeepSeek V4 Tokens
For raw text, use the tokenizer published with the exact DeepSeek V4 checkpoint. Tiktokenizer loads that tokenizer in the browser and exposes the resulting token boundaries and IDs. DeepSeek V4 Pro and V4 Flash are released as one model family and use the same model-specific counting workflow.
For a complete API request, treat the provider's usage response as authoritative. A serving stack can apply a chat template, insert role markers and special tokens, serialize tool definitions, or account for reasoning and cache usage beyond the text pasted into a local counter.
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained(
"deepseek-ai/DeepSeek-V4-Flash"
)
text = "Count this DeepSeek V4 prompt."
token_ids = tokenizer.encode(text, add_special_tokens=False)
print(len(token_ids), token_ids)DeepSeek V4 Pro vs V4 Flash Token Counting
The Pro and Flash variants differ in model size, capability, speed, and price, but token counting should still be tied to the published V4 tokenizer and the request template used by your inference provider. You do not need to estimate V4 tokens with an OpenAI encoding.
The current DeepSeek API lists a 1M-token context and a maximum output of 384K tokens for both variants. It identifies the current Flash service version as DeepSeek-V4-Flash-0731.
| Variant | API model ID | Context window | Recommended count |
|---|---|---|---|
| DeepSeek V4 Pro | deepseek-v4-pro | 1,048,576 | Published V4 tokenizer + API usage |
| DeepSeek V4 Flash | deepseek-v4-flash | 1,048,576 | Published V4 tokenizer + API usage |
What the Local DeepSeek Count Includes
- The token IDs produced from the exact text entered in the browser.
- Model-specific vocabulary and pre-tokenization behavior from the published tokenizer.
- No automatic guarantee that a third-party inference provider uses an identical chat template.
- No hidden reasoning, tool-call, cache, image, or generated-output usage.
DeepSeek V4 Migration Note
DeepSeek announced the V4 preview on April 24, 2026, and the legacy deepseek-chat and deepseek-reasoner names became inaccessible after July 24, 2026 at 15:59 UTC. Applications should use the explicit deepseek-v4-pro or deepseek-v4-flash model ID and recount representative prompts under the V4 request format.
Do not reuse a DeepSeek R1 count as a V4 billing or context guarantee. Even when two model generations produce similar raw-text results, a changed tokenizer configuration or serving template can alter the complete request.
Tiktokenizer Reference Sources
Tokenizer behavior and model limits change. Verify production decisions with current provider documentation: