An always-on agent rarely overspends because a token is expensive. It overspends because the loop multiplies: every step re-sends the system prompt, the task and everything already done, then bills the reply on top. The rate prices a step; the loop decides how many steps you pay for.
Four lines, and they compound:
Monthly cost = Σ over steps (input × rate + output × rate) + retry overhead. A rate cut moves each term 20 or 30 percent; a step cap changes how many terms exist.
A five-step task with 2,000 tokens of prompt per request, 400 output tokens per step and 1,000 tokens of new history each step costs 10,000 input and 2,000 output tokens stateless. With history accumulating it is 2+3+4+5+6 = 20,000 input for the same work — double, at an unchanged rate, with an unchanged answer.
Doubling the step budget doubles requests and more than doubles input, because each step grows. Ten steps of accumulating context is not twice a five-step agent, it is closer to three times.
Billing on failure depends on what the request produced. A request that generated no token is cheap — at Tapix AI, failed requests are not billed; only generated tokens are charged. The expensive retry is the one that succeeds after a failure: it pays the accumulated context again, and the failed attempt bought nothing. A 20% retry rate on an accumulating loop is a 20% input increase per task, so retries belong in the budget model, not the incident log.
In a loop, turn twenty pays for turns one through nineteen as input. That is the request format: tool results, plans and prior messages all go back up on every call.
None of this costs quality if the agent can still retrieve what it dropped. If the state is removable, it was billed for nothing.
A budget that lives in a dashboard is a report, not a limit. Four caps bound the bill:
Order matters. Degrade before you fail: smaller model, less retrieval, fewer tools, then a logged failure. A silent downgrade is worse than a visible error, because the error can be measured.
Cost units with output at 5× input, per 1,000 tasks, so the ratios hold at any dollar rate. Token counts are illustrative.
| Loop pattern | Input tokens | Output tokens | Cost units (input + 5 × output) | Multiple of one call | What fixes it |
|---|---|---|---|---|---|
| Single call, no loop | 2M | 0.4M | 4 | 1.0× | nothing to fix |
| Five steps, context reset each step | 10M | 2M | 20 | 5.0× | step cap |
| Five steps, context accumulating | 20M | 2M | 30 | 7.5× | summarise between steps |
| Accumulating plus 20% retries | 24M | 2M | 34 | 8.5× | retry budget, idempotent tools |
Row three costs 50% more than row two for the same steps and replies; only the context policy differs. Row four is a retry storm before anyone notices.
Four steps, before the agent sees production traffic.
Re-run it when the prompt changes: a longer system prompt raises the floor of every step, which is how agent bills creep.
Tapix AI is a gateway, not a model vendor: one OpenAI-compatible endpoint, priced below the list price, billed per token from prepaid credit, no monthly fee, failed requests not billed. The prepaid balance doubles as the hard ceiling, and the model ladder is a string change. It lowers the rate; it does not shrink the loop.
Q: Do failed or retried agent steps cost money?
A request that generates no tokens is not billed at Tapix AI. The retry cost is the successful attempt that follows, paying the accumulated context again; a retry storm shows up as input tokens, not an error line.
Q: Why does my agent bill grow faster than my task count?
Context accumulation. Input scales with loop length squared, so more tasks at more steps each compounds. Check steps per task before rates.
Q: Should I cap max_tokens or max steps first?
Steps. A step cap bounds input, output and retry exposure at once; a token cap bounds one step while the loop keeps going.
Q: Is switching to a cheaper model the right fix?
It is the last lever. A tier ladder suits cheap subtasks; moving the whole loop to a small model usually costs more in retries and extra steps than it saves.
Q: How do I keep an always-on agent's spend predictable?
Prepaid credit plus caps. The balance is the ceiling, so a runaway loop cannot produce an invoice you did not choose, and caps stop it burning the balance in an hour.
Cap the steps, shrink the context between steps, keep scratch state out of the prompt, and put the cheap model on the cheap subtasks. Then worry about the per-token rate.