How to Count Kimi K3 Tokens
Kimi K3 is now open-weight and its official repository publishes a 160K token vocabulary plus a custom Python tokenizer and XTML message encoder. Tiktokenizer loads a browser-compatible tokenizer conversion derived from those artifacts, so ordinary text entered above is counted with K3 token IDs rather than an o200k_base comparison.
For a complete chat request, ordinary text is only one layer. Kimi K3 uses XTML structural markers for messages, thinking, tools, and responses, and it has model-specific handling for images and other media. Use Moonshot's published tokenizer with trust_remote_code=True or the Kimi API when you need the complete serialized request rather than a raw-text count.
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained(
"moonshotai/Kimi-K3",
trust_remote_code=True,
)
text = "Count this Kimi K3 prompt."
token_ids = tokenizer.encode(text, add_special_tokens=False)
print(len(token_ids))
print(token_ids)Kimi K3 Local Count vs Full Request Usage
The browser counter is appropriate for inspecting prose, Chinese text, source code, JSON, whitespace, and other ordinary text. It does not execute arbitrary Python from the model repository, and it does not attempt to simulate image or video token accounting.
The converted tokenizer has been validated against K3's custom tokenizer for ordinary encoding, but Kimi's custom Python chat renderer remains the reference for XTML conversation structure. The usage returned by a real kimi-k3 API call remains authoritative for provider billing.
| Counting method | Status | Use it for |
|---|---|---|
| Tiktokenizer K3 browser tokenizer | Exact ordinary text | Token boundaries, IDs, and raw text size |
| Official K3 Python tokenizer + XTML encoder | Reference implementation | Messages, thinking, tools, and special tokens |
| Kimi API usage | Provider-authoritative | Real multimodal request usage and billing review |
Kimi K3 Model and Context Facts
Moonshot describes Kimi K3 as an open-weight, native multimodal agentic model for long-horizon coding, knowledge work, and reasoning. The published model has 2.8 trillion total parameters, 104 billion activated parameters, a 160K vocabulary, and a 1,048,576-token context window.
The Kimi API model ID is kimi-k3. Thinking is always enabled for K3, with low, high, and max reasoning-effort settings and max as the documented default. Native visual and video inputs are supported by the API, but their usage should be read from the API rather than inferred from the text vocabulary.
- System and user messages, prior turns, and any preserved reasoning content sent back to the model.
- Tool definitions and tool results used by a long-running coding or research agent.
- Text, images, and video inputs, which do not all follow plain-text tokenization.
- Expected reasoning and final-answer output, because Kimi K3 reasons by default.
Why the Kimi K3 API Count Can Be Higher
A Kimi API request wraps content in the K3 message format and can include system messages, XTML control tokens, reasoning content, tools, images, videos, and prior assistant messages. Those components can increase usage even when the visible user sentence has the same base-text count.
For multi-turn conversations and tool calls, Moonshot instructs clients to send the complete assistant message back on the next turn rather than keeping only its final content. Recount or inspect provider usage whenever the conversation history, tools, media, or reasoning effort changes.
Tiktokenizer Reference Sources
Tokenizer behavior and model limits change. Verify production decisions with current provider documentation: