Lab 11 — Unit-Economics Cost Calculator
Runs fully offline (Python 3 only). Model the cost ladder and prove (or fix) your margin — the business-side skill every senior engineer/CTO needs. Concepts: Phase 15.05, cheatsheet 18.
Goal
Compute cost per request → task → resolved task → user → gross margin, and quantify the impact of routing + caching levers.
Files
lab-11-cost-calculator/
README.md
cost_calc.py ← runnable: cost ladder + margin + routing/caching levers
Run
python3 cost_calc.py
# a chatty agent with retries on an expensive model
python3 cost_calc.py --in-tok 6000 --out-tok 1500 --in-price 3 --out-price 15 \
--requests-per-task 4 --success-rate 0.6 --tasks-per-user 300 --price-per-user 99
Exercises
- Negative margin: find inputs (expensive model, low success rate, high usage) that produce a negative gross margin. Then fix it with the levers.
- Resolved-task cost: show how a low success rate inflates cost per resolved task vs cost per request.
- Levers: quantify the margin improvement from 80% routing to a 0.1× model + 50% cache hit.
- Break-even (stretch): add a self-host model (fixed GPU $/month + ~0 marginal) and find the monthly volume where it beats the API.
- Pricing: given a target 75% margin, solve for the minimum price per user.
Deliverables
- A cost ladder for your product idea (real token counts + prices).
- A before/after-levers margin comparison.
- A pricing recommendation (to-margin) + a usage cap to prevent power-user blowout.
Why it matters (interview)
"Every request costs money — here's my cost per resolved task and how I engineer 75% margin with routing/caching" is exactly what platform/CTO interviews probe (interview-prep 09). Pairs with the cost-model template.