Understanding AI App Costs
Read a little, play a little. No scary maths, and no rush.
The bill arrives per token
LLM pricing looks tiny — "$0.15 per million input tokens" — until you multiply by real traffic. Every query pays for input tokens (your prompt + retrieved context) at one rate and output tokens (the answer) at a higher one. A 2,000-token prompt with a 500-token answer at $0.15/$0.60 per million costs about $0.0006 per query — which is $600 per million queries. Side projects don't notice; products with users very much do.
The four levers that actually move the bill
- Cache aggressively. Repeated questions ("what are your hours?") should never reach the model twice. Exact-match cache first, semantic cache (similar past question → reuse answer) second. Caching alone routinely cuts 50–80%.
- Shrink the context. Top-K of 3 instead of 10, tighter chunks, no "helpful" extra documents. Every token you don't send is money kept.
- Right-size the model. A small model triages ("is this a refund question?"), the big model handles only the hard cases. Routing is architecture, not compromise.
- Cap the output.
max_tokenslimits runaway answers — a model asked to "explain thoroughly" will happily spend your budget doing so.
The math to do before shipping
Estimate per-query cost × expected queries, then add the retrieval side (embeddings are cheap but not free, vector DB hosting isn't either). If unit economics fail at 10× your current traffic, fix the pipeline before the launch post — success should not bankrupt you.
A worked budget: a support assistant
Expected traffic: 200,000 questions a month. A typical request carries 2,500 input tokens (system prompt, retrieved chunks, question) and returns 400 output tokens.
Using the example rates above ($0.15 input, $0.60 output per million tokens):
- Input: 2,500 × $0.15 ÷ 1,000,000 ≈ $0.000375
- Output: 400 × $0.60 ÷ 1,000,000 = $0.00024
- Per question: about $0.0006, so roughly $123 a month.
Swap in a model priced 20 times higher and the same traffic costs about $2,460 a month. If a cache answers 40% of questions without calling the model, either figure drops by about 40%. Ten minutes with these numbers shows which lever matters for your product before any money is spent.
Costs people forget
- Retries and failures. Failed and retried calls are usually billed too.
- Hidden reasoning. Reasoning models produce internal thinking tokens that are billed as output, even though you never see them.
- Conversation history. A chat resends earlier turns on every request, so long conversations get steadily more expensive per message.
- Everything around the model. Eval runs, re-embedding documents after changes, and vector database hosting all appear on the bill.
Track cost per feature
Tag every model call with the feature that made it, such as "chat", "summaries", or "search", and chart spend per feature per day. When the bill jumps, you will know which feature caused it within minutes rather than after a week of guessing. Set an alert for sudden spikes, which usually mean a loop or a bug rather than real growth.
Remember this
- Cost = (in × pin + out × pout) / 1M. Output costs more; cache everything repeatable.
- Small-model triage + tight context + caps = the standard cost playbook.
Check your understanding
5 questions · first-try answers earn the most XP
My notes
Saved in this browser. Highlight a line above and save it, or write it in your own words.
Nothing saved yet. Your highlights will live here.
References
Finished reading?
Ticking it here also ticks the chapter in the sidebar, the section count and your streak — it is all one number.
Practice this in an incident
Related chapters
Spotted a mistake or want a topic covered? Report an issue