PHPackages                             mehrab-wj/tiktoken-php - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. mehrab-wj/tiktoken-php

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

mehrab-wj/tiktoken-php
======================

a clone of python tiktoken but for PHP! fast BPE tokeniser for use with OpenAI's models.

v1.0.0(3y ago)1788.5k↑34.5%33MITPHPPHP ^8.1

Since Apr 19Pushed 3y agoCompare

[ Source](https://github.com/mehrab-wj/tiktoken-php)[ Packagist](https://packagist.org/packages/mehrab-wj/tiktoken-php)[ RSS](/packages/mehrab-wj-tiktoken-php/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (5)Versions (2)Used By (3)

TikToken clone for PHP - PHP GPT3 tokenizer
===========================================

[](#tiktoken-clone-for-php---php-gpt3-tokenizer)

PHP Text Tokenizer for GPT models

About
-----

[](#about)

A PHP toolkit to tokenize text like GPT family of models process it.

Forked from [semji/gpt3-tokenizer-php](https://github.com/semji/gpt3-tokenizer-php) to bug fixes and improvement.

Requirements
------------

[](#requirements)

- PHP 8.1
- mbstring extension [details here on how to install mbstring](https://www.php.net/manual/en/mbstring.installation.php)

Usage
-----

[](#usage)

First install the package using composer:

```
composer require mehrab-wj/tiktoken-php
```

```
use TikToken\Encoder;
$prompt = "Ai is cool";
$encoder = new Encoder();

$tokens = $encoder->encode($prompt); // [32, 72, 318, 3608]

// Get tokens count:
echo count($tokens); // 4
```

###  Health Score

36

—

LowBetter than 82% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity41

Moderate usage in the ecosystem

Community16

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 66.7% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Unknown

Total

1

Last Release

1125d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/75be5d76a36e5e4c0279858a690ca98bc1c2aafc559419497641699233b3a2ba?d=identicon)[mehrab-wj](/maintainers/mehrab-wj)

---

Top Contributors

[![srogier](https://avatars.githubusercontent.com/u/814069?v=4)](https://github.com/srogier "srogier (26 commits)")[![CodeRevolutionPlugins](https://avatars.githubusercontent.com/u/91943804?v=4)](https://github.com/CodeRevolutionPlugins "CodeRevolutionPlugins (8 commits)")[![mehrab-wj](https://avatars.githubusercontent.com/u/13809573?v=4)](https://github.com/mehrab-wj "mehrab-wj (5 commits)")

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StylePHP CS Fixer

Type Coverage Yes

### Embed Badge

![Health badge](/badges/mehrab-wj-tiktoken-php/health.svg)

```
[![Health](https://phpackages.com/badges/mehrab-wj-tiktoken-php/health.svg)](https://phpackages.com/packages/mehrab-wj-tiktoken-php)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
