Token count
A token count is a measure of the number of tokens present in text or processed or generated during a model or corpus operation.
Build AI-Enhanced Web Apps
Token usage is the quantity of input and output tokens consumed by a language-model interaction.
- How it is used
- Tracks model-call usage for cost management and conversation-history size for token-limit management.
- How deep it goes
- Shows callback-based usage tracking and describes history counting, while leaving unsupported models to custom solutions.
- Examples
- Uses a TokenTracker callback for a Gemini model and conversation-history monitoring with js-tiktoken.
- What you can do after
- Apply it via LangChain.js callbacks and js-tiktoken to monitor call usage and conversation history.
Designing AI Systems
Token usage is the quantity of language-model input and output tokens consumed by an AI operation.
- How it is used
- Supports per-request cost attribution and aggregated spending analysis across AI workflows.
- How deep it goes
- Defines prompt, completion, total, and cache-related metrics and specifies request-level recording and aggregation.
- Examples
- Shows a chat response with 847 prompt tokens and 156 completion tokens and a request-metrics dataclass.
- What you can do after
- Diagnose spending drivers and prompt bloat using token metrics grouped by workflow, model, user, and time.
Spring AI in Action
Token usage is the measured quantity of input and output tokens consumed during a language-model interaction.
- How it is used
- Tracks language-model consumption to estimate billing, control prompt costs, and observe Spring AI operations.
- How deep it goes
- Explains input, output, and total counts, metric tags, Java logging, and Actuator queries, but not tokenization internals.
- Examples
- Demonstrates board-game prompts, ChatResponse logging, and filtered Actuator measurements for input, output, total, model, and operation.
- What you can do after
- Diagnose token spending by logging ChatResponse metadata and querying gen_ai.client.token.usage with filtering tags.
Machine Learning Platform Engineering
Token usage is the quantity of language-model input and output tokens consumed during an interaction or application operation.
- How it is used
- Monitors LLM resource consumption for efficiency, observability, performance analysis, and operational cost control.
- How deep it goes
- Explains input/output ratios, reasoning-step allocation, prompt reduction, tracing, alerts, and budgets without specifying tokenizer internals.
- Examples
- Uses verbose and concise prompts, Langfuse traces, RAG pipelines, token ratios, cost dashboards, alerts, and budget thresholds.
- What you can do after
- Diagnose/debug with Langfuse by tracing token usage, locating expensive operations, and validating prompt reductions against quality and safety.
Read how Machine Learning Platform Engineering explains token count →
Vibe Engineering
Token consumption is the quantity of language-model input and output tokens used by an AI system or user over a defined period.
- How it is used
- Uses token consumption to monitor AI-agent pipelines, surface anomalous spend, and investigate bottlenecks.
- How deep it goes
- Explains metric misuse, rebound effects, cost arithmetic, and dashboard monitoring without descending into model internals.
- Examples
- Uses token leaderboards, cost comparisons, interaction growth, and an agent-pipeline dashboard as concrete examples.
- What you can do after
- Diagnose/debug with it by correlating token spikes, agent failures, queue delays, costs, and remaining work.
How Large Language Models Work
The quantity of tokens consumed as input to or produced as output by a language model.
- How it is used
- Tracks model input and output to explain cost, latency, capacity, and language representation.
- How deep it goes
- Explains BPE-driven counting with a worked comparison, but stops short of formal tokenizer algorithms.
- Examples
- Uses GPT-3 tokenizations of “I’m running” and “I’m runnin,” plus cross-language cost comparisons.
- What you can do after
- Evaluate tokenization-related cost, latency, language disparities, and software differences before deploying or upgrading systems.
Read how How Large Language Models Work explains token count →
Also covered in
- Essential GraphRAG
- Build an AI Agent (From Scratch)
- LLMs in Production
- AI Agents in Action, Second Edition
- Natural Language Processing in Action, Second Edition
What to know first
- language modelA language model is a computational model that represents patterns in linguistic sequences to assign probabilities, predict, generate, or evaluate language.
- context windowA context window is a bounded span of sequence elements or contextual information that a model or processing operation can consider together.
- tokenA token is a discrete unit of text, such as a word, subword, punctuation mark, or symbol, produced by tokenization and processed by a language model.
- promptA prompt is text or other input supplied to an AI model to provide instructions, context, or other information that guides its response or generated output.
Related concepts
- tiktokenmeasured by · tiktoken is an OpenAI-developed library that efficiently encodes text using model-specific byte-pair-encoding tokenizers and supports token counting.
- frequency analysisused by · Frequency analysis examines how often symbols, values, events, or linguistic units occur in data, text, or signals.
- prompt engineeringused by · Prompt engineering is the deliberate design and refinement of inputs, instructions, and context to guide an AI model’s behavior or outputs.
- tokenmaxxingused by · Tokenmaxxing is the practice of maximizing AI token consumption and treating consumption volume as evidence of productivity.
- text chunkused by · A text chunk is a bounded segment of a larger text treated as a unit for processing, storage, or retrieval.
Questions about token count
What is token count?
A token count is a measure of the number of tokens present in text or processed or generated during a model or corpus operation.
Which Manning books explain token count?
Build AI-Enhanced Web Apps, Designing AI Systems, Spring AI in Action, Machine Learning Platform Engineering, Vibe Engineering and How Large Language Models Work.
What should I know before learning token count?
Manning books that teach token count usually introduce language model, context window, token and prompt first.
What is token count also called?
Token count is also called token usage or token consumption.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.





