0% completed
How Can I Reduce My Token Usage?
On This Page
Step 1: Measure Where the Tokens Go
Step 2: Send Only the Input That the Question Needs
Step 3: Cache the Part That Repeats
Step 4: Limit and Shape the Output
Step 5: Lower the Price of the Tokens That Remain
Step 6: Stop Before Quality Drops
Common Wrong Beliefs
What This Means for Your Work
Try It Yourself
Check Your Understanding
Key Takeaways
Short answer: First measure which parts of a request use the tokens. In most applications the largest part is input that is sent again with every request: instructions, chat history, and documents. Send less of that input, cache the part that repeats, and limit the length of the output. Do not remove text that the model needs, because a wrong answer usually costs more than the saved tokens.
Look at the widest part of the bar. The instructions written by the developer (the system prompt) are 1,500 of the 1,750 tokens. The application sends the same 1,500 tokens with every question.
Harbor Bikes is an online bike store, and its engineering team is building a support assistant on an LLM. The assistant receives 20,000 customer questions a day. Every amount of money in this lesson uses illustrative prices, which are invented for the example and are not the price list of any provider. For a large model, they are 3 per million input tokens and 15 per million output tokens.
A model counts text in small pieces called tokens, and What Is a Token and Why Do Models Not Read Words? explains them.
Step 1: Measure Where the Tokens Go
A request has more parts than the message that a user typed. The table lists the parts and the current numbers of the assistant. The assistant treats every question as a new chat and adds no documents, so two parts are empty.
| Part | What it holds | Harbor Bikes today |
|---|---|---|
| <span style="white-space:nowrap">System prompt</span> | The developer's instructions, sent with every request | 1,500 tokens |
| <span style="white-space:nowrap">Chat history</span> | The earlier messages of the same chat, sent again each time | 0 tokens |
| <span style="white-space:nowrap">Documents and tool results</span> | Text that the application adds, and the descriptions of its tools | 0 tokens |
| <span style="white-space:nowrap">New message</span> | The customer's question | 50 tokens |
| <span style="white-space:nowrap">Output</span> | The answer, and the private working text that some models write before it (thinking tokens) | 200 tokens |
The API response reports the input tokens and the output tokens that the request used (the usage numbers). Many providers also show totals on a dashboard. Read these numbers first, because the largest part is often not the one that a team expects.
For Harbor Bikes, one request has 1,550 input tokens and 200 output tokens. One day has 20,000 x 1,550 = 31,000,000 input tokens, which cost 93.00, and 20,000 x 200 = 4,000,000 output tokens, which cost 60.00. The total is $153.00 a day at the illustrative prices.
The measurement shows two facts. The system prompt is 20,000 x 1,500 = 30,000,000 of the 31,000,000 daily input tokens. The output is only 4,000,000 of the 35,000,000 daily tokens, but it is 60.00 of the 153.00. Why Do Output Tokens Cost More Than Input Tokens? explains why output has the higher price.
Step 2: Send Only the Input That the Question Needs
The largest savings usually come from text that the application adds to every request:
- Documents. The team wants the assistant to answer from the help center, which has 400 articles and about 500,000 tokens. Sending the whole help center with every question costs 1.50 per request at the illustrative prices, which is 30,000 a day. An average article has about 1,250 tokens, so sending only the three articles that relate to the question adds 3,750 tokens. That is about 0.01 per request and 225 a day. What Is RAG and When Do I Need It? describes how an application finds those articles.
- Chat history. In a chat with several questions, the application sends the earlier messages again each time. One question and its answer are 50 + 200 = 250 tokens. At the fourth question, the three earlier questions and answers add 3 x 250 = 750 tokens. The application can keep only the most recent messages, or it can replace the older ones with a short summary.
- Tool descriptions. The description of every tool that the model may call is also input in every request. Remove the tools that a task never uses.
Step 3: Cache the Part That Repeats
The team cannot remove the system prompt, but it is the same text in every request. Many providers can store the result of processing a beginning that repeats. They then charge a small part of the normal price for those tokens. This feature is called prompt caching.
At an illustrative cached price of 0.30 per million tokens, the 30,000,000 system prompt tokens cost 9.00, and the other 1,000,000 input tokens cost 3.00. The input cost decreases from 93.00 to 12.00, and the daily total decreases from 153.00 to $72.00. This arithmetic ignores the first request after the stored copy expires and any extra charge for storing it.
Notice that the blue part is much smaller in the second row, although the application still sends the same 31,000,000 input tokens. Caching does not reduce the number of tokens. It only lowers the price of the repeated ones. What Is Prompt Caching and How Does It Lower My Bill? explains the rules of prompt caching.
Step 4: Limit and Shape the Output
After caching, the output is 60.00 of the 72.00, so it is now the largest part of the cost. Three changes reduce it:
- State the length in the system prompt, for example "Answer in at most three sentences."
- Ask for only the part that changed, such as the corrected lines and not the whole file.
- Set a maximum number of output tokens in the request as a safety limit. This limit cuts an answer that reaches it, and the answer then ends in the middle, so the limit does not replace the instruction.
If the average answer decreases from 200 tokens to 150, the daily output is 3,000,000 tokens and costs 45.00. Together with the cached input of 12.00, the total is $57.00 a day. Providers charge for thinking tokens as output, so a simple question should not run with a high thinking setting.
Step 5: Lower the Price of the Tokens That Remain
A smaller model usually costs several times less per token. The illustrative prices for a small model are 0.60 per million input tokens and 3 per million output tokens. At these prices, the same day costs $30.60 without caching. The saving is real only when the answers of the smaller model pass your checks. Teams therefore usually move the simple steps to the smaller model first. How Do I Choose Between a Small Model and a Large Model? describes how to decide.
Some providers also offer a batch interface. It accepts a large group of requests, returns the answers later, usually within a day, and charges a lower price. A customer who is waiting for an answer cannot use this interface. A program that runs every night and labels the 20,000 questions of the day can use it.
Notice that the first three methods all act on repeated input. The order is typical and not fixed, and your own usage numbers show which method comes first in your application.
Step 6: Stop Before Quality Drops
Every method above keeps the text that the model needs. One more reduction seems useful but causes harm: removing instructions and facts until the answers get worse.
The Harbor Bikes system prompt states that the return period is 30 days and that standard shipping takes 5 business days. If those two lines are about 30 tokens long, removing them saves 600,000 tokens a day, which is $1.80 at the illustrative price. The assistant then has no source for those facts, and it produces a likely guess.
A safe routine is to change one thing, run the same set of test questions each time, and compare both the answers and the usage numbers. Keep the change only if the answers are still correct.
Common Wrong Beliefs
| Belief | What actually happens |
|---|---|
| My messages are short, so my token usage is low. | The application adds the system prompt, the chat history, and documents to every request. The Harbor Bikes customer typed 50 of the 1,750 tokens. |
| Caching reduces the number of tokens that I send. | The application sends the same tokens. The provider charges a lower price for the repeated ones. |
| Output is a small share of the tokens, so its length does not matter. | For Harbor Bikes, the output is 4,000,000 of the 35,000,000 daily tokens but 60.00 of the 153.00. |
What This Means for Your Work
- Record the usage numbers of every request. Store the input tokens, the output tokens, and the cached tokens with each log entry.
- Reduce the repeated input first. Text that is sent with every request is multiplied by the number of requests. One document that is not needed costs more than many long questions.
- Ask for the shortest output that the task needs. State the length and the format in the instructions, and request only the changed part of a long text.
- Test the answers after every reduction. A lower bill with wrong answers is not a saving.
Try It Yourself
The program below calculates the tokens and the cost of one day of the Harbor Bikes assistant from the parts of one request. The prices are illustrative. Run it and find the line that starts with "Total per day".
The first run prints a total of 153.00 a day, and it shows that the system prompt is 96.8% of the input. Now change `DOCUMENT_TOKENS` from 0 to `3750`, which adds three help articles to every request, and run the program again. The total increases to 378.00 a day, and the documents are now 70.8% of the input.
Check Your Understanding
An internal tool sends a style guide (a document of writing rules) of 6,000 tokens with every request. The users' questions average 100 tokens, the answers average 150 tokens, and the tool handles 5,000 requests a day. The team wants a lower bill. Which part should the team check first?
Key Takeaways
- Measure before you reduce. The usage numbers in the API response show which part of a request holds the most tokens.
- Repeated input is usually the largest part. Send only the documents and the history that a question needs, and cache the beginning that stays the same.
- Output tokens are few and expensive. Ask for short answers and for only the part that changed.
- Every reduction must keep the quality of the answers. Keep the text that the model needs, and test the answers after each change.
The next lesson, What Is a Context Window and What Happens When It Is Full?, explains the limit on the number of tokens in one request.
Reading Progress
0%
On This Page
Step 1: Measure Where the Tokens Go
Step 2: Send Only the Input That the Question Needs
Step 3: Cache the Part That Repeats
Step 4: Limit and Shape the Output
Step 5: Lower the Price of the Tokens That Remain
Step 6: Stop Before Quality Drops
Common Wrong Beliefs
What This Means for Your Work
Try It Yourself
Check Your Understanding
Key Takeaways