How do you enforce a $0.50 per-task LLM budget at runtime beyond setting max_tokens?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Track cumulative cost across all calls, check projected next-call cost against remaining budget, downgrade or early-finalize when close, hard-kill on exhaustion. The runtime owns the budget, not a per-call cap.
Imagine a road trip with 50 dollars in your pocket. You do not control the trip by saying every snack must cost less than 5 dollars. That would let you spend 5 dollars on snacks ten times and run out. You control it by carrying a running tally: how much have I spent so far, how much is left, how much is the next stop probably going to cost. When you are getting close to empty, you stop at a cheaper place or skip a stop. When you hit zero, you stop the trip and call home. An agent task budget works the same way. You do not just cap each LLM call. You watch the running total, predict the next call, and adjust before you run out instead of after.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
Lead with the framing that budget is a per-task runtime concern, not a per-call model parameter. Describe the running-sum cost track and the per-call projection step. Cover the two close to limit strategies, tier downgrade and early finalize, and explain why each works. Hard-kill on exhaustion with a structured failure carrying the partial answer and reason code. Close with observability: per-task cost emission, p99 alerts, prompt caching as a multiplier on effective budget.
Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Setting max_tokens per call and hoping the total stays under budget, when max_tokens has no idea what the other calls in the task have already spent.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.