Intermediate level · Module 4: Building Applications with LLM APIs · Lesson 3 of 3
Estimating and Controlling Cost
Learners estimate cost per request and per month from token counts and prices, compare model options and apply simple savings.
In this lesson you will
- Estimate application costs
- Reduce costs without losing quality
Key concepts
cost per requestinput vs output tokensmonthly estimateprompt trimmingsmaller or local models
The lesson
Cost per request ≈ (input tokens × input price + output tokens × output price). Multiply by expected requests for a monthly estimate. Providers often price output tokens higher than input tokens, and prices change, so check current rates.
Savings come from sending less context (fewer or shorter passages), shorter answers, caching repeated questions, and using smaller hosted or local models for simple tasks.
Local models have no per-token charge but need hardware and electricity, and may give lower quality; include these in comparisons.
Step by step
- Measure average input and output tokens for 20 project questions.
- Estimate the monthly cost for 1,000 questions per month with three model options.
- Apply prompt trimming and re-estimate.
- Write a cost recommendation.
Estimating the cost of 1,000 assistant requests
How token counts and per-token prices turn into running costs, and how trimming the prompt or changing model changes them.
| Option | Input tokens per request | Output tokens per request | Input price ($/M) | Output price ($/M) | Cost per 1,000 requests ($) |
|---|---|---|---|---|---|
| Large hosted model | 800 | 300 | 2.5 | 10 | 5 |
| Large hosted, prompt trimmed | 400 | 300 | 2.5 | 10 | 4 |
| Small hosted model | 800 | 300 | 0.15 | 0.6 | 0.3 |
| Local open model | 800 | 300 | 0 | 0 | 0 |
What the data shows
For the large hosted model, output tokens cost more than input tokens: 300 output tokens cost $3.00 per 1,000 requests, while 800 input tokens cost $2.00.
Trimming the prompt from 800 to 400 input tokens (fewer or shorter retrieved passages) saves $1.00 per 1,000 requests (20%), if answer quality holds.
The small hosted model costs about 6% of the large one ($0.30 against $5.00) and is worth testing for simple questions. The local model has no per-token charge, but needs a capable computer, electricity and maintenance, and its quality must be measured.
Recommendation
Measure real token counts on your own questions, compare two or three options on quality, and route simple requests to the cheapest option that meets the quality bar.
Practice activity
Write a cost estimate and recommendation for the project assistant.
Expected result: A clear estimate with options and a justified recommendation.
Check your understanding
-
How do you estimate the cost of one request?
Show answer
Input tokens × input price + output tokens × output price.
-
Name two ways to reduce LLM costs.
Show answer
For example send less context, shorten answers, cache, or use smaller or local models.
Further learning
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.