PHPackages                             sundance-solutions/larachain-token-count - 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. sundance-solutions/larachain-token-count

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

sundance-solutions/larachain-token-count
========================================

Quick helper to count tokens

1.0.0(2y ago)49.1k↓33.3%1[2 PRs](https://github.com/alnutile/larachain-token-count/pulls)MITPHPPHP ^8.1

Since May 31Pushed 2y ago1 watchersCompare

[ Source](https://github.com/alnutile/larachain-token-count)[ Packagist](https://packagist.org/packages/sundance-solutions/larachain-token-count)[ Docs](https://github.com/sundance-solutions/larachain-token-count)[ RSS](/packages/sundance-solutions-larachain-token-count/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (1)Dependencies (12)Versions (4)Used By (0)

Quick helper to count tokens
============================

[](#quick-helper-to-count-tokens)

**GO USE  👉**

Below is supersceded by the above ☝️
====================================

[](#below-is-supersceded-by-the-above-️)

[![Latest Version on Packagist](https://camo.githubusercontent.com/097efa7ad96e73882eed87c41ad5c54d2194828e0abc8df0f26e950faf945c88/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f73756e64616e63652d736f6c7574696f6e732f6c617261636861696e2d746f6b656e2d636f756e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sundance-solutions/larachain-token-count)[![GitHub Tests Action Status](https://camo.githubusercontent.com/fbcada7016cb5c64261835f80495e0244b3270b8ca13b831f79026238fa236e9/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73756e64616e63652d736f6c7574696f6e732f6c617261636861696e2d746f6b656e2d636f756e742f72756e2d74657374732e796d6c3f6272616e63683d6d61696e266c6162656c3d7465737473267374796c653d666c61742d737175617265)](https://github.com/sundance-solutions/larachain-token-count/actions?query=workflow%3Arun-tests+branch%3Amain)[![GitHub Code Style Action Status](https://camo.githubusercontent.com/da8b79838867a58e6f02ac4416a7be64012bec95bbf1d82e7656dc97da48fcf3/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f616374696f6e732f776f726b666c6f772f7374617475732f73756e64616e63652d736f6c7574696f6e732f6c617261636861696e2d746f6b656e2d636f756e742f6669782d7068702d636f64652d7374796c652d6973737565732e796d6c3f6272616e63683d6d61696e266c6162656c3d636f64652532307374796c65267374796c653d666c61742d737175617265)](https://github.com/sundance-solutions/larachain-token-count/actions?query=workflow%3A%22Fix+PHP+code+style+issues%22+branch%3Amain)[![Total Downloads](https://camo.githubusercontent.com/635a0c7cd8ecd166b99b476d5f7279a0685e23692091ca0ab005f8b00b4d3836/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f73756e64616e63652d736f6c7574696f6e732f6c617261636861696e2d746f6b656e2d636f756e742e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/sundance-solutions/larachain-token-count)

GPT-3 Approximate Token Counter in PHP

This repository contains a PHP function that approximates the token count of a text string, following the tokenization rules used by OpenAI's GPT-3.

GPT-3, an advanced language model developed by OpenAI, reads text in chunks called tokens. A token in GPT-3 can be as short as one character or as long as one word (e.g., 'a', 'apple'). For languages with more complex scripts (like Chinese, Japanese, etc.), one character can be multiple tokens. Spaces and punctuation are also considered separate tokens.

The function provided here offers an approximation of how GPT-3 might tokenize a given string, counting words, spaces, and punctuation as separate tokens. This allows you to estimate the number of tokens in a text string without making an API call, which can be useful for monitoring usage or avoiding unnecessary costs.

Please note that this is a simplified approximation, and the actual tokenization may vary slightly in GPT-3's actual implementation. In particular, some words might be tokenized into multiple tokens if they contain special characters or are very long. Additionally, this method may not accurately tokenize languages other than English, especially those using non-Latin characters.

As of the last update in September 2021, OpenAI has not provided a public method for accurately counting tokens the way GPT-3 does. Therefore, this function is an estimation, not a guaranteed accurate count.

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

[](#installation)

You can install the package via composer:

```
composer require sundance-solutions/larachain-token-count
```

Usage
-----

[](#usage)

```
use SundanceSolutions\LarachainTokenCount\Facades\LarachainTokenCount;

    $text = "Your document text...";
    $results = LarachainTokenCount::count($text);
    expect($results)->toEqual(8);
```

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.

Credits
-------

[](#credits)

- [Alfred Nutile](https://github.com/alnutile)
- [All Contributors](../../contributors)

License
-------

[](#license)

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

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity29

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity55

Maturing project, gaining track record

 Bus Factor1

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

1083d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/da51f2fb140a4e118e94dd59ff819c11dd9a656b9c0ff8b2074c5fd2c07978ee?d=identicon)[alnutile](/maintainers/alnutile)

---

Top Contributors

[![alnutile](https://avatars.githubusercontent.com/u/365385?v=4)](https://github.com/alnutile "alnutile (6 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (2 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (2 commits)")

---

Tags

laravelsundance-solutionslarachain-token-count

###  Code Quality

TestsPest

Code StyleLaravel Pint

### Embed Badge

![Health badge](/badges/sundance-solutions-larachain-token-count/health.svg)

```
[![Health](https://phpackages.com/badges/sundance-solutions-larachain-token-count/health.svg)](https://phpackages.com/packages/sundance-solutions-larachain-token-count)
```

###  Alternatives

[spatie/laravel-data

Create unified resources and data transfer objects

1.8k28.9M627](/packages/spatie-laravel-data)[spatie/laravel-livewire-wizard

Build wizards using Livewire

4061.0M4](/packages/spatie-laravel-livewire-wizard)[hirethunk/verbs

An event sourcing package that feels nice.

513162.9k6](/packages/hirethunk-verbs)[worksome/exchange

Check Exchange Rates for any currency in Laravel.

123544.7k](/packages/worksome-exchange)[ralphjsmit/livewire-urls

Get the previous and current url in Livewire.

82270.3k4](/packages/ralphjsmit-livewire-urls)[hydrat/filament-table-layout-toggle

Filament plugin adding a toggle button to tables, allowing user to switch between Grid and Table layouts.

6292.3k1](/packages/hydrat-filament-table-layout-toggle)

PHPackages © 2026

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