Write cleaner prompts. Spend fewer tokens. Build smarter AI apps.
π§ What Problem Does It Solve?
Every time your Laravel app sends data to an AI model β it costs tokens. More tokens = more cost + less context.
But most developers donβt know how heavy their prompt really is.
Thatβs why TOON includes a built-in Token Estimator β a lightweight tool to quickly measure your prompt before sending it to an LLM.
β¨ What Is TOON?
TOON (Token-Optimized Object Notation) is a compact, human-readable data format built for Laravel. It converts PHP arrays / JSON into an AI-friendly format that reduces token usage and improves context clarity.
And now β it can also estimate the token weight of that data.
π’ Token Estimation β The Feature You Actually Need
TOON gives you a native, zero-dependency PHP method to estimate token usage:
use Sbsaga\Toon\Facades\Toon;
$prompt = Toon::convert($data); // Converts JSON/PHP array to TOON format
$stats = Toon::estimateTokens($prompt); // Estimates token usage
dd($stats);
Example Output:
{
"words": 20,
"chars": 182,
"tokens_estimate": 19
}
π‘ Why This Helps Developers
β Spot heavy prompts instantly
β Reduce AI costs before making API calls
β Keep more context inside model limits
β Works locally, in CI, or before production
β No external tokenizer β fully PHP native
π§ Practical Use Cases
| Use Case | How TOON Helps |
|---|---|
| Local development | Measure prompt size while designing AI requests |
| CI check | Fail build if prompt > 3,000 tokens |
| Debugging | Compare JSON vs TOON format side-by-side |
| Optimization | Remove unnecessary data & observe impact |
| LLM cost control | Save real money over large requests |
π Important Note
- This is an approximate estimation, not a billing-accurate tokenizer.
- It is model-agnostic, fast, and perfect for comparison / debugging.
π§ͺ Try It in 20 Seconds
composer require sbsaga/toon
π Ready-to-Use Tags (Paste into Medium / Dev.to)
laravel, php, ai, prompt-engineering, chatgpt, openai, ai-tooling, laravel-dev
π§ βCompress your prompts, not your ideas.β β TOON helps you talk to AI efficiently.
Top comments (0)