yethee/tiktoken
PHP port of OpenAI tiktoken for fast tokenization. Get encoders by model or encoding name, encode text to token IDs, with default vocab caching and configurable cache dir. Optional experimental FFI lib mode (tiktoken-rs) for better performance on larger texts.
Added support for the following models: 04-mini, gpt-oss, gpt-4.5 and gpt-5
Added an alternative implementation of the encoder using tiktoken-rs library (#27).
Yethee\Tiktoken\Exception\IOError classYethee\Tiktoken\Exception\LibError classYethee\Tiktoken\Encoder\LibEncoder classYethee\Tiktoken\Encoder\NativeEncoder classYethee\Tiktoken\Vocab\VocabLoader::loadFile() methodYethee\Tiktoken\Encoder is now an interface$useLib to Yethee\Tiktoken\EncoderProvider constructor
- public function __construct()
+ public function __construct(private bool $useLib = false)
EncoderProvider::setVocabCache() method:
- public function setVocabCache(string|null $cacheDir): void
+ public function setVocabCache(string $cacheDir): void
o1 models (#18, #19)chatgpt-4o modelsbabbage-002davinci-002text-embedding-3-smalltext-embedding-3-largeo200k_base (GPT-4o) (#14)[BC break] Changed signature of method VocabLoader::load
- public function load(string $uri): Vocab;
+ public function load(string $uri, string|null $checksum = null): Vocab;
EncodeUtil::fromBytes()Encoder::encodeInChunks() method, which allows encode a text in chunks.Cache is enabled by default to avoid performance issues (see #2 and #5)
How can I help you explore Laravel packages today?