Cheapest LLM for coding agents
A coding agent re-sends its whole history on every step, so its cost behaves very differently from a single API call. This ranks every model on one realistic agent run. Prices verified 2026-10-18.
Assumptions
- 12,000 tokens of system prompt and tool definitions, 2,000-token task
- 30 steps, each adding 1,000 output tokens (thinking included) and a 3,000-token tool result
- Prompt caching on: the previous prompt is read from cache, new tokens are written (cache-write premiums included where a provider charges one)
- 1,000 runs per month, standard (non-batch) pricing, no web search fees
Change any of these in the calculator: every row below has a link that opens the same scenario for that model.
The short answer
- Cheapest flagship model: Mistral Large 4 at $0.29 (temporary sale price; regular $1.36 / $4.18 per 1M)
- Cheapest mid-tier model: Gemini 3.8 Flash at $0.36 (price rises 2027-01-01)
- Cheapest small model: GPT-6 Luna at $0.05
The cheapest model overall is GPT-6 Luna at $0.05 per run; the most expensive is GPT-6 Astra at $5.16, a 100× spread for the same token counts.
What drives the cost
History, not the task. By the last step the prompt is 131,000 tokens, and the run bills 2,160,000 input tokens in total. That is why prompt caching matters so much here: across models with cache pricing it cuts the cost of this run by 68% to 87%.
Long-context tiers. The final steps cross the long-context threshold of Claude Haiku 5.5 (100K), so those requests are billed at the higher rate for the whole prompt.
Step count grows cost faster than linearly. Each extra step re-sends everything before it. Going from 30 to 45 steps:
- Mistral Large 4: $0.29 at 30 steps → $0.53 at 45 steps (1.81×)
- Gemini 3.8 Flash: $0.36 at 30 steps → $0.64 at 45 steps (1.77×)
A model that solves the task in fewer steps, or with fewer retries, can be cheaper per finished task even when its per-token price is higher. Measure steps per solved task on your own repository before switching on price alone.
Full ranking (36 models)
| # | Model | Tier | Per run (cached) | Per run (no cache) | Per month (1,000 runs) | |
|---|---|---|---|---|---|---|
| 1 | GPT-6 Luna OpenAI | small | $0.05 | $0.23 | $51.55 | Calculator |
| 2 | Ministral 3 8B Mistral AI | small | $0.05 | $0.33 | $54.45 | Calculator |
| 3 | Mistral Small 4 Mistral AI | small | $0.07 | $0.34 | $67.95 | Calculator |
| 4 | DeepSeek V4.1 Flash DeepSeek | small | $0.09 | $0.68 | $87.18 | Calculator |
| 5 | GPT-5.6 Luna OpenAI | small | $0.11 | $0.47 | $109 | Calculator |
| 6 | Claude Haiku 5.5 Anthropic | small | $0.12 | $0.62 | $119 | Calculator |
| 7 | Codestral Mistral AI | small | $0.13 | $0.67 | $127 | Calculator |
| 8 | Gemini 3.1 Flash-Lite Google | small | $0.13 | $0.59 | $128 | Calculator |
| 9 | Gemini 3.5 Flash-Lite Google | small | $0.17 | $0.72 | $175 | Calculator |
| 10 | Gemini 2.5 Flash Google | small | $0.17 | $0.72 | $175 | Calculator |
| 11 | Mistral Large 4 Mistral AI sale price | flagship | $0.29 | $1.53 | $293 | Calculator |
| 12 | Gemini 3.8 Flash Google price changes 2027-01-01 | mid | $0.36 | $1.73 | $362 | Calculator |
| 13 | Gemini 3.6 Flash Google price changes 2027-01-01 | mid | $0.36 | $1.73 | $362 | Calculator |
| 14 | DeepSeek V4 Pro DeepSeek | flagship | $0.38 | $2.97 | $380 | Calculator |
| 15 | GPT-5.4 mini OpenAI | small | $0.38 | $1.76 | $385 | Calculator |
| 16 | Claude Haiku 4.5 Anthropic | small | $0.52 | $2.31 | $516 | Calculator |
| 17 | Grok Build 0.1 xAI | small | $0.60 | $2.22 | $596 | Calculator |
| 18 | Grok 4.20 (Reasoning) xAI | reasoning | $0.64 | $2.77 | $644 | Calculator |
| 19 | Grok 4.3 xAI | mid | $0.64 | $2.77 | $644 | Calculator |
| 20 | Mistral Medium 3.5 Mistral AI | mid | $0.72 | $3.47 | $725 | Calculator |
| 21 | Gemini 4 Argon Google price changes 2026-12-01 | flagship | $0.76 | $4.62 | $763 | Calculator |
| 22 | Claude Sonnet 5.5 Anthropic | mid | $0.83 | $4.62 | $828 | Calculator |
| 23 | GPT-6.1 Sol OpenAI | mid | $0.83 | $4.62 | $828 | Calculator |
| 24 | Gemini 3.1 Pro (Preview) Google | flagship | $1.03 | $4.68 | $1,026 | Calculator |
| 25 | Claude Sonnet 5 Anthropic | mid | $1.03 | $4.62 | $1,031 | Calculator |
| 26 | GPT-6 Sol OpenAI | mid | $1.03 | $4.62 | $1,031 | Calculator |
| 27 | GPT-5.6 Terra OpenAI | mid | $1.09 | $4.68 | $1,091 | Calculator |
| 28 | Grok 4.7 xAI | flagship | $1.45 | $4.50 | $1,455 | Calculator |
| 29 | Claude Sonnet 4.6 Anthropic | mid | $1.55 | $6.93 | $1,547 | Calculator |
| 30 | Claude Opus 5.5 Anthropic | flagship | $1.66 | $9.24 | $1,656 | Calculator |
| 31 | GPT-5.6 Sol OpenAI | flagship | $2.06 | $9.24 | $2,062 | Calculator |
| 32 | GPT-5.5 OpenAI | flagship | $2.56 | $11.70 | $2,565 | Calculator |
| 33 | Claude Opus 5 Anthropic | flagship | $2.58 | $11.55 | $2,578 | Calculator |
| 34 | Claude Opus 4.8 Anthropic | flagship | $2.58 | $11.55 | $2,578 | Calculator |
| 35 | Claude Fable 5.1 Anthropic | flagship | $3.63 | $23.10 | $3,633 | Calculator |
| 36 | GPT-6 Astra OpenAI | flagship | $5.16 | $23.10 | $5,155 | Calculator |
USD, standard list prices. Tags mark announced price changes and temporary sale prices.
Price is not quality
This page ranks by cost only. Models differ in accuracy, instruction following, tool use, latency, rate limits and data policies, and those differences often matter more than the price gap. Shortlist two or three models from the table, run them on a sample of your real inputs, and compare cost per successful result.
Related comparisons
More guides
- Cheapest LLM for RAG chatbots
- Cheapest LLM for batch classification and extraction
- Long-context document analysis (400K tokens)
- Cheapest LLM for high-volume customer support
- Prompt caching explained, with savings
FAQ
What is the cheapest model for a coding agent?
On this workload (30 steps, caching on) it is GPT-6 Luna at $0.05 per run. The cheapest flagship model is Mistral Large 4 at $0.29. Cheapest is not the same as best: compare success rate on your own tasks.
How much does prompt caching save on an agent run?
Between 68% and 87% on this run, depending on the model's cached-input price.
Do thinking tokens count?
Yes. Providers bill thinking or reasoning tokens as output tokens. This guide assumes 1,000 output tokens per step including thinking; raise it in the calculator if your agent thinks longer.