mis3085/tiktoken-for-laravel
TikToken for Laravel brings OpenAI's tiktoken tokenizer to your app, letting you count, encode, and decode tokens for GPT models through a simple facade. Estimate API costs, trim prompts to fit context limits, and integrate token counts into validation, logging, or usage tracking.
cl100k_base/o200k_base drift problem — a small but real maintenance tax.Adopt when:
new calls.Look elsewhere when:
count_tokens, Gemini's countTokens) or a provider-agnostic abstraction.usage for anything customer-facing or financially material.Adoption gate I'd set: wrap it behind your own narrow interface (TokenCounter::count(string $text, string $model): int) on day one. The wrapper is cheap; the lock-in isn't the point. That way a swap to a provider endpoint or a Rust-backed service is a one-file change, and you can unit-test with a fake counter.
For executives (one paragraph): We currently have no reliable way to predict what an LLM feature costs before it runs, which means our pricing and margin assumptions are guesses and our context-limit handling is reactive. This package adds pre-call token counting to our Laravel stack in a few hours of work: it lets us price usage-based tiers with real numbers, cap runaway spend per customer, and make retrieval quality decisions on evidence. It's MIT-licensed, a thin wrapper over a known tokenizer, and we'll isolate it behind our own interface so the switching cost stays near zero. The risk is maintainer attention on a small project, not technical lock-in — and the exposure is negligible given the wrapper's size.
For engineering:
o200k_base for newer models.usage for billing; PHP port performance is not the Rust original's; pin the version and keep a fallback path.For finance/ops: gives us a per-request cost figure we can attach to a customer, a feature, and an environment — the missing input for usage-based pricing and for forecast-vs-actual reviews.
How can I help you explore Laravel packages today?