Budgets
Read · 1 of 2
A ceiling on every run
Turn limits stop endless loops. Cost limits stop expensive ones: one huge document read ten times can burn through a day's budget.
Give each run a budget, check it before every call, and stop cleanly when the next call would go over. Then report what was done, so a person can decide whether to raise it.
Read this lesson as text
Decide what a task may cost before it starts, and stop at the limit.
A ceiling on every run
Turn limits stop endless loops. Cost limits stop expensive ones: one huge document read ten times can burn through a day's budget.
Give each run a budget, check it before every call, and stop cleanly when the next call would go over. Then report what was done, so a person can decide whether to raise it.
Exercise: Stop at the budget
Input: the budget in dollars, then the planned cost of each model call on one line.
Make the calls in order while the total stays within budget. Print calls made: N, spent $X (2 decimals), then either finished or stopped: the next call ($Y) would go over budget.