Download the PHP package frolaxhq/laravel-llm-tokenkit without Composer
On this page you can find all versions of the php package frolaxhq/laravel-llm-tokenkit. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download frolaxhq/laravel-llm-tokenkit
More information about frolaxhq/laravel-llm-tokenkit
Files in frolaxhq/laravel-llm-tokenkit
Package laravel-llm-tokenkit
Short Description Token estimation, cost calculation & context-window utilities for LLM-powered Laravel apps
License MIT
Homepage https://github.com/frolaxhq/laravel-llm-tokenkit
Informations about the package laravel-llm-tokenkit
LLM TokenKit for Laravel
Token estimation, cost calculation & context-window utilities for LLM-powered Laravel apps.
TokenKit is a stateless Laravel package that helps you:
- 📊 Estimate tokens for text and chat message arrays
- 💰 Calculate costs based on provider-specific pricing
- 📐 Build context windows with rolling window and token-budget truncation strategies
No database, no migrations, no external API calls. Works offline.
Installation
Publish the config file:
Quick Start
Estimate Tokens for Text
Estimate Tokens for Chat Messages
Calculate Cost
You can also pass arrays:
Or provide explicit pricing:
Build Context Window
Or pass an array:
Configuration
Pricing
Pricing is resolved in this order:
- Exact model match —
pricing.providers.{provider}.models.{model} - Wildcard match — e.g.
gpt-4.1*matchesgpt-4.1-mini - Provider default —
pricing.providers.{provider}.default - Global default —
pricing.default
Estimation
Context Builder
Artisan Command
Check which estimation backend is active:
This will report active estimators, detected tokenizer libraries, sample estimates, and pricing configuration. No network calls are made.
⚠️ Important Notes
- Token estimates are approximations. Different providers/models tokenize differently.
- The heuristic estimator uses a
chars/4base rule, which is reasonable for GPT models but may vary. - For non-Latin scripts (Bangla, Hindi, Arabic, CJK), multipliers are applied but accuracy is lower.
- Always compare estimates against actual provider usage before relying on them for billing.
Suggested Defaults for SaaS
If building a SaaS product, consider:
- Adding a 10-15% buffer to cost estimates for safety
- Using
Confidence::Mediumor higher estimates for billing purposes - Regularly updating pricing in your config to match provider changes
- Implementing usage tracking with actual provider-reported tokens alongside estimates
Testing
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-llm-tokenkit with dependencies
spatie/laravel-package-tools Version ^1.16
illuminate/contracts Version ^10.0||^11.0||^12.0||^13.0