Command Palette

Search for a command to run...

Hectal
Phase 13: Choosing and Adapting Models
LLM Engineering · Exercise 4 of 6 PreviousNext
Advanced

Break-even against a hosted API

Write break_even(fixed_per_month, in_tokens, out_tokens, price_in, price_out) where prices are dollars per million tokens. It returns the smallest whole number of requests per month at which the hosted cost reaches fixed_per_month (use math.ceil).

If a request costs nothing on the hosted side (the per-request price is 0 or less), return None, because there is no break-even.

What Check tests

  1. The lesson's numbers give 6,314,286 requests
  2. Doubling the prices halves the break-even
  3. A free hosted request has no break-even
  4. The result is a whole number

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.