Counting and budgeting tokens
Token usage is easiest to control when it is measured per part of the request. A practical breakdown for each AI feature:
- System prompt and tool definitions: fixed per request; long tool lists add up quickly.
- Retrieved context: often the largest input, driven by how many passages are sent and how long each is.
- Conversation history: grows with every turn unless summarized or trimmed.
- User input: usually small, unless users paste documents.
- Output and reasoning: controlled by maximum output settings, instructions about length and the reasoning effort chosen.
Measure these with the provider's token counting endpoint or the model's tokenizer library, such as tiktoken for OpenAI models, and log actual usage returned in every response.
Example: trimming an assistant's token use
Example: a support assistant's traces show that a typical request sends a long system prompt, twenty retrieved passages and the full conversation history. The team makes four changes: it moves rarely used instructions into a tool the model can call when needed, adds reranking and sends the best five passages instead of twenty, summarizes conversation turns older than the last few, and enables prompt caching for the stable prefix. Each change is evaluated on the same test set to confirm answer quality holds. Input tokens per request fall substantially, latency improves and quality scores stay level. The team adds a dashboard showing tokens per resolved conversation, not just per request.
Tokens and Indian languages
Tokenizers are built from training text, and many were built from English-heavy data. As a result, Hindi in Devanagari and other Indian scripts can need several times more tokens than English for the same meaning on some models, while newer tokenizers have narrowed the gap. Romanized Hindi behaves differently again. For Indian-language products:
- Count tokens for real sample messages in each language on each candidate model.
- Factor the difference into context limits, latency and running cost estimates.
- Consider whether replies can be shorter, and whether retrieved passages can stay in English while answers are in Hindi.
Measuring token efficiency
| Measure | Why |
|---|
| Input and output tokens per request, by feature | Shows where usage comes from |
| Tokens per completed task | Agents may take many calls per task; per-call numbers hide that |
| Cached input share | Confirms caching works |
| Output tokens at high percentiles | Finds runaway responses |
Our agent running cost tool turns token estimates into a running cost picture for an agent.
Set alerts on token usage as well as reports. A sudden rise in tokens per request often signals a bug, such as a loop in an agent, a retrieval step returning whole documents, or a prompt template duplicating history, and catching it within hours avoids a surprise at month end.
Typical problems are estimating tokens from word counts, ignoring tool definitions and reasoning tokens, unbounded conversation history, and no maximum output setting. Tokens define the context window, drive AI latency, are shaped by temperature at generation time, and are the target of model routing and caching. Gepton reduces token spend in AI cost optimization.