Lesson 1.3 · 7 min read · about 50 min to master at a very slow pace
Tokens, Cost and Latency
How LLM APIs are priced per input and output token, how to estimate the monthly bill for a client before you build, and what actually makes a response slow.
How you pay
APIs charge per million tokens, with output tokens priced higher than input tokens (often 4 to 5 times higher). The cost of one call is:
where and are the prices per million tokens. Prices change often and differ by model size by a factor of 10 or more, so always check the current price list. The numbers below are illustrative.
Worked example: a support assistant
Each question sends a 1,500-token system prompt plus 3,000 tokens of retrieved documents plus a 100-token question: . The answer is tokens. Prices: €2.50 per million input, €10 per million output.
Per call: €.
At 2,000 questions a day for 30 days: € a month.
Notice where the money goes: input is 80% of the bill here, because RAG sends a lot of context. Trimming retrieved text from 3,000 to 1,500 tokens saves more than shortening answers.
What makes a response slow
- Time to first token (TTFT): the wait before anything appears. Grows with input length and model size.
- Output speed: tokens per second while writing. Output tokens are generated one by one, so a 600-token answer takes roughly twice as long as a 300-token one.
At a TTFT of 0.5 s and 60 tokens per second, a 300-token answer takes about s. Streaming (showing tokens as they arrive) does not make it finish sooner, but the user sees text after 0.5 s instead of 5.5 s, which is what feels fast.
Levers, in order of impact
Use a smaller model where it passes your evals; send less context; ask for shorter outputs; cache repeated prompt prefixes; stream. Section 6 covers each in production.
Stuck? Common doubts
Questions real learners asked while studying this lesson. They stay closed so they don't spoil your own thinking: open only the ones you need.
First passWhy are output tokens more expensive than input tokens?
Input tokens are processed in parallel in one pass. Output tokens are produced one at a time, each needing its own pass through the model, which uses far more GPU time per token. The price difference reflects that.
Going deeperHow do I estimate tokens before I have a tokenizer set up?
Use the rule of thumb (1 token ≈ 4 characters ≈ ¾ word in English) for a first estimate, then measure: every API response reports the exact input and output token counts in its usage field. Log those from day one; they are your real cost data.
Cheatsheet
Cost of a call
Latency
Where RAG money goes
Check your understanding
Score 75% or more to master this lesson and earn XP. Answer first, then check.