Cost Optimization interview question

MLOps & ProductionCost OptimizationLLM System Designmedium

Estimate the monthly LLM bill for this RAG chatbot workload. Every user turn is a separate API call that re-sends the full prompt.

Workload itemValue
Conversations per day50,000
User turns per conversation6
Input tokens per turn1,500 system prompt + 1,000 history (avg) + 2,000 retrieved context + 100 user message
Output tokens per turn250
Price (illustrative)$0.50 per 1M input tokens, $1.50 per 1M output tokens
Month30 days
  1. AAbout $4,000 a month: 50,000 calls a day × 4,600 input tokens ≈ $115 plus ≈ $19 of output per day, since a conversation's context is sent once and then reused on later turns.
  2. BAbout $24,000 a month: 300,000 calls a day × 4,600 input tokens ≈ $690 plus ≈ $113 of output per day; input dominates because the whole context is re-sent on each new turn.
  3. CAbout $63,000 a month: 300,000 calls a day × 4,600 input tokens ≈ $2,070 plus ≈ $38 of output per day, because input tokens are billed at the higher of the two listed rates.
  4. DAbout $22,000 a month: 300,000 calls a day × 4,850 tokens ≈ $728 per day, because output tokens are billed at the input rate whenever they are returned in the same API call.
Show the answer and explanation

Correct answer: B, About $24,000 a month: 300,000 calls a day × 4,600 input tokens ≈ $690 plus ≈ $113 of output per day; input dominates because the whole context is re-sent on each new turn.

Explanation Cost Optimization

Work per API call, then scale up:

StepValue
Calls per day50,000 × 6 = 300,000
Input tokens per call1,500 + 1,000 + 2,000 + 100 = 4,600
Input per day300,000 × 4,600 = 1.38B tokens → $690
Output per day300,000 × 250 = 75M tokens → $112.50
Per day$802.50
Per month× 30 ≈ $24,075

Input is about 86% of the bill, even though output tokens cost 3× more per token, because every turn re-sends the system prompt, history and retrieved chunks. That points to the biggest levers:

  • Prefix caching of the 1,500-token system prompt: if cached tokens cost 10% of the normal rate, that alone saves ≈ $200 a day (≈ $6,000 a month, about 25%).
  • Fewer or shorter retrieved chunks via reranking (e.g. top 3 instead of top 8).
  • History summarisation or windowing instead of re-sending every turn verbatim.
  • Routing easy turns to a cheaper model (cascade).

Where the distractors come from: counting one call per conversation instead of per turn (≈ $4,000); swapping the input and output prices (≈ $63,000); billing output at the input rate (≈ $22,000). Chat APIs are stateless: the model does not remember earlier turns unless they are re-sent.

Interview tip: present cost per conversation (here ≈ $0.016) alongside the monthly total, and show the cost breakdown by prompt component; it makes the optimisation discussion concrete.

Practice it as a quiz

Answer this and the other free questions with instant grading, streaks and weak-topic tracking, or unlock all 4,000 questions.

More MLOps & Production questions

  1. What does this symmetric INT8 quantization snippet print, and which statement about using an asymmetric (zero-point) scheme for ReLU outputs is correct?
  2. A telecom team adds a new feature, dropped_calls_7d, produced by a streaming job from network events starting today. To train on 18 months of history, past…
  3. A retailer's progressive-delivery pipeline shifts traffic to a new recommendation-API version in steps of 5% → 25% → 50% → 100%. At each step, automated…
  4. A telecom support bot on a self-hosted vLLM server sends a 3,000-token system prompt plus the growing chat history on every turn. After you enable automatic…
  5. A security review of a retail client's Google Cloud project finds that the Vertex AI training pipeline, a GKE scoring service and a nightly export job all run…