PHPackages                             your1/tokenizer-x - 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. [Parsing &amp; Serialization](/categories/parsing)
4. /
5. your1/tokenizer-x

ActiveLibrary[Parsing &amp; Serialization](/categories/parsing)

your1/tokenizer-x
=================

TokenizerX calculates required tokens for given prompt

1.0.1(1y ago)0273MITPHPPHP ^7.4

Since Mar 28Pushed 1y agoCompare

[ Source](https://github.com/YOUR1/tokenizer-x)[ Packagist](https://packagist.org/packages/your1/tokenizer-x)[ Docs](https://github.com/rajentrivedi/tokenizer-x)[ RSS](/packages/your1-tokenizer-x/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)DependenciesVersions (3)Used By (0)

Calculates the OpenAI tokens for the given prompt
=================================================

[](#calculates-the-openai-tokens-for-the-given-prompt)

[![Latest Version on Packagist](https://camo.githubusercontent.com/e5cfde66635be04deaae49d2faa3c47cc9914394eea6a753eafc6c4861cd6978/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f72616a656e747269766564692f746f6b656e697a65722d782e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rajentrivedi/tokenizer-x)

[![GitHub Code Style Action Status](https://camo.githubusercontent.com/0ba8471f6d7848fe85d36a90a990836de8fac10723cce2622c9ef2ef121c9527/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f72616a656e747269766564692f746f6b656e697a65722d782f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/rajentrivedi/tokenizer-x/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/e3afd59c0f3d99a5d9ef8e9b9e5a83363d4cbca60271f8fb9d118072eaf6f686/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f72616a656e747269766564692f746f6b656e697a65722d782e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/rajentrivedi/tokenizer-x)

TokenizerX supports Laravel 11 and Laravel 10.

### Installation

[](#installation)

```
    composer require rajentrivedi/tokenizer-x
```

TokenizerX
----------

[](#tokenizerx)

TokenizerX is a Laravel package designed to streamline tokenization processes in your applications. With the latest update, TokenizerX now supports cutting-edge GPT-4 models, providing advanced natural language processing capabilities.

It calculates the tokens required for a given prompt before requesting the OpenAI REST API. This package helps to ensure that the user does not exceed the OpenAI API token limit and can generate accurate responses.

To access the OpenAI Rest API, you may consider the beautiful Laravel Package [OpenAI PHP](https://github.com/openai-php/client).

Supported OpenAI Models
-----------------------

[](#supported-openai-models)

- gpt-4o
- gpt-4
- gpt-3.5-turbo
- text-davinci-003
- text-davinci-002
- text-davinci-001
- text-curie-001
- text-babbage-001
- text-ada-001
- davinci
- curie
- babbage
- ada
- code-davinci-002
- code-davinci-001
- code-cushman-002
- code-cushman-001
- davinci-codex
- cushman-codex
- text-davinci-edit-001
- code-davinci-edit-001
- text-embedding-ada-002
- text-similarity-davinci-001
- text-similarity-curie-001
- text-similarity-babbage-001
- text-similarity-ada-001
- text-search-davinci-doc-001
- text-search-curie-doc-001
- text-search-babbage-doc-001
- text-search-ada-doc-001
- code-search-babbage-code-001
- code-search-ada-code-001

Supported Encoding
------------------

[](#supported-encoding)

- r50k\_base
- p50k\_base
- p50k\_edit
- cl100k\_base

Installation
------------

[](#installation-1)

You can install the package via composer:

```
composer require rajentrivedi/tokenizer-x
```

Usage
-----

[](#usage)

By default package will consider GPT-3 model

```
use Rajentrivedi\TokenizerX\TokenizerX;
TokenizerX::count("how are you?");
```

If you want token counts for specific OpenAI model, you can pass model as a second argument from above given supported model list.

```
use Rajentrivedi\TokenizerX\TokenizerX;
TokenizerX::count("how are you?", "gpt-4");
```

You can also read the text from file

```
TokenizerX::count(file_get_contents('path_to_file'));
```

Please make sure that text of the file don't change while reading the file programmatically, this may happen due to encoding. You can check the generated token IDs by using following

```
TokenizerX::tokens(file_get_contents('path_to_file'));
```

This will return an array of tokens generated &amp; compare those token IDs with [OpenAI Tokenizer](https://platform.openai.com/tokenizer)

You can also use the OpenAI Tokenizer to double-check package generated token counts.

Support
-------

[](#support)

If you find TokenizerX helpful and would like to support its ongoing development, you can contribute by buying me a coffee! Your support helps in maintaining and improving the package for the Laravel community.

[![ko-fi](https://camo.githubusercontent.com/201ef269611db7eb6b5d08e9f756ab8980df3014b64492770bdf13a6ed924641/68747470733a2f2f6b6f2d66692e636f6d2f696d672f676974687562627574746f6e5f736d2e737667)](https://ko-fi.com/T6T4T0NM4)

Testing
-------

[](#testing)

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

⭐ Star the Repository ⭐
-----------------------

[](#-star-the-repository-)

If you find this project useful or interesting, I kindly request you to give it a ⭐ star on GitHub. Your support will encourage and motivate me to continue improving and maintaining this project.

By starring the repository, you can show appreciation for the work put into developing this open-source project. It also helps to increase its visibility, making it more accessible to other developers and potentially attracting contributors.

To give a ⭐ star, simply click on the **Star** button at the top-right corner of the repository page.

Credits
-------

[](#credits)

- [Rajen Trivedi](https://github.com/rajentrivedi)
- [All Contributors](../../contributors)

License
-------

[](#license)

TokenizerX is developed using
=============================

[](#tokenizerx-is-developed-using)

- [GPT-3 Encoder PHP](https://github.com/CodeRevolutionPlugins/GPT-3-Encoder-PHP)
- [Tiktoken-php](https://github.com/yethee/tiktoken-php)
- [Laravel Package Skeleton by Spatie](https://github.com/spatie/package-skeleton-laravel)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance46

Moderate activity, may be stable

Popularity11

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity38

Early-stage or recently created project

 Bus Factor1

Top contributor holds 61.9% 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

Every ~2 days

Total

2

Last Release

413d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/2afbde5126c60557333240dff2896c67b055ab9786571431c7e647981e906c77?d=identicon)[YOUR1](/maintainers/YOUR1)

---

Top Contributors

[![rajentrivedi](https://avatars.githubusercontent.com/u/69707769?v=4)](https://github.com/rajentrivedi "rajentrivedi (39 commits)")[![rajenindianic](https://avatars.githubusercontent.com/u/94968368?v=4)](https://github.com/rajenindianic "rajenindianic (13 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (5 commits)")[![YOUR1](https://avatars.githubusercontent.com/u/3681016?v=4)](https://github.com/YOUR1 "YOUR1 (3 commits)")[![mechelon](https://avatars.githubusercontent.com/u/26432041?v=4)](https://github.com/mechelon "mechelon (1 commits)")[![gaichao168](https://avatars.githubusercontent.com/u/20994327?v=4)](https://github.com/gaichao168 "gaichao168 (1 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (1 commits)")

---

Tags

phplaravellanguageprocessingtokennaturalcodexGPT-3openaidall-etokenizerchatChatGptchat gptcl100k\_basetokenizer-xr50k\_basep50k\_basep50k\_edit

### Embed Badge

![Health badge](/badges/your1-tokenizer-x/health.svg)

```
[![Health](https://phpackages.com/badges/your1-tokenizer-x/health.svg)](https://phpackages.com/packages/your1-tokenizer-x)
```

###  Alternatives

[rajentrivedi/tokenizer-x

TokenizerX calculates required tokens for given prompt

91214.0k3](/packages/rajentrivedi-tokenizer-x)[openai-php/laravel

OpenAI PHP for Laravel is a supercharged PHP API client that allows you to interact with the Open AI API

3.7k7.6M74](/packages/openai-php-laravel)[openai-php/client

OpenAI PHP is a supercharged PHP API client that allows you to interact with the Open AI API

5.8k22.6M232](/packages/openai-php-client)

PHPackages © 2026

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