The Best Fluffy Pancakes recipe you will fall in love with. Full of tips and tricks to help you make the best pancakes.
CHEAPUNO guide
How to set per-run call budgets and log used flags for agents?
Add hard ceilings on steps and tokens to agent loops to prevent runaway costs and track which calls were actually used.
Cover

Photo: StockSnap (CC0)
What you are probably seeing
Your billing dashboard shows spikes that do not match your expected usage because agent loops keep calling tools or models until they hit a soft limit.
You notice that many API calls in your logs are marked as successful but the results are never saved or referenced in the final output, indicating wasted spend.
Why it happens
Agent systems often lack strict termination conditions, allowing them to iterate until they fail or timeout rather than stopping at a defined budget.
Without explicit logging for each tool or model call, you cannot distinguish between calls that contributed to the solution and those that were discarded during reasoning.
What changed recently
Step by step
1. Define a maximum step count and token limit for each agent run to establish a hard ceiling on resource consumption.
2. Implement a check at the start of every loop iteration that stops the agent if the accumulated cost or step count exceeds the defined budget.
3. Create a logging layer that records every individual tool or model call with a unique identifier for traceability.
4. Add a used flag to your logs to mark which calls were part of the final reasoning path versus those that were exploratory or discarded.
5. Review your logs weekly to identify patterns of wasted calls and adjust your budget thresholds to match actual operational needs.
Ways to go further
Better fit: Logging Techniques and Practices For when You are implementing the logging for model calls and usage status.. Open the free course on Alison ↗
Affiliate links: CHEAPUNO may earn a commission if you buy through them, at no extra cost to you.
Other problems readers raise
How to stop Stripe webhook retries from creating duplicate charges?
How to make Stripe webhook handlers idempotent?
Is my app ready for iPhone Duo submission?
How to check if AI vendors testified at regulatory hearings or ignored subpoenas