Skip to main content
🔒 Preview mode. The first 15 Foundations lessons are free; this one is Pro. Start a 7-day trial to unlock the editor, AI hints and the rest of the curriculum. Card required, cancel any time in Dashboard.Start 7-day trial →
← CoursesAI Engineering with PythonModule 6 · Frontier AI EngineeringToken counting + cost optimization checklistwrite100 / 105
+130 XP
Task
📝 **Task:** Implement `estimate(input_fresh, input_cached, output, price_in, price_out, batch=False) -> float`. Rules: * Fresh input tokens cost `price_in` per 1M. * Cached input tokens cost `0.1 * price_in` per 1M (10%). * Output tokens cost `price_out` per 1M. * If `batch=True`, multiply the whole thing by `0.5`. * Round result to 4 decimals. The driver exercises four scenarios: canonical sync, same batched, all-fresh (no cache benefit), and zero-output (input-only cost). Expected output: ``` sync=0.0132 batch=0.0066 no_cache=0.0375 no_output=0.0057 ``` 📋 Implement the function above. Tests run automatically. 💡 **Hint:** Re-read the theory if stuck.
✏️ Write your code here
🐍
Loading Python...
One-time download (~1 MB). Then it runs instantly.
📊 Result
Press Run to see result...

💬 Discussion

Be the first to ask a question or share a tip.
Sign in to join the discussion. Reading is free.
Loading discussion…