tiktoken
A tokenization library developed by OpenAI, based on the Byte Pair Encoding (BPE) algorithm. It is used for text tokenization in models such as ChatGPT.
Core Facts
Token是大语言模型处理文本的基本单位,大约对应0.75个英文单词或1.5个汉字
The GPT series uses tiktoken (based on BPE encoding) for tokenization.
OpenAI provides the open-source tool tiktoken, which allows developers to estimate token counts before calling the API.
Timeline (last 90 days)
Developers should use the tokenizer corresponding to the target model (such as OpenAI's tiktoken or the Hugging Face tokenizers library) for precise token counting.
The o200k_base tokenizer is open-sourced through the tiktoken library, and developers can directly call its encode/decode interfaces.
Every segmentation result in the video comes from actual output of tiktoken 0.14.0.
The project provides a free counter at modelmarket.dev/tools/tool-list-cost that uses the same tokenizer as the statistics and was compared against tiktoken on 120 of HISTOR's tool lists (2.6 million tokens in total), with zero differences.
tiktoken is OpenAI's open-source tokenizer library, and cl100k_base is its commonly used encoding scheme; an English word typically corresponds to 1-2 tokens, while Chinese uses more.
The OpenAI API's logit_bias parameter does not accept the word itself as a key but requires token ID strings, which must be obtained by encoding with the tokenizer matching the model (such as the tiktoken library).
An LLM gateway needs to parse the model field in the request payload to make routing decisions, use tokenizers such as tiktoken to count tokens in messages for token-based rate limiting, translate OpenAI-format tools definitions into Anthropic's input_schema, and extract and accumulate the usage field from each chunk of the response stream to compute cost.
When counting with the tiktoken library and the o200k_base encoding, the smallest git_status tool (no parameters) is only 54 tokens, while the largest search_code tool (five parameters) reaches 193 tokens.
The author's measurements show that the JSON Schema definitions of 18 tools consume 2,388 tokens, averaging 133 tokens per tool, and in a 10-step Agent run they can account for 36% of input tokens and 32% of the total bill.
tiktoken's README gives an average of about 4 bytes of text per token.
16 more timeline events
All Facts (20)
Token是大语言模型处理文本的基本单位,大约对应0.75个英文单词或1.5个汉字
90%VerifiedThe GPT series uses tiktoken (based on BPE encoding) for tokenization.
80%VerifiedOpenAI provides the open-source tool tiktoken, which allows developers to estimate token counts before calling the API.
80%VerifiedOpenAI uses the tiktoken tokenizer for token metering.
70%VerifiedOpenAI has used a variant of BPE since GPT-2, and GPT-4's cl100k_base vocabulary contains approximately 100,000 tokens.
65%VerifiedThe number of tokens consumed by the same Chinese text may differ by 30%–50% across different large model service providers.
65%UnverifiedLLaMA 3的分词器从SentencePiece升级为基于tiktoken的BPE分词器,词表大小扩展至128,256
90%UnverifiedOpenAI's GPT series uses the tiktoken library, with vocabulary sizes typically ranging between 50,000 and 100,000 Tokens
85%Unverifiedttok is a command-line tool built on OpenAI's open-source tiktoken library, used to count the number of tokens in text.
60%Unverifiedtiktoken is OpenAI's open-source tokenizer library, cl100k_base is the encoding scheme used for the GPT-3.5/4 series, and its tokenization results differ from Anthropic Claude's proprietary tokenizer, usually by a single-digit to low-teen percentage.
60%UnverifiedOpenAI uses the tiktoken tokenization algorithm, and Google uses the SentencePiece tokenization algorithm.
60%UnverifiedDevelopers should use the tokenizer corresponding to the target model (such as OpenAI's tiktoken or the Hugging Face tokenizers library) for precise token counting.
50%UnverifiedThe o200k_base tokenizer is open-sourced through the tiktoken library, and developers can directly call its encode/decode interfaces.
50%Unverifiedtiktoken is OpenAI's open-source tokenizer library, and cl100k_base is its commonly used encoding scheme; an English word typically corresponds to 1-2 tokens, while Chinese uses more.
50%UnverifiedThe OpenAI API's logit_bias parameter does not accept the word itself as a key but requires token ID strings, which must be obtained by encoding with the tokenizer matching the model (such as the tiktoken library).
50%UnverifiedAn LLM gateway needs to parse the model field in the request payload to make routing decisions, use tokenizers such as tiktoken to count tokens in messages for token-based rate limiting, translate OpenAI-format tools definitions into Anthropic's input_schema, and extract and accumulate the usage field from each chunk of the response stream to compute cost.
50%UnverifiedWhen counting with the tiktoken library and the o200k_base encoding, the smallest git_status tool (no parameters) is only 54 tokens, while the largest search_code tool (five parameters) reaches 193 tokens.
50%UnverifiedThe author's measurements show that the JSON Schema definitions of 18 tools consume 2,388 tokens, averaging 133 tokens per tool, and in a 10-step Agent run they can account for 36% of input tokens and 32% of the total bill.
50%Unverifiedtiktoken's README gives an average of about 4 bytes of text per token.
50%UnverifiedOpenAI's tokenizer is open source; in JavaScript, js-tiktoken can run in any environment (including the browser), and in Python the corresponding package is tiktoken.
50%