tiktoken
https://github.com/openai/tiktoken
tiktoken is a fast BPE tokeniser for use with OpenAI's models.
例:How to count tokens with tiktoken