Yeda AI Tips · #140

Español

Put a Hard Per-Job Cap on Every Automated AI Call

Every automated AI call needs a hard cap. A bug should produce a bounded bill, not an unbounded one. When a human is in the loop, a runaway prompt is annoying — you notice, you stop it. When the call runs on a cron, in a queue worker, or inside an agent loop, nobody is watching each run, and the meter climbs quietly all night.

Why recurring spend is the dangerous kind

Interactive spend is self-limiting: a person is sitting there. Automated spend is not. The three classic failure modes each multiply your bill without anyone noticing:

None of these throw an error. They just cost money until the invoice arrives.

Cap the three axes, then alarm the account

Put a hard cap on every axis a runaway job can grow along, at the call site — not in a config nobody reads.

AxisWhat to capHow
Output lengthTokens the model may generatemax_tokens (Anthropic) / max_completion_tokens (OpenAI)
Batch sizeItems processed per runSlice the input list; hard-fail past a ceiling
Wall-clockTime one call may takeClient request timeout, plus a job-level deadline
MoneyTotal spend on the accountA cloud budget alarm

On Anthropic's Messages API, max_tokens is a required parameter — you cannot make a call without declaring the ceiling. On OpenAI's Chat Completions, max_tokens was deprecated in September 2024 in favor of max_completion_tokens, which is the only form the o-series reasoning models accept. Set it deliberately to what the task actually needs, not to the maximum.

Capping tokens bounds one call. Capping items bounds the fan-out — a job that should touch 100 rows should refuse to touch 100,000. Capping time bounds a hung call. And a budget alarm is the backstop for everything you forgot: it watches the money directly.

The account-level backstop

Even a perfectly capped job can surprise you when ten of them run at once. Put a spend alarm on any account the automation can bill against. AWS Budgets, for example, lets you set a cost budget with a fixed monthly target and get notified on both actual (already accrued) and forecasted (projected) spend — a common pattern is an alert at 80% of the budget. Notifications go to email or an Amazon SNS topic. Budgets update up to three times a day, so treat the alarm as a floor, not a real-time kill switch.

Power moves

Resources

Running LLMs in production? Yeda AI designs, audits, and ships automated AI systems with the guardrails baked in.

Talk to us · Read the blog