Best LLM API for Coding Tasks
Anthropic's Claude API is the strongest default for coding tasks: Claude Sonnet 5 at $2/MTok input and $10/MTok output, with prompt caching at 0.1x input price and a full 1M token context window at standard rates. DeepSeek is the cheapest option if off-peak scheduling fits your workflow.
| Tool | Entry plan | Paid from | Notes | Verified |
|---|---|---|---|---|
| Anthropic API | — | $1/MTok input (Claude Haiku 4.5) | Output $5 per MTok; cache hits $0.10 per MTok; batch $0.50 in / $2.50 out | 2026-08-28 |
| Google Gemini API | Free — Free tier | $0.3/MTok input (Gemini 3.5 Flash-Lite) | Output $2.50 per MTok | 2026-08-28 |
| OpenRouter | Free — Inference | — | OpenRouter passes through provider pricing without markup on API usage | 2026-08-28 |
| DeepSeek | — | $0.44/MTok input (cache miss, peak) (deepseek-v4-flash) | Off-peak $0.22 per MTok. Cache hit $0.014 peak / $0.007 off-peak. Output $1.32 peak / $0.66 off-peak | 2026-08-28 |
Pricing verified: 2026-08-28 — fromAnthropic APIGoogle Gemini APIOpenRouterDeepSeek
How we picked
We picked based on verified per-token pricing, context window handling, and caching behavior — the three things that matter most for a coding agent that resends large context (files, diffs, system prompts) on nearly every call. We checked each vendor's own pricing page directly rather than relying on secondhand price comparisons, since API pricing in this category shifts often.
Four providers made the cut because we have verified pricing for all four: Anthropic's Claude API, Google's Gemini API, OpenRouter as a pass-through router, and DeepSeek as a low-cost specialist. Each serves a different priority — capability, a free tier, provider flexibility, or raw cost — so the right pick depends on which trade-off matters most for your workload.
The shortlist
Coding work is context-heavy, so caching and context-window pricing matter as much as the headline per-token rate. Here's how the four compare on the numbers that actually move a real bill.
| Provider | Input (standard) | Output (standard) | Free/cheap option | Caching |
|---|---|---|---|---|
| Anthropic API | Sonnet 5: $2/MTok | Sonnet 5: $10/MTok | Small free credit for new accounts | Cache hits at 0.1x input price |
| Gemini API | Flash-Lite: $0.30/MTok | Flash-Lite: $2.50/MTok | Free tier with limited models | Not detailed in fact sheet |
| OpenRouter | Pass-through, no markup | Pass-through, no markup | Free models, 50 req/day | Depends on underlying provider |
| DeepSeek | v4-flash: $0.44/MTok peak, $0.22 off-peak | v4-flash: $1.32 peak, $0.66 off-peak | Off-peak scheduling halves cost | Cache hits ~30x cheaper than misses |
Anthropic's Claude API prices Opus 5 at $5/MTok input and $25/MTok output, Sonnet 5 at $2/MTok input and $10/MTok output, and Haiku 4.5 at $1/MTok input and $5/MTok output. Prompt caching is the standout feature for coding: cache reads cost 0.1x the base input price, a 5-minute cache write costs 1.25x base input, and a 1-hour write costs 2x — and caching stacks with the Batch API's 50% discount on both input and output tokens for asynchronous work. Claude 4.6 and later models include the full 1M token context window at standard pricing with no long-context surcharge, which matters for large codebases. The trade-off: there's no permanent free tier, only a small credit grant for new accounts, and output tokens cost five times input on every model, so generation-heavy workloads add up.
Google's Gemini API is the only one of the four with a genuinely free tier you can build against long-term rather than a one-off credit — limited model access, free input and output tokens, and bundled Google AI Studio access, though free tier content is used to improve Google's products. Paid pricing runs from Flash-Lite at $0.30/MTok input and $2.50/MTok output up to Flash at $1.50/MTok input and $9.00/MTok output; Gemini 2.5 Pro splits its rate at the 200k-token mark, running $1.25-$2.50/MTok input and $10-$15/MTok output depending on prompt length.
OpenRouter doesn't set its own inference price — it passes through whatever the underlying provider charges, with no markup on API usage. The cost instead shows up in how you fund the account: a 5.5% fee with an $0.80 minimum on Stripe card purchases, or 5% via crypto through Coinbase. Bring-your-own-key usage is free up to $25,000/month (enterprise: $200,000/month), then 5% above that threshold. Free models are rate-limited to 50 requests per day, rising to 1,000/day once you've purchased at least $10 in credits — a workable way to prototype a coding agent against multiple models through one API key before committing spend.
DeepSeek is the cost leader by a wide margin if your workload tolerates its scheduling. deepseek-v4-flash costs $0.44/MTok input at peak on a cache miss, dropping to $0.22 off-peak, with output at $1.32 peak / $0.66 off-peak. Cache hits are dramatically cheaper still — $0.014/MTok at peak, $0.007 off-peak — roughly 30x cheaper than a cache miss. Peak hours are defined as 01:00-04:00 and 06:00-10:00 UTC, Monday through Friday, so exploiting the off-peak discount means scheduling batch coding jobs outside those windows.
What to watch out for
The biggest trap is comparing headline input prices without accounting for output cost and caching behavior, since coding workloads are asymmetric in ways that change the real bill. Anthropic's output tokens cost five times input on every model, so a workload that generates a lot of code (rather than mostly reading it) will lean heavily on the output rate, not the cheaper input rate advertised up front. Claude 4.7 and later models also use a tokenizer that produces roughly 30% more tokens for the same text, which is worth factoring into any cost estimate built from an older model's token counts.
DeepSeek's headline cheapness comes with real scheduling friction: peak rates are double off-peak, defined strictly in UTC, so an unscheduled burst of coding-agent activity during peak hours costs twice what a planner might expect, and cost forecasting requires modeling both cache-hit rate and time of day rather than just token volume.
OpenRouter's no-markup promise is real for inference, but the funding fees are not nothing — a 5.5% Stripe fee with an $0.80 minimum makes small, frequent top-ups disproportionately expensive, so batching larger credit purchases is worth doing deliberately rather than topping up in small increments as you go.
Gemini's free tier is genuinely free to build against, but remember that content on it is used to improve Google's products — fine for a public open-source coding agent, not appropriate for anything touching confidential code or customer data. And Gemini's pricing varying by prompt length and input type makes it the hardest of the four to forecast from a flat per-token estimate; model the actual split between short and long prompts before committing budget. For deeper pricing math across all four providers, our LLM API cost calculator and cheapest LLM API roundup are worth running your specific workload through, and our Gemini API vs OpenAI API comparison covers one specific head-to-head in more depth.
Frequently asked questions
What is the best LLM API for coding tasks?
Anthropic's Claude API is a strong default: Claude Sonnet 5 costs $2 per million input tokens and $10 per million output tokens, with prompt caching at 0.1x the input price for reused context like system prompts and large files.
Which LLM API is cheapest for coding?
DeepSeek is the cheapest documented option here. deepseek-v4-flash costs $0.44 per million input tokens at peak, or $0.22 off-peak, with cache hits as low as $0.007 per million tokens off-peak.
Does prompt caching actually matter for coding agents?
Yes. Coding agents repeatedly resend large context like file trees and system prompts, so caching has an outsized effect. Anthropic's cache hits cost 0.1x the base input price, and DeepSeek's cache hits are roughly 30x cheaper than cache misses.
Is there a free way to test an LLM API for coding?
Google's Gemini API has a genuinely free tier with limited model access and free input/output tokens, though free tier content is used to improve Google's products. OpenRouter also offers free models rate-limited to 50 requests per day.
What's the catch with OpenRouter for coding work?
OpenRouter passes through provider pricing with no markup on inference, but buying credits with a card via Stripe costs a 5.5% fee with a $0.80 minimum, which is a real cost a direct provider account doesn't have.