LLM agent cost in production 2026: $0.40 for an 8-step loop

By LLMTest Team · Jul 31, 2026 · 6 min read costagentssolopreneursvibe-coders
On this page

On this page

  1. Why agents accumulate costs
  2. Workload 1: 3-call customer support agent
  3. Workload 2: 8-step sequential coding agent
  4. Workload 3: 5-parallel research agent
  5. Workload comparison at a glance
  6. Three ways to cut agent costs
  7. Subscription vs API for agent workloads

A ticket-classification bot spends $0.008 per conversation on Claude Sonnet 5. An 8-step coding agent on the same model spends $0.159 per run. That 20x gap has nothing to do with smarter models or more complex tasks: it comes from context accumulation. Every step sends the full conversation history, so the input token count climbs with each turn even when nothing meaningful changes.

This post models three agent workloads, each with exact token counts and USD totals per run and per 1,000 runs across four model tiers.

Why agents accumulate costs

Single-call requests are stateless: send context in, get an answer back. Agent loops are stateful in the worst way for your bill. Each step appends its output to the conversation, then the next step sends the whole conversation again. A tool result that landed in step 2 is still being paid for in step 8.

Two forces compound this:

Tool results inflate context fast. A code search returning three file excerpts adds 1,500 to 2,000 tokens to every subsequent step. A raw JSON API response can add more. By step 6, the agent may be sending 4,000 tokens of tool results that haven't changed since step 2.

Output tokens cost 5x more than input. An 8-step agent generating 500 tokens of output per step accumulates $0.020 of output cost on Sonnet 5 before counting input. That scales fast.

The hidden costs that compound LLM bills often stem from exactly this pattern: prompt bloat and retry loops are single-call versions of what agent loops do structurally.

Workload 1: 3-call customer support agent

A support bot classifies user intent, queries a knowledge base, then drafts a reply. Three sequential model calls:

Step Input tokens Output tokens What's included
Classify intent 800 80 System prompt (500) + user message (300)
Retrieve KB article 1,480 250 Prior turn + search result (600)
Draft response 1,930 450 Full conversation so far
Total 4,210 780
Model Per run Per 1,000 runs
GPT-4o-mini ($0.15/$0.60 per MTok) $0.0011 $1.10
Claude Haiku 4.5 ($1/$5) $0.0082 $8.20
Claude Sonnet 5 ($2/$10, intro) $0.0164 $16.40
Claude Opus 5 ($5/$25) $0.0410 $41.00

A direct single-call version of the same bot (system prompt plus user message, one response) runs about 2,000 input and 450 output: $0.0043 on Haiku. The 3-step agent costs roughly 2x that per run. The extra cost buys better retrieval accuracy and cleaner separation between classification and response.

Workload 2: 8-step sequential coding agent

This is the workload pattern behind Claude Code sessions, Cursor agent mode, and Copilot Workspace. The agent reads files, plans the change, writes code across multiple blocks, generates tests, reviews for issues, and writes a PR description. Context grows on every step:

Step Input tokens Output tokens Notes
1. Plan 2,000 400 System prompt (1,500) + task
2. Read codebase 3,900 300 + file excerpts via tool (1,500 tokens)
3. Write code block 1 5,200 600 Context still growing
4. Write code block 2 6,200 600
5. Write code block 3 6,800 500
6. Write tests 7,300 700
7. Review and lint 8,000 400
8. Write PR description 8,400 800 Full history by now
Total 57,800 4,300
Model Per run Per 1,000 runs
GPT-4o-mini $0.011 $11.00
Claude Haiku 4.5 $0.080 $80.00
Claude Sonnet 5 $0.159 $159.00
Claude Opus 5 $0.396 $396.00

A single-call equivalent for the same coding task (send full context, get code back) runs about 6,000 input and 1,200 output: $0.012 on Haiku, $0.036 on Sonnet 5, $0.060 on Opus 5. The 8-step agent costs 6 to 7 times more due purely to context re-transmission. The tradeoff is output quality: iterative generation catches issues a single-shot call misses.

This is precisely why cost budget guards in agent loops are essential. An uncapped 15-step loop on Opus 5 can reach $0.60+ per run before the model decides it's finished.

Workload 3: 5-parallel research agent

A research agent fires 5 independent queries in parallel, then synthesizes the results. Because each parallel worker runs independently, there's no context accumulation across workers. You pay for breadth, not depth.

Calls Input tokens Output tokens Notes
5 parallel workers (each) 2,000 500 System + query + retrieved docs
Synthesis call 5,000 1,000 System + all 5 worker summaries
Total 15,000 3,500
Model Per run Per 1,000 runs
GPT-4o-mini $0.004 $4.00
Claude Haiku 4.5 $0.033 $33.00
Claude Sonnet 5 $0.065 $65.00
Claude Opus 5 $0.163 $163.00

Running the same 5 research steps sequentially, each step carrying the prior step's output, would roughly triple the input token count. The parallel design trades some coherence (workers don't see each other's results until synthesis) for significantly lower cost.

Workload comparison at a glance

All three workloads on Claude Sonnet 5 at $2/$10 per MTok:

Workload Model calls Total tokens Cost per 1,000 runs
3-call support bot 3 ~5,000 $16.40
5-parallel research 6 ~18,500 $65.00
8-step coding loop 8 ~62,100 $159.00

The coding loop costs 10x the support bot despite making only 2.7x the number of calls. Call count doesn't predict cost. Token accumulation does.

Three ways to cut agent costs

Compress tool results before feeding them back. If a code search returns 3 files (2,000 tokens), extract only the relevant functions before appending them (400 tokens). Across the 8-step coding agent with two tool calls in early steps, this saves about 10,000 input tokens per run. On Sonnet 5, that's $20 per 1,000 runs, a 13% reduction.

Cache the static system prompt. A 1,500-token system prompt re-sent on all 8 steps accounts for 12,000 tokens of input per run. With Anthropic's prompt caching, repeated reads cost 10% of the base input rate. At a 90% cache-hit rate on Sonnet 5, the system prompt portion drops from roughly $24 to $4 per 1,000 runs. The prompt caching break-even analysis walks through how to calculate whether your prefix length justifies the 25% write surcharge.

Route early steps to cheaper models. Steps 1 to 3 in the coding loop (planning and retrieval) don't need frontier reasoning. Running them on Haiku 4.5 ($1/$5) and escalating to Sonnet 5 for code generation and review cuts the blended cost from $159 to roughly $110 per 1,000 runs. The cheap-first routing pattern shows how to implement this without restructuring your agent.

Subscription vs API for agent workloads

Tool Monthly cost Equivalent agent runs (Sonnet 5) Best for
Anthropic Claude Pro $20/mo 126 8-step coding runs Occasional personal coding sessions
Anthropic Claude Max $100/mo 629 runs Heavy personal Claude Code use
GitHub Copilot Pro+ $19/mo Bundled IDE-integrated agentic coding
OpenAI ChatGPT Plus $20/mo N/A (GPT-4o-mini API is $11/1k) UI-based research and writing

One caveat: subscriptions cover access to the provider's own interface (claude.ai, Claude Code, ChatGPT). If you're building a product that runs agent sessions for your customers, you use the API directly and subscription tiers don't apply to that traffic.

Verify current pricing on Anthropic's pricing page{:target="_blank" rel="noopener"} before committing. Claude Sonnet 5 is at introductory pricing ($2/$10 per MTok) through August 31, 2026, after which it reverts to standard rates.

To get per-session cost attribution without adding custom instrumentation, LLMTest's proxy logs token usage per call and rolls it up by agent session, so you can see exactly which workloads are spending what before the monthly bill arrives.

Ship LLM features without burning your budget.

LLMTest proxies your OpenAI / Anthropic calls, tracks cost per feature, and auto-rewrites prompts to be cheaper while holding quality. Free to start.

Create a free account

Related articles

Tool calling in Node.js in 2026: 3 guards against runaway loops
Three production guards that stop runaway LLM agent loops in Node.js: max turns, cost budgets, and return value validation with working code.
How to route LLM prompts in 2026: cheap first, escalate on fail
Route each prompt to the cheapest model that handles it well. When quality falls short, escalate silently. Here's the pattern with working Node.js code.