<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: pop3zxcv</title>
    <description>The latest articles on DEV Community by pop3zxcv (@pop3_zxcv).</description>
    <link>https://dev.to/pop3_zxcv</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4061144%2Fb521fe90-d169-4c2a-9ae2-18f7de95c1f9.jpg</url>
      <title>DEV Community: pop3zxcv</title>
      <link>https://dev.to/pop3_zxcv</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pop3_zxcv"/>
    <language>en</language>
    <item>
      <title>Why Your AI Agent Costs 6x More Than You Calculated</title>
      <dc:creator>pop3zxcv</dc:creator>
      <pubDate>Mon, 03 Aug 2026 18:27:06 +0000</pubDate>
      <link>https://dev.to/pop3_zxcv/why-your-ai-agent-costs-6x-more-than-you-calculated-3na9</link>
      <guid>https://dev.to/pop3_zxcv/why-your-ai-agent-costs-6x-more-than-you-calculated-3na9</guid>
      <description>&lt;p&gt;Pricing an LLM call is simple arithmetic. Input tokens times the input rate, plus output tokens times the output rate. Every pricing page shows you this, every calculator computes it, and for a chatbot it is correct.&lt;/p&gt;

&lt;p&gt;For an agent it is wrong by a factor of six, and the factor gets worse the longer the agent runs.&lt;/p&gt;

&lt;p&gt;The reason is not hidden or subtle. It follows from one property of language models that everybody knows and almost nobody puts into their cost estimate.&lt;/p&gt;

&lt;h2&gt;
  
  
  Models have no memory
&lt;/h2&gt;

&lt;p&gt;A language model does not remember your last request. Each call is independent. If you want the model to know what happened three steps ago, you send it again.&lt;/p&gt;

&lt;p&gt;So an agent loop does this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;step 1  send: system prompt + task
        get:  a tool call

step 2  send: system prompt + task + step 1 output + tool result
        get:  another tool call

step 3  send: system prompt + task + step 1 + step 2 + both tool results
        get:  another tool call
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Take a concrete shape. A 2,000-token system prompt with tool schemas, a 500-token task, 400 tokens of model output per step, and 1,200 tokens of tool results per step. Here is what each step actually sends:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Step&lt;/th&gt;
&lt;th&gt;Context sent&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;2,500 tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;4,100 tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;5,700 tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Each step costs more than the one before it, forever. Step 3 is more than twice the price of step 1 and it is doing the same amount of new work.&lt;/p&gt;

&lt;h2&gt;
  
  
  The formula
&lt;/h2&gt;

&lt;p&gt;Across &lt;code&gt;N&lt;/code&gt; steps, every step pays for the system prompt and the task. That part is linear:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;N × (system + user)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The accumulated history is the part that hurts. Step &lt;code&gt;i&lt;/code&gt; carries the output and tool results of all &lt;code&gt;i − 1&lt;/code&gt; steps before it. Summing that over the whole run gives the triangular number:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;(output + tool_result) × N × (N − 1) / 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Put together:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;total input tokens = N × (system + user) + (output + tool_result) × N × (N−1) / 2
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The second term is quadratic. Double the step count and that part roughly quadruples.&lt;/p&gt;

&lt;h2&gt;
  
  
  What that does at different step counts
&lt;/h2&gt;

&lt;p&gt;Same workload shape as above, no retries, no caching:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Steps&lt;/th&gt;
&lt;th&gt;Raw conversation&lt;/th&gt;
&lt;th&gt;Billed input&lt;/th&gt;
&lt;th&gt;Multiplier&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;7,300&lt;/td&gt;
&lt;td&gt;12,300&lt;/td&gt;
&lt;td&gt;1.7×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;5&lt;/td&gt;
&lt;td&gt;10,500&lt;/td&gt;
&lt;td&gt;28,500&lt;/td&gt;
&lt;td&gt;2.7×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;10&lt;/td&gt;
&lt;td&gt;18,500&lt;/td&gt;
&lt;td&gt;97,000&lt;/td&gt;
&lt;td&gt;5.2×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;12&lt;/td&gt;
&lt;td&gt;21,700&lt;/td&gt;
&lt;td&gt;135,600&lt;/td&gt;
&lt;td&gt;6.2×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;20&lt;/td&gt;
&lt;td&gt;34,500&lt;/td&gt;
&lt;td&gt;354,000&lt;/td&gt;
&lt;td&gt;10.3×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;30&lt;/td&gt;
&lt;td&gt;50,500&lt;/td&gt;
&lt;td&gt;771,000&lt;/td&gt;
&lt;td&gt;15.3×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;50&lt;/td&gt;
&lt;td&gt;82,500&lt;/td&gt;
&lt;td&gt;2,085,000&lt;/td&gt;
&lt;td&gt;25.3×&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;100&lt;/td&gt;
&lt;td&gt;162,500&lt;/td&gt;
&lt;td&gt;8,170,000&lt;/td&gt;
&lt;td&gt;50.3×&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;"Raw conversation" is the number you get if you add up everything the agent said and everything it read. It is the number your intuition reaches for. "Billed input" is what appears on the invoice.&lt;/p&gt;

&lt;p&gt;At 3 steps the gap is small enough to ignore. At 12 steps you are paying 6.2 times your estimate. At 50 steps, 25 times. A deep research agent that runs a hundred steps bills fifty times the tokens the conversation contains.&lt;/p&gt;

&lt;p&gt;Nothing is broken when this happens. It is what the pricing model does when you loop it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Retries make it worse
&lt;/h2&gt;

&lt;p&gt;A failed tool call, malformed JSON, a guardrail rejection: whatever the cause, a retry re-sends the context too, at whatever depth the failure happened.&lt;/p&gt;

&lt;p&gt;At a 10% retry rate the 12-step example moves from 6.2× to 6.9×. Not dramatic on its own, but it stacks on top of a number that is already six times your estimate, and retry rates in production are rarely zero.&lt;/p&gt;

&lt;h2&gt;
  
  
  Three things that move the bill
&lt;/h2&gt;

&lt;p&gt;Take the 12-step agent at a 10% retry rate on Claude Sonnet 5. Baseline is $0.351 per run. At 1,000 runs a day that is $10,534 a month.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prompt caching.&lt;/strong&gt; Most of what you are paying for is context re-sent verbatim, and cache reads cost roughly 90% less than fresh input. A 90% hit rate takes the run to $0.109. That is 69% off, with the same model and the same agent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Step count.&lt;/strong&gt; Halving the loop from 12 steps to 6 takes it to $0.112, or 68% off. Almost identical to what caching bought you, which is worth sitting with for a second: removing half the reasoning steps and caching everything are about equally valuable.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tool result size.&lt;/strong&gt; Trimming tool results from 1,200 tokens to 400 takes it to $0.235, or 33% off. Smaller than the other two but easier than either. Every tool result is re-sent by every step that follows it, so truncating a verbose search result compounds down the whole run.&lt;/p&gt;

&lt;h2&gt;
  
  
  The counterintuitive one
&lt;/h2&gt;

&lt;p&gt;The instinct when a bill is too high is to switch to a cheaper model. Compare that against cutting steps, on a 20-step agent:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Change&lt;/th&gt;
&lt;th&gt;Cost per run&lt;/th&gt;
&lt;th&gt;Saving&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Baseline: Sonnet 5, 20 steps&lt;/td&gt;
&lt;td&gt;$0.867&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Swap to Haiku 4.5, still 20 steps&lt;/td&gt;
&lt;td&gt;$0.433&lt;/td&gt;
&lt;td&gt;50%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Stay on Sonnet 5, cut to 10 steps&lt;/td&gt;
&lt;td&gt;$0.257&lt;/td&gt;
&lt;td&gt;70%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Ten steps on the frontier model is cheaper than twenty steps on the small one, and you keep the better model.&lt;/p&gt;

&lt;p&gt;This is not a quirk of these two models. Price is linear: a model at half the rate costs half as much, and that is the ceiling on what switching can buy you. Step count is superlinear, so halving it saves more than half. The gap widens as the agent gets longer.&lt;/p&gt;

&lt;p&gt;Which means the first question about an expensive agent is not "what cheaper model could do this", it is "why does this take twenty steps".&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the usual calculators miss it
&lt;/h2&gt;

&lt;p&gt;Nearly every LLM pricing calculator prices one request. Input times rate, plus output times rate. That is the right model for a chat completion and it is what the pricing pages describe, so it is a reasonable thing to build.&lt;/p&gt;

&lt;p&gt;The closest prior treatment I found is &lt;a href="https://softcery.com/ai-voice-agents-calculator" rel="noopener noreferrer"&gt;Softcery's voice agent calculator&lt;/a&gt;, which applies a flat 1.8× "reality factor" to LLM cost and notes in a footnote that conversation history "compounds O(n²) with turns". They diagnosed the mechanism correctly. For voice at roughly four turns a minute with short turns, a constant is probably a fair approximation, and theirs also absorbs function-calling round trips and barge-in handling.&lt;/p&gt;

&lt;p&gt;Tool-using agents sit somewhere else on the curve. Turns are fewer but each one drags a large tool result behind it, so the quadratic term takes over much earlier. A constant that fits a voice call will not fit a research loop, which is the case for computing the curve rather than picking a number.&lt;/p&gt;

&lt;h2&gt;
  
  
  What this arithmetic does not tell you
&lt;/h2&gt;

&lt;p&gt;Worth being clear about the edges.&lt;/p&gt;

&lt;p&gt;Retries here are a flat multiplier on the total. Real retries happen at a specific depth, so a failure at step 18 costs far more than one at step 2, and a flat rate under-counts late failures.&lt;/p&gt;

&lt;p&gt;Cache hit rate is one number. In reality your system prompt might cache at 99% while your tool results never cache at all.&lt;/p&gt;

&lt;p&gt;Providers tokenize differently, so comparing token counts across vendors is approximate. And cache writes are not free everywhere: OpenAI's GPT-5.6 charges 1.25× uncached input to write to cache, which the numbers above do not include.&lt;/p&gt;

&lt;p&gt;None of this changes the shape of the curve. It does mean you should treat any figure here as a planning estimate rather than a billing forecast.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run it on your own numbers
&lt;/h2&gt;

&lt;p&gt;I built a calculator that models the loop instead of a single request: step count, tool result size, retry rate, cache hit rate, across 17 models, with the per-step accumulation and cost attribution broken out. Free, no signup, runs entirely in the browser.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://costperrun.com" rel="noopener noreferrer"&gt;costperrun.com&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The pricing data is &lt;a href="https://github.com/pop3zxcv/costperrun" rel="noopener noreferrer"&gt;on GitHub&lt;/a&gt; with a source URL and verification date against every rate. If you find a stale price, open an issue.&lt;/p&gt;

&lt;p&gt;The number worth checking first is your step count. It is almost always higher than you think, and it is the term that squares.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>llm</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
