Call records to metrics
Twenty scripted records. Percentiles use the nearest-rank rule. Prices are example numbers: check your provider.
Metrics turn thousands of call records into a few numbers you can watch and alert on: latency percentiles, time to first token, tokens, cost, error and retry rates and cache hit rate.
Change the code and press Run (Ctrl+Enter). Predict what will happen first, then break it on purpose and read what changes. Your edits are saved and match the lesson page.
Ready for more? This phase has 5 hands-on exercises with automatic checks.
Practice questions
Write the code in the editor, run it, then open the model answer to compare.
Write percentile(values, p) with the nearest-rank rule for 1 <= p <= 100 and print p50, p90 and p100 of [7, 3, 9, 1, 5, 8, 2, 6, 4, 10].
Write cache_hit_rate(records) where each record is "hit" or "miss"; return the percentage with one decimal as a string such as "33.3%", and "n/a" for an empty list.
Explain it without notes
Why are percentiles better than the mean for latency, and what does p95 mean?
What is the difference between time to first token and total time, and when does each matter?
Which metrics would you put on a dashboard for an LLM feature, and why?
Expected output
calls: 20, errors: 2 (10.0%)
latency mean 2325 ms, p50 650 ms, p95 3100 ms
time to first token p50 160 ms, p95 900 ms
tokens in 19016, out 2540, cost 0.013318 dollars
cache hit rate: 30.0%