The Question Everyone Asks After the Demo
An AI agent looks cheap in a demo and expensive in production. The reason is simple: agents loop. Every step re-sends context and generates reasoning tokens, so a "one prompt" task can quietly become dozens of model calls. This guide gives you the real monthly math and the levers that actually move it.
The Cost Formula
An agent's monthly bill is roughly:
steps per task × (input tokens + output tokens) × task volume × model rate
The multiplier people forget is steps per task. A retrieval-augmented, tool-using agent might make 5–20 model calls per user task, each re-sending a growing context window. That's why output tokens and re-sent context — not the first prompt — dominate the bill.
Worked Examples
Assume a moderate agent: ~15 calls per task, ~4K input + ~1K output per call (~75K tokens per task), and 3,000 tasks/month (~225M tokens). Using current rates:
| Model | Rate (in/out per 1M) | ~Monthly cost |
|---|---|---|
| Claude Opus 4.8 | $5 / $25 | ~$2,025 |
| GPT-5.4 | $2.50 / $15 | ~$1,125 |
| Gemini 2.5 Pro | $1.25 / $10 | ~$675 |
| DeepSeek V4 Flash | $0.44 / $1.32 peak | ~$139 |
(These direct-rate figures illustrate 180M input and 45M output tokens before caching, retries, tools, or volume discounts; your token mix will differ.) The spread is still large, but the correct decision metric is cost per successful task rather than sticker price alone.
The Hidden Cost Drivers
- "Thinking"/reasoning modes can consume substantially more output tokens. Set an explicit reasoning budget where supported and enable higher effort only for tasks that pass a value test.
- Growing context. Each step re-sends history. Prune aggressively; summarize old turns instead of resending them raw.
- Retry storms. Poor error handling doubles spend without producing more output. Use exponential backoff.
- Runaway loops. An agent that doesn't know when to stop burns tokens indefinitely. Cap steps and add a budget guard.
- The staging experiment nobody turned off. Track spend per feature/environment.
How to Cut It (Biggest Levers First)
- Route by difficulty. Run most steps on a cheap model (DeepSeek V4 Flash, Haiku, Gemini Flash-Lite) and escalate only the hard ones to a flagship. This model-cascade is the single biggest lever — often 5–25x.
- Cache the stable context. Cached-input tiers can sharply reduce repeated input. Agents that resend the same system prompt and tools every step benefit most; measure the actual cache-hit ratio.
- Batch the non-urgent. 50% off for anything a human isn't waiting on.
- Trim context and cap output. Fewer tokens in and out on every one of those 15 calls compounds.
Full playbook in how to reduce AI API costs.
Build It So Routing Is Trivial
The cheap-default / premium-escalation pattern needs easy model switching. A single-key gateway makes the model one config string — and on LinkModel you get fixed per-request pricing (at the currently displayed LinkModel rate) across Claude, GPT, Gemini, and DeepSeek, so your agent can route per step without juggling providers. Architecture in build an AI app with multiple models.
A More Complete Agent Cost Formula
Token price is only one line item. Estimate a run as:
run cost = model input + cached input + model output + tool/API calls + retries + storage/compute + human review
Then multiply by successful runs, not requested runs. A workflow with cheap tokens and frequent failures can cost more than a pricier model that finishes in fewer steps.
Worked Per-Run Scenario
Assume an agent makes eight model calls. Each call reads 6,000 input tokens and produces 800 output tokens. The task therefore consumes 48,000 input and 6,400 output tokens before retries. At $1 per million input tokens and $5 per million output tokens, model spend is:
- Input:
48,000 ÷ 1,000,000 × $1 = $0.048 - Output:
6,400 ÷ 1,000,000 × $5 = $0.032 - Base model cost:
$0.08 per run
At 50,000 runs per month, that is $4,000 before tools and retries. A 10% retry rate raises model spend to about $4,400. If a paid search call costs $0.01 and occurs three times per run, add another $1,500.
Instrument Before Optimizing
Log workflow name, model ID, input/cached/output tokens, tool name and price, step count, retry reason, final status, latency, and reviewer result. Aggregate by feature and customer. Monthly provider totals cannot tell you which agent step is wasting money.
Set two guards: a maximum step count and a maximum dollar budget per run. Stop or request approval when either is reached.
Bottom Line
A production agent typically costs tens to low-thousands of dollars a month, and model choice + routing + caching move that by 10x or more. Estimate with the formula, default to a cheap model, escalate only when needed, cache the stable context, and cap your loops.
Start free with a $1 credit and benchmark your agent's real per-task cost across models before you commit.
