AI Engineer Portal
Your personal operating system for career transition.
Exercise
Track and alert on LLM cost per feature
Track and Alert on LLM Cost Per Feature
Without cost visibility, you will discover that your most popular feature is generating $30,000/month in LLM costs via the monthly billing invoice — after the fact. The solution is instrumented cost tracking that captures cost at request time, grouped by feature.
What to build
Implement a CostLedger that:
record(event: CostEvent) -> None— record a cost event withfeature,model,input_tokens,output_tokens,user_id.daily_report(date_str: str | None = None) -> DailyReport— costs grouped by feature for today. Include total cost, per-feature breakdown, and top 3 costliest requests.check_alerts(budgets: dict[str, float]) -> list[BudgetAlert]— check if any feature has exceeded its daily budget.hourly_burn_rate(feature: str) -> float— average cost per hour over the last 24 hours for a feature.
Use these rates per 1000 tokens (input/output):
gpt-4o-mini: $0.00015 / $0.0006gpt-4o: $0.0025 / $0.01claude-3-5-haiku-20241022: $0.0008 / $0.004
Constraints
- Standard library only.
- Use
datetimefor timestamps. - Events stored in-memory.
Evaluation / medium / Step 16 of 36
Evaluation and review loops
Separate the scoring logic from the interpretation logic. Your goal is not just a number; it is a useful next action.
- - Produces a useful signal, not decorative output
- - Makes regression review easier
- - Would support a benchmark or observability loop
- - Would this output help decide what to fix next?
- - Are important failure modes visible?
- - Does the score hide any ambiguity I should record?
Practice
Generate a variation
Generate a new exercise variation to deepen understanding or practice a related concept.
Attempt history
Recent submissions
Before you submit, decide what a strong answer should make obvious to the reviewer.
No attempts yet.