Cheapest LLM for AI Agents: 30 Models Ranked by Cost Per Run
Every current API model ranked by the cost of the same 12-step tool-calling run, a reliability tier list, the route-cheap-escalate-on-failure pattern with code, and when the flagship is cheaper per successful task.
The article text carries the review date. The rate table below is rebuilt from the live catalogue on every deploy.
Fastest win
On a reference 12-step tool-calling run (166,800 input tokens, 3,600 output tokens) DeepSeek V4 Flash costs $0.009, GPT-5.4 nano $0.038, Gemini 3.8 Flash $0.139, GPT-5.4 mini $0.141, Claude Haiku 4.5 $0.185, Claude Sonnet 5 $0.370 and GPT-5.5 $0.942. The cheapest model that reliably follows tool schemas without a validator on every call is Gemini 3.8 Flash or GPT-5.4 mini at about $0.14; everything below that price needs strict schemas, validation and an escalation path.
The cheapest LLM for agents, in one number each
The cheapest model that will run a tool-calling agent is DeepSeek V4 Flash at $0.05 in / $0.16 out per 1M tokens, or $0.0089 for a reference 12-step run. The cheapest model we would run unattended in production is Gemini 3.8 Flash ($0.75 / $3.75) or GPT-5.4 mini ($0.75 / $4.50) at about $0.14 per run. The cheapest flagship-class model is Claude Sonnet 5 ($2 / $10) at $0.37. Prices are USD per 1M tokens from our catalogue as of 2026-09-11.
The reference run: a 4,000-token system prompt plus tool definitions sent every step, a 1,500-token tool result appended after each step, 300 output tokens per step, 12 steps. Because each step re-sends the full history, the context at step k is 4,000 + (k - 1) × 1,800 tokens, and the run totals:
- Input tokens = 12 × 4,000 + 1,800 × 12 × 11 ÷ 2 = 48,000 + 118,800 = 166,800
- Output tokens = 12 × 300 = 3,600
- Run cost = 166,800 × (input rate ÷ 1,000,000) + 3,600 × (output rate ÷ 1,000,000)
For Claude Sonnet 5: $0.3336 + $0.036 = $0.3696. Input is 90% or more of the run on every model, so the ranking tracks the input price. The general formula for N steps is in how much does an AI agent cost to run.
All 30 current models ranked by cost of the 12-step run
No caching or batch discounts applied. Multiply the last column by 1,000 for a monthly budget at 1,000 runs.
| Rank | Model | $/1M in/out | 12-step run |
|---|---|---|---|
| 1 | DeepSeek V4 Flash | $0.05/$0.16 | $0.0089 |
| 2 | GLM 4.7 Flash | $0.06/$0.40 | $0.0114 |
| 3 | Llama 4 Scout | $0.10/$0.30 | $0.0178 |
| 4 | DeepSeek V4.1 Flash | $0.15/$0.60 | $0.0272 |
| 5 | Llama 4 Maverick | $0.20/$0.70 | $0.0359 |
| 6 | GPT-5.4 nano | $0.20/$1.25 | $0.0379 |
| 7 | Codestral 2508 | $0.30/$0.90 | $0.0533 |
| 8 | Qwen3 Coder 480B | $0.30/$1.00 | $0.0536 |
| 9 | MiniMax M2.7 | $0.30/$1.20 | $0.0544 |
| 10 | Gemini 3.5 Flash Lite | $0.30/$2.50 | $0.0590 |
| 11 | GPT-4.1 mini | $0.40/$1.60 | $0.0725 |
| 12 | GLM 4.7 | $0.40/$1.75 | $0.0730 |
| 13 | Mistral Medium 3.1 | $0.40/$2.00 | $0.0739 |
| 14 | Devstral 2 | $0.40/$2.00 | $0.0739 |
| 15 | Mistral Large 3 | $0.50/$1.50 | $0.0888 |
| 16 | DeepSeek V4 Pro | $0.66/$1.98 | $0.1172 |
| 17 | Gemini 3.8 Flash | $0.75/$3.75 | $0.1386 |
| 18 | GPT-5.4 mini | $0.75/$4.50 | $0.1413 |
| 19 | Kimi K2.6 | $0.95/$4.00 | $0.1729 |
| 20 | Claude Haiku 4.5 | $1.00/$5.00 | $0.1848 |
| 21 | GPT-5.3-Codex | $1.75/$14.00 | $0.3423 |
| 22 | Grok 4.6 | $2.00/$6.00 | $0.3552 |
| 23 | Qwen 3.8 Max | $2.00/$6.00 | $0.3552 |
| 24 | Claude Sonnet 5 | $2.00/$10.00 | $0.3696 |
| 25 | Gemini 3.1 Pro | $2.00/$12.00 | $0.3768 |
| 26 | GPT-5.4 | $2.50/$15.00 | $0.4710 |
| 27 | Claude Sonnet 4.6 | $3.00/$15.00 | $0.5544 |
| 28 | Claude Opus 5 | $5.00/$25.00 | $0.9240 |
| 29 | GPT-5.5 | $5.00/$30.00 | $0.9420 |
| 30 | GPT-5.5 Pro | $30.00/$180.00 | $5.6520 |
The spread from rank 1 to rank 29 is 106×. Prompt caching narrows it without reordering it: with cache reads at roughly 10% of list on Anthropic and OpenAI and roughly 25% on Gemini, Sonnet 5 falls to about $0.12 and Gemini 3.8 Flash to about $0.06 per run. Live rows are on the models page.
Reliability tiers: which cheap models actually follow tool schemas
Price is the easy half. An agent model has to emit a tool call that matches the schema, pick the right tool, stop when done, and not loop. The tiers below are our editorial reading of how much scaffolding each model needs in a production loop, not a benchmark; run your own eval on your own schemas before committing.
- Tier A, run unattended with normal validation: Claude Opus 5, GPT-5.5, GPT-5.4, Gemini 3.1 Pro, Claude Sonnet 5. Consistent schema adherence, good stopping behaviour, fewest wasted steps.
- Tier B, run unattended with strict schemas: Claude Haiku 4.5, GPT-5.4 mini, Gemini 3.8 Flash, GPT-5.3-Codex and Devstral 2 (coding loops), DeepSeek V4 Pro, Kimi K2.6, Qwen 3.8 Max, Grok 4.6, Mistral Large 3.
- Tier C, run with validation, retries and an escalation path: GPT-5.4 nano, Gemini 3.5 Flash Lite, DeepSeek V4 Flash, DeepSeek V4.1 Flash, GLM 4.7, MiniMax M2.7, Qwen3 Coder 480B, Llama 4 Maverick, Codestral 2508, Mistral Medium 3.1. Expect malformed arguments, wrong tool choices on large tool sets and step-count blowouts on open-ended tasks.
- Tier D, not as the planner: Llama 4 Scout, GLM 4.7 Flash, GPT-4.1 mini (previous generation). Fine for single-shot classification inside a loop someone else drives.
The cheapest model that still does this reliably is Gemini 3.8 Flash or GPT-5.4 mini at about $0.14 per run, with Claude Haiku 4.5 at $0.185 as the Anthropic equivalent. Below $0.10 per run you are buying a model that needs a supervisor, and the supervisor's cost belongs in your per-task number.
The pattern: route cheap, validate, escalate on failure
The cost-per-task winner is almost never a single model. It is a Tier C or B model as the first attempt, a validator that checks the tool call and the final result, and a Tier A model that takes over only when the cheap attempt fails. One OpenAI-compatible client through OpenRouter makes the ladder a list of model names (see our OpenRouter vs direct API comparison for the routing margin).
from openai import OpenAI
client = OpenAI(base_url="https://openrouter.ai/api/v1", api_key=KEY)
LADDER = [ # (model, $ in per 1M, $ out per 1M)
("deepseek/deepseek/deepseek-v4-flash", 0.05, 0.16),
("google/gemini-3.8-flash", 0.75, 3.75),
("anthropic/claude-sonnet-5", 2.0, 10.0),
]
def run_task(task, max_steps=12, budget_usd=0.60):
spent = 0.0
for model, p_in, p_out in LADDER:
history = [{"role": "user", "content": task}]
for _ in range(max_steps):
r = client.chat.completions.create(model=model, messages=history,
tools=TOOLS, max_tokens=2000)
u = r.usage
spent += (u.prompt_tokens * p_in + u.completion_tokens * p_out) / 1e6
if spent > budget_usd:
return None, spent # hard cap: give up
ok, done = apply_tool_calls(r, history) # validate + execute
if not ok:
break # schema/tool failure: escalate
if done and validate_result(history):
return history[-1], spent # success on this rung
return None, spentvalidate_result must be a cheap deterministic check that the task is actually finished (tests pass, the record exists, the JSON matches), and spent is shared across every rung. Without a validator, the ladder just launders failures upward.
Cost per successful task: where the flagship wins
Cost per successful task = cost per run ÷ success rate, plus the escalation or retry cost when the run fails. A worked example with illustrative success rates (replace them with your own eval numbers):
| Strategy | Run cost | Assumed success | Cost per successful task |
|---|---|---|---|
| DeepSeek V4 Flash alone | $0.0089 | 45% | $0.020 |
| DeepSeek V4 Flash, escalate to Sonnet 5 | $0.0089 + 55% × $0.37 | 96% | $0.22 |
| Gemini 3.8 Flash, escalate to Sonnet 5 | $0.139 + 25% × $0.37 | 97% | $0.24 |
| Claude Sonnet 5 alone | $0.370 | 92% | $0.40 |
Routing beats every single-model strategy on API spend. Three things push the flagship back into the lead. Failure cost: if a failed run needs a person to notice and rerun it, a 55% first-attempt failure rate costs more in minutes than the routing saved in dollars. Step count: a cheap model that takes 30 steps ($0.293 on Gemini 3.5 Flash Lite) to do what Sonnet 5 does in 12 ($0.37) has thrown away its advantage. Side effects: when a wrong tool call sends an email or writes to production, the validator cannot undo it.
When to pay for the flagship: as the planner in a multi-agent system, on any step with irreversible side effects, and whenever a failed run costs more than about $0.50 in someone's time. When not to: on the routine majority of steps, where Tier B at $0.14 with strict schemas is the right default.
How to cap spend, whichever model you pick
Every agent loop needs four limits regardless of model:
max_tokensper call of 1,000 to 4,000 for tool-calling turns.- A hard step cap, 12 to 15 for most task types, in your loop or via the SDK's turn limit.
- Stop conditions: a required finish tool, an abort on repeated identical tool calls, and an abort on two consecutive tool errors.
- A per-run USD budget computed from the usage object after every call, shared across escalation rungs as in the snippet above.
Sensible per-run ceilings: about $0.10 for a Tier C loop, $0.30 for Tier B, $1.00 for Tier A, and $2.00 for a run allowed to escalate all the way. The AI cost calculator converts a monthly run count into a budget line, and the Claude agent API cost, OpenAI Agents SDK cost and Gemini agent API cost guides cover vendor-specific caps and caching syntax.
Verdict
Cheapest model that runs an agent at all: DeepSeek V4 Flash at $0.009 per 12-step run. Cheapest we would run unattended with strict schemas: Gemini 3.8 Flash or GPT-5.4 mini at about $0.14, Claude Haiku 4.5 at $0.185 on Anthropic. Who should pay flagship rates on every step: teams whose tool calls have side effects or whose failures cost real time. Who should not: anyone with a validator and a routine task mix. Cheapest way to get the result: caching first, Tier B by default, a Tier C first attempt behind a validator, and a shared per-run budget.
Key Takeaways
- →On a 12-step reference run DeepSeek V4 Flash costs $0.009, GPT-5.4 nano $0.038, Gemini 3.8 Flash $0.139, GPT-5.4 mini $0.141, Claude Sonnet 5 $0.370, GPT-5.4 $0.471 and GPT-5.5 $0.942
- →Run cost = 166,800 input tokens × input rate + 3,600 output tokens × output rate; input is 90% or more on every model, so the ranking follows the input price
- →Gemini 3.8 Flash and GPT-5.4 mini at about $0.14 are the cheapest models that follow tool schemas reliably enough to run unattended with strict schemas
- →Below $0.10 per run a model needs a validator and an escalation path; route cheap, validate, escalate to Sonnet 5 or GPT-5.4 on failure
- →Cost per successful task = run cost ÷ success rate plus escalation cost; the flagship wins when failures cost time, tool calls have side effects, or the cheap model's step count blows out
- →Caching (roughly 10% of list input on Anthropic and OpenAI, 25% on Gemini) narrows the tiers but does not reorder them
Editorial context
Who is this for?
Developers and technical buyers choosing a model for a tool-calling agent on cost, and platform teams designing a model-routing ladder.
When NOT to use this
Chat users picking a subscription; teams with a single-vendor mandate who should read that vendor's agent cost guide instead.
Pricing insights
The 30-model spread on the same 12-step run is 106× ($0.009 to $0.94), but only models at about $0.14 and above follow tool schemas reliably enough to run unattended, so the real choice is between a $0.14 Tier B default and a $0.37 to $0.47 flagship for the hard minority.
Alternatives to consider
Gemini 3.8 Flash, GPT-5.4 mini or Claude Haiku 4.5 as the default; DeepSeek V4 Flash or GPT-5.4 nano as a first attempt behind a validator; Claude Sonnet 5, Gemini 3.1 Pro or GPT-5.4 as the escalation model.
Final verdict
Route cheap, validate, escalate. Cache first, default to a Tier B model at about $0.14 per run, put a Tier C model in front only if your validator is trustworthy, and pay flagship rates only for planning, side effects and tasks where failure costs time.
Frequently Asked Questions
What is the cheapest LLM for AI agents?
DeepSeek V4 Flash at $0.05 in / $0.16 out per 1M tokens, about $0.009 for a 12-step tool-calling run, provided you add strict schemas, a validator and an escalation path. The cheapest model we would run unattended is Gemini 3.8 Flash or GPT-5.4 mini at about $0.14 per run.
What is the cheapest model for tool calling that is actually reliable?
Gemini 3.8 Flash ($0.75 / $3.75 per 1M) and GPT-5.4 mini ($0.75 / $4.50) at about $0.14 per 12-step run, and Claude Haiku 4.5 ($1 / $5) at $0.185 on Anthropic. With strict tool schemas and a validator all three follow schemas consistently on routine tasks. Run your own eval on your own schemas first.
Is a cheap model always cheaper per completed task?
No. Cost per successful task is run cost divided by success rate plus escalation cost. DeepSeek V4 Flash with Sonnet 5 as fallback costs about $0.22 per success against $0.40 for Sonnet 5 alone, but if a failed run costs a person time or a wrong tool call has side effects, the flagship is cheaper in total.
What is the route-cheap-escalate-on-failure pattern?
Try the task on a cheap model first, validate the tool calls and the final result with a deterministic check, and rerun on a flagship only when validation fails. Keep one dollar budget across all attempts so escalation cannot run unbounded.
Does prompt caching change which model is cheapest for agents?
It narrows the gaps without reordering the tiers. Cache reads at roughly 10% of list on Anthropic and OpenAI bring Claude Sonnet 5 from $0.37 to about $0.12 per run and GPT-5.4 mini from $0.14 to about $0.045; Gemini's roughly 25% takes 3.8 Flash from $0.14 to about $0.06.
Related
Free courses · no sign-up
Still deciding? Learn the basics first, then come back to the prices.