12/16
Part 5 of 6 · The worked exampleLearn
Take the bill down one measured step at a time
3. The plan. Each step is cheaper and each one gets checked before the next.
bill = {
"Sonnet, no cache": request_cost(SONNET, 1860, 250),
"cache the shared prompt": sonnet_hit,
"Haiku first, 20% sent on": haiku_hit + 0.2 * sonnet_hit,
"answers cut to 180 tokens": cached_cost(HAIKU, 1800, 60, 180, True) + 0.2 * cached_cost(SONNET, 1800, 60, 180, True),
}
for step, each in bill.items():
print(f"{step:26} ${each * 3_600_000:7,.0f} a month")
Which step saves the most dollars?
Pick one to see what it prints.
Pick an answer above to see the rest
A week after launch, the cache hit rate drops from 99% to almost 0. What do you check first?
Pick an answer above to see the rest