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.

Not startedJump to quiz

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

, prices per million tokens.

Latency

Latency ≈ TTFT + output tokens ÷ tokens per second. Streaming cuts perceived wait, not total time.

Where RAG money goes

In RAG most of the bill is input tokens (context). Trim retrieved text before shortening answers.

See every cheatsheet by category →

Check your understanding

Score 75% or more to master this lesson and earn XP. Answer first, then check.

Q1calculateA call uses 2,000 input tokens and 500 output tokens. Prices are €1 per million input and €4 per million output. What does it cost?
Q2calculateEach RAG answer costs €0.01 and the client expects 1,500 questions a day. Roughly what is the monthly (30-day) model cost?
Q3calculateTTFT is 0.4 s and the model writes 50 tokens per second. About how long does a 400-token answer take to finish?
Q4interpretYou add streaming to a chatbot. What changes for the user?
Q5applyA RAG app sends 6,000 tokens of context and gets 250-token answers; output costs 4× input per token. Which change cuts the bill most?