Reducing Cost with Token Efficiency
This lesson covers estimating and tracking tokens and the techniques that cut input and output tokens without reducing effectiveness, since tokens drive most foundation model costs.
Learning outcomes
After completing this lesson, you will be able to:
- Estimate and track token usage.
- Optimize input tokens with fewer, better context chunks.
- Optimize output tokens with limits and concise formats.
Estimating and tracking tokens
A token is a piece of a word; in English, one token is roughly four characters or three quarters of a word, but ratios vary by model and language. Applications estimate tokens before a call (with a token counting API where the model supports it, a tokeniser, or a character-based approximation) to enforce budgets, and track actual usage from the usage field in each response (input, output and cache tokens).
Usage is aggregated by application, feature, tenant and user. InputTokenCount and OutputTokenCount metrics in the AWS/Bedrock namespace show totals by model. Application inference profiles with cost allocation tags attribute Bedrock spend to applications in AWS Cost Explorer, and AWS Cost Anomaly Detection alerts on unexpected spend.
Estimating tokens and cost
Optimizing input tokens
Context window optimisation sends only what the model needs. Retrieve fewer, better chunks by reranking and keeping the top results; trim chunks to relevant sections. Context pruning removes old or irrelevant conversation turns, replacing them with a running summary. Prompt compression removes redundant instructions, verbose boilerplate and excess few-shot examples, and replaces long examples with short ones, measuring quality after each cut. Structured data is sent as compact JSON or tables rather than prose. Repeated long prefixes are handled with prompt caching, covered later in this module.
The following diagram compares what each turn of a costly RAG assistant sends before and after changes that cut its tokens.

Trimming input tokens
Optimizing output tokens
Output tokens are usually priced several times higher than input tokens, and because they are generated one at a time, every extra output token also adds latency. Reducing output length therefore lowers both cost and response time. Response size controls set maxTokens for each use case and instruct the model to be concise, for example "Answer in at most three sentences".
The form of the output matters as much as its length. Asking for structured output, such as a label or a few JSON fields, instead of an explanation can reduce a response from hundreds of tokens to a handful. Stop sequences end generation as soon as the required content is complete. And step-by-step reasoning, which can multiply output length, should be requested only where evaluation shows that it improves results. The following table summarises the techniques.
| Technique | Reduces | Watch for |
|---|---|---|
| Fewer, reranked chunks | Input tokens | Recall loss; measure retrieval quality |
| History pruning and summaries | Input tokens in long chats | Losing important early facts |
| Prompt compression | Input tokens on every call | Quality regressions; re-evaluate |
| maxTokens and concise instructions | Output tokens and latency | Truncated answers |
| Structured output instead of prose | Output tokens | Fit to downstream needs |
| Application inference profiles | Nothing directly; attributes cost | Tagging discipline |
Output tokens
A costly RAG assistant
A RAG assistant sends 20 retrieved chunks, the full chat history and a 1,500-token system prompt with eight examples on every turn, and answers average 600 tokens. Costs are three times the budget.
Reranking and keeping 5 chunks, summarising history beyond the last 6 turns, trimming the examples to two, caching the static system prompt, and setting maxTokens to 300 with a conciseness instruction cut tokens substantially; an evaluation run confirms quality is unchanged.
Why limit maxTokens and ask for concise answers?
Show answer
Output tokens cost more than input tokens and also increase latency.
Exam Tips
Remember for the exam
- Track tokens per application with usage data, metrics and application inference profiles.
- Send fewer, reranked chunks and pruned history.
- Output tokens cost more: limit maxTokens and ask for concise answers.
- Re-evaluate quality after every token reduction.