Menu

Budgeting an agent loop: input tokens are billed at every step
📰

Budgeting an agent loop: input tokens are billed at every step

DEV Community: api·Long AI·6 days ago
#2OuaJyCx
#devtoapi#devto#dev#tokens#input
Long article (820 words) — no AI summary yet.
Reading 0:00
15s threshold

Most API budgets are written for a single prompt. Agent work is not a single prompt. A 20-step loop re-sends its whole working context twenty times, and every one of those sends is billed as input tokens. That is the line item that quietly turns a "cheap" model into an expensive month.

This post walks through what actually gets billed in a loop, puts a formula on it, and prices a 20-step run on four models against the marketplace snapshot from 29 November 2026.

What gets billed on each step

An agent turn is usually three things: a system prompt, the accumulated conversation and tool results, and the model's reply. The reply is output tokens. Everything you send is input tokens, including the parts you already sent on the previous nineteen steps.

Two consequences follow directly. First, cost grows roughly with the square of step count, not linearly: step n re-bills everything up to n .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.