Your LLM bill tripled this quarter. Design a cost-engineering programme - attribution, cascades, context management.
Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.
Model answer: the part to lead with
Step 1: attribution before optimisation. You can't fix what you can't see. Instrument every call with input/output/cached/reasoning token counts × current prices, tagged by feature, tenant, model, and prompt version; dashboard cost per request / per feature / per active user, plus anomaly alerts on burn rate. Nine times out of ten the trebling has a specific cause: an agent loop re-sending un-cached 20K-token contexts every step, a runaway retry path, reasoning-token creep after a model upgrade, or one enthusiastic B2B tenant. Find it before redesigning anything.
Full worked answer
Step 1: attribution before optimisation. You can't fix what you can't see. Instrument every call with input/output/cached/reasoning token counts × current prices, tagged by feature, tenant, model, and prompt version; dashboard cost per request / per feature / per active user, plus anomaly alerts on burn rate. Nine times out of ten the trebling has a specific cause: an agent loop re-sending un-cached 20K-token contexts every step, a runaway retry path, reasoning-token creep after a model upgrade, or one enthusiastic B2B tenant. Find it before redesigning anything.
Step 2: the mechanical levers, in typical ROI order.
- Prompt caching: restructure prompts to stable-prefix-first; on Anthropic-style pricing cached reads are ~10% of input price. For agent/chat traffic this alone often cuts input spend 50%+.
- Batch API for everything offline: ~50% off with a 24 h window.
- Output discipline:
max_tokenscaps, terse formats, no input-echoing, tuned reasoning effort. Output is typically ~4-8× input-priced, so output tokens are where trimming pays most. - Context management: sliding-window + summarization for history, fewer/better RAG chunks (retrieval precision is a cost feature), prune verbose tool results in agent loops. Watch for the quadratic-ish pattern: context that grows per turn while being re-billed every turn.
Step 3: model tiering/cascades. Route by predicted difficulty: a cheap router (heuristics, small classifier, or logprob-based confidence) sends easy traffic to a small model and escalates hard cases - FrugalGPT-style cascade: try cheap, verify (validators, self-consistency, judge), escalate on failure. Right-size per feature via evals; many features run fine on models 10-30× cheaper than the default-to-frontier choice. Guard rails: eval-gate every routing change, monitor escalation rate (a cascade that escalates 60% of traffic costs more than direct-to-big).
Step 4: make it stay fixed. Cost-per-feature in weekly review, budget alerts per tenant, regression tests on token counts in CI (a prompt edit that doubles tokens should fail a check), and re-price quarterly as models/prices shift.
What a good answer covers
- Step 1: attribution before optimisation
- Instrument every call with input/output/cached/reasoning token counts × current prices, tagged by…
- Nine times out of ten the trebling has a specific cause
- Find it before redesigning anything
- Step 2: the mechanical levers, in typical ROI order
Key terms: Step 1: attribution before optimisation · Prompt caching · Batch API · Output discipline · Context management · Step 3: model tiering/cascades
In the glossary: Prompt caching · Batch API · RAG · Router · Self-consistency · Regression test
Interviewer follow-ups to expect
How do you build a difficulty router without labelled data?
A model upgrade improved quality but doubled reasoning tokens - how do you decide?
Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep