Price the drafting feature's month from requests, tokens and assumed rates, then pick the lever that brings it under a $30,000 budget.
codeeasyExercise · 4 min · 33 of 59
On this page
The drafting feature works, and at the volume it now serves it costs 90% of the revenue it earns. The tokens lesson set out the three lines of a model bill; here the bill is computed by a function, so every figure in the answer is one that ran.
The same feature across all 12,000 seats and every tenant: 200,000 requests a day, about 17 a seat on average, though usage is skewed and one tenant sends a quarter of it. Each prompt is 1,500 input tokens, 1,100 of them a fixed system prompt that is identical on every call, and the model returns 300 output tokens. Assume $3 per million input tokens, $15 per million output tokens and a 30-day month; the vendor also publishes a cached-input rate that you have not looked up. The eval shows 70% of tickets need a short reply, and their drafts run under 150 tokens when the model is told to be brief; a smaller model exists at a tenth of the price, but its golden-set score is not yet known. A wrong draft the agent catches costs about 20 seconds, at an assumed $30 an hour. The monthly budget for the feature is $30,000, half the $60,000 of add-on revenue in pricing an AI feature.
What does the feature cost a month as specified, does it fit, and if not, which lever do you pull first and what does it save? Write the function that prices one slice of traffic, and use it for every figure.
def solve(daily_requests, in_tokens, out_tokens, price_in, price_out):
"""Monthly cost in USD over 30 days; prices are per million tokens.
daily_requests: requests a day in this slice of traffic.
in_tokens, out_tokens: tokens per request, prompt and reply.
price_in, price_out: USD per million input and per million output tokens.
Returns the month rounded to the dollar, rounded once, at the end.
"""
Input: 200,000 × 1,500 = 300M tokens a day × $3/M = $900. Output: 200,000 × 300 = 60M tokens × $15/M = $900. $1,800 a day, $54,000 at 30 days — 1.8× the budget. The function is that sum per request, times requests, times 30, rounded once at the end. It prices one uniform slice, so each lever is two calls added together:
lever 1 solve(140_000, 1500, 150, 3.0, 15.0) -> 28350 short 70%, output capped
solve(60_000, 1500, 300, 3.0, 15.0) -> 16200 the other 30%
44550
lever 2 solve(140_000, 1500, 150, 0.3, 15.0) -> 11340 short 70%, input at a tenth
the other 30%, unchanged 16200
27540
Levers, in order. First, cap output at 150 tokens for the 70% of tickets the eval shows are short: output falls to 140,000 × 150 + 60,000 × 300 = 39M tokens a day, and the bill to $44,550 a month. It is free: a line in the prompt and a cap on the call. Second, route those same short tickets to the smaller model once its golden-set score is known: at a tenth of the input price the bill falls to about $27,500, inside budget. That counts the input line only; the routed output stays at the mid-tier rate as a margin for drafts the router escalates. Third, cache the fixed 1,100-token prefix, 73% of every prompt; the saving depends on the vendor's cached-input rate, so read that page rather than assume it, and confirm the prefix really is identical on every call. The first two levers bring the bill under $30,000; the third is upside and is not counted until the rate is read.
What would change the answer: a smaller model that loses more than about 2 points on the short slice. Each point is 1,400 wrong drafts a day at 20 seconds, about $7,000 a month, so 2.4 points cancels the $17,000 routing saves.
"Switch to the cheapest model." Without the eval this is a guess with a bill attached: a model 20 points worse on the short slice costs about 20 × $7,000 = $140,000 a month in agent time to save $17,000, and the answer never computed the bill it was fixing.
"Cache the prefix at a tenth of the input price and the bill is fine." The arithmetic looks complete and rests on a rate nobody has read. The cached rate is the vendor's to publish; until it is read, lever 3 is upside, not a line in the plan.
"Round the per-request cost to the cent, then multiply." $0.009 becomes $0.01 and the bill $60,000, 11% high; on the routed slice $0.0027 becomes $0.00 and the function reports routing as free. Round once, at the month.
Python 3 · standard library22 lines · 9 of 9 tests passing
"""The token bill — one slice of traffic priced for a 30-day month.
A mixed bill is the sum of calls, one per slice: the levers on the page are
priced by splitting the 200,000 requests into the short 70% and the other 30%
and calling solve() once for each.
"""
def solve(daily_requests, in_tokens, out_tokens, price_in, price_out):
"""Monthly cost in USD over 30 days; prices are per million tokens.
daily_requests: requests a day in this slice of traffic.
in_tokens, out_tokens: tokens per request, prompt and reply.
price_in, price_out: USD per million input and per million output tokens.
Returns the month rounded to the dollar, rounded once, at the end.
"""
# Dollars per request = tokens × price per million ÷ 1,000,000, input and output
# priced separately because output costs five times input at the assumed rates.
# Nothing is rounded until the month: a per-request cost such as $0.0027 rounded to
# the cent would read as free.
per_day = daily_requests * (in_tokens * price_in + out_tokens * price_out) / 1_000_000
return round(per_day * 30)
The cases that ran
TESTS = [
# The plan's three cases. The first is the feature as specified: $1,800 a day.
((200_000, 1500, 300, 3.0, 15.0), 54_000),
((10_000, 4000, 500, 0.5, 2.0), 900),
((1_000_000, 800, 120, 1.0, 5.0), 42_000),
# Lever 1, the two slices on the page: the short 70% with output capped at 150, and
# the other 30% unchanged. Together $44,550.
((140_000, 1500, 150, 3.0, 15.0), 28_350),
((60_000, 1500, 300, 3.0, 15.0), 16_200),
# Lever 2: the short slice on a model at a tenth of the input price, output kept at
# the mid-tier rate as a margin. With the 30% slice, $27,540 — about $27,500.
((140_000, 1500, 150, 0.3, 15.0), 11_340),
# No traffic costs nothing.
((0, 1500, 300, 3.0, 15.0), 0),
# Input only: the output term contributes nothing when no tokens come back.
((200_000, 1500, 0, 3.0, 15.0), 27_000),
# Rounded once, at the month: $0.4662 a day × 30 = $13.99, so 14.
((333, 1000, 100, 1.0, 4.0), 14),
]