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. Second, verbosity from tools is not free — a tool that returns a 4,000-token JSON blob adds 4,000 input tokens to this step and to every step after it.
The arithmetic
For a loop of N steps with a starting context of C0 tokens and an average per-step growth of g tokens:
input_tokens_total ≈ N × C0 + g × N(N−1)/2
The second term dominates as soon as the loop gets long. At 20 steps with a 2,000-token average growth, that term alone is 380,000 tokens — 19 times the starting context.
Output tokens are usually the smaller half. If each step emits 600 tokens, a 20-step run produces 12,000 output tokens, but 240,000 input tokens. Budget by input, verify with output.
A worked example: 20 steps, four models
Assume a 4,000-token system prompt and history that grows to about 20,000 tokens by step 20 — an average of 12,000 input tokens per step, 600 output tokens per step. Prices are from the marketplace pricing page, in CNY per million tokens, snapshot 29 November 2026.
| Model | Input ¥/M | Output ¥/M | Input cost | Output cost | Per run |
|---|---|---|---|---|---|
| deepseek-v4.1-flash | 0.11 | 0.43 | ¥0.026 | ¥0.005 | ¥0.032 |
| glm-5.3 | 0.43 | 1.51 | ¥0.103 | ¥0.018 | ¥0.121 |
| gpt-6-astra | 0.52 | 2.58 | ¥0.125 | ¥0.031 | ¥0.156 |
| claude-opus-5 | 1.47 | 7.36 | ¥0.353 | ¥0.088 | ¥0.441 |
Per run, the spread between the cheapest and the most expensive is 13.8×: three fen against forty-four. That looks like small change until you put a volume behind it. At 1,000 runs a day, the same loop costs ¥32 on the cheapest model and ¥441 on the most expensive one — ¥9,600 versus ¥132,000 over a month of steady traffic.
Where the money hides: tool output
The formula above has one knob most teams never touch: g, the per-step growth. In practice g is set by whatever your tools return, not by the model. A search tool that dumps raw HTML, a database tool that returns the whole table, a browser tool that sends back page chrome — each adds tokens that get re-billed 19 more times in a 20-step loop.
Trimming a tool's output from 4,000 to 800 tokens cuts the quadratic term by 80%. On the gpt-6-astra row that is roughly ¥0.05 off every run — and it costs nothing to implement, unlike switching models. Before shopping for a cheaper model, look at what your tools hand back.
Three budgeting rules that hold up
Budget input, model output. Write the monthly estimate from expected input tokens and re-check actual spend against output tokens. The two halves move independently: a model with a cheap input and an expensive output punishes long answers, not long context.
Cap the loop, not the prompt. A maximum step count is a spend ceiling. Without one, a retry storm can triple the token count while every individual call still looks normal on a dashboard.
Price the retry. Every retried step pays for the failed attempt's input plus the successful one. If your retry rate is 10%, add 10% to input tokens — not 5%, because retries also inflate the context they carry forward.
Checking the numbers before you commit
The table above is arithmetic on published per-million-token prices; your own loop will have a different average context and a different tool verbosity, so the useful step is to re-run it with your numbers. The live pricing table lists input and output prices per model and per seller, which is the only way to compare across a marketplace where two sellers can quote the same model at different prices. If you are unsure which billing unit applies to your case, the API documentation covers per-token and per-call billing side by side.
If you want to see which models on the platform carry the widest input/output spread before you pick one, the model plaza groups them by vendor and capability.
None of this changes the shape of the bill: input tokens dominate agent loops, context growth makes cost quadratic, and tool output is the cheapest lever you have.
Top comments (0)