The bill for a coding agent rarely comes from one expensive call. It builds up: every turn resends the conversation, tool output piles up, the cache misses, a few retries run, and a couple of subagents spin up along the way. By the end of the month, the total is hard to trace back to anything specific. To reduce LLM API cost, start by breaking the bill into its parts.
Do not start with the lowest unit price on the price list. Start with the structure of the bill. Four token prices, context, caching, batch jobs, and a little monitoring will explain most of the total. The shortest answer: read the four token prices, tier your models, control context and caching, batch what can wait, and monitor the bill. Prices are from official pricing pages as of November 15, 2026.
1. Read the LLM API price sheet: four prices, not two
A token is the small unit of text a model reads and writes. For token-billed models, the price sheet has at least four columns:
| Tier | Input | Output | Cache read | Cache write |
|---|---|---|---|---|
| Flagship | $8 | $40 | $0.20 | $10 |
| Mid | $2 | $10 | $0.10 | $2.50 |
| Light | $0.10 | $0.50 | $0.01 | $0.125 |
All figures are in US dollars per million tokens (MTok), from Anthropic's official pricing page as of November 15, 2026. The light-tier figures apply to prompts up to 100K tokens; above that, the page lists higher prices.
Three numbers explain most of the bill. On the pages cited here, output costs 4–5x input: 5x on Anthropic's page, 4x for DeepSeek's flash model. Cache reads cost 5% of input at the mid tier. Cache writes cost 1.25x input, so caching is not free; you pay more to write the cache and less to read it later.
That explains why the same conversation can cost very different amounts on the first send and the second send. It also explains why changing the system prompt, switching models, or coming back after a long break can push the next request back to full input pricing.
There are three more things to check on a price sheet: peak/off-peak pricing, batch discounts, and per-use charges. DeepSeek's pricing page says off-peak rates are half of peak rates; peak hours are 01:00–04:00 and 06:00–10:00 UTC, Monday through Friday, excluding Chinese public holidays. Anthropic's page says batch processing saves 50%. Kimi's pricing page says batch inference costs 60% of the standard price.
Per-use charges sit outside token pricing. On DeepSeek's page, web search is $0.75 per 1,000 searches, file parsing is $0.225 per 1,000 pages, and speech-to-text is $0.116 per hour. Anthropic charges $10 per 1,000 web searches. A coding agent that loops through searches or parses a stack of PDFs can run up these charges while its token bill still looks modest.
If you buy through a relay or aggregator, the sheet may show a discount instead of list price. Ask three questions before comparing: which list price the discount applies to, whether cache and output prices are discounted too, and whether there is a minimum spend. See this article on relay pricing for a breakdown of how to read those sheets.
2. Tier your models to reduce LLM API cost
Model choice is the first lever. On Anthropic's pricing page, the flagship tier is $8 input and $40 output per MTok; the light tier is $0.10 input and $0.50 output. Using the light-tier price for prompts up to 100K tokens, that is an 80x difference on both input and output. You do not need the flagship model for every task.
Claude Code's official docs make the same point: use the mid-tier model for most coding work, and reserve the flagship for complex architectural decisions or multi-step reasoning. Simple subagent tasks can run on a smaller model.
A practical split:
- Planning, architecture, hard debugging, cross-module refactors: flagship.
- Day-to-day coding, tests, bug fixes, code review: mid-tier.
- Batch classification, format conversion, log summaries, commit messages, simple lookup: light tier or a batch endpoint.
- Subagents: assign a model per task instead of letting every subagent inherit the main session's flagship.
A lower unit price is not automatically a lower total cost. It may take more turns, read more files, or produce a diff that needs rework. Measure total cost, not just the per-million-token price. A safer pattern is small-to-large: let the light model filter, extract, or classify, then send the hard cases to the mid-tier or flagship. Give each step a verifiable output, such as a test, a type check, or a diff.
For a task-by-task model selection framework, see Best LLM for Coding: Choose by Task.
3. Treat context as a budget
Context is the second bill, and a part of LLM API cost that is easy to miss. A coding agent resends the full conversation on every turn, including files it has read, commands it has run, and tool output it has received. Claude Code's docs put it plainly: a one-line question in a session that has been open all day still draws usage for the whole conversation.
That is why reducing LLM API cost is a context problem as much as a unit-price problem.
Six habits usually pay off:
- Run
/clearwhen you switch tasks. Unrelated work should not stay in the same session. Clearing drops the old context, so the next turn does not pay for it. If you want the session back later, run/renamefirst and/resumeafterwards. - Run
/compactat a natural break. Let the agent summarize the conversation instead of waiting for auto-compaction to fire in the middle of a task. You can tell it what to preserve, for example code samples and API usage. Note that compaction is itself a large request. It is cheaper while the cache is warm; after a long break, the summary request has to reprocess the history as uncached input. - Keep
CLAUDE.mdunder 200 lines. The official guidance is to include only essentials. Move project-specific workflows, checklists, and domain knowledge into skills that load on demand instead of stuffing them into every session's context. - Disable MCP servers you are not using. MCP is a protocol for connecting an agent to external tools; each server can add tool definitions and instructions. The docs recommend using an existing CLI tool when one is available, checking
/contextto see what is taking up space, and disabling unused servers. - Filter verbose output with hooks. A hook is a small script that runs before or after a tool call. The official example trims test output to the last 100 lines, cutting a log from tens of thousands of tokens to hundreds. Build logs and test reports are good candidates.
- Send verbose work to subagents. Running tests, fetching docs, and analyzing logs can produce a lot of output. Do it in a subagent and bring only the summary back to the main conversation. The subagent's requests still count, so give it a smaller model and keep each task self-contained.
Then there is prompt caching. Prompt caching means the provider stores a repeated request prefix and bills the next hit at the cached rate. The match is exact: change one thing in the prefix and everything after it is recomputed.
A few practical details:
- Cache reads are cheap; cache writes are not. On Anthropic's page, the mid tier charges $0.10 per MTok for cache reads, $2.50 for cache writes, and $2 for ordinary input. Do not change the prefix just to "turn on caching"; you will pay the write price again. Caching usually pays off when the same prefix is read repeatedly; the waste comes from changing it constantly. Kimi's page says K3 models bill cache writes separately by TTL, and a cache hit does not repeat the write charge.
- The common TTL is five minutes; a one-hour option exists. Kimi's page says the default TTL is five minutes. Claude Code's docs say the one-hour TTL charges a higher cache-write rate and helps when you leave a session idle. For short bursts of work, the five-minute window is usually enough.
- Model switches, tool-set changes, system-prompt changes, and long breaks can invalidate the cache. Settle these settings at the start of a task instead of changing them mid-task.
- Subagents have their own context and cache. A subagent's first request does not read the main conversation's cache, so do not assume a warm main session makes subagents cheap.
- Editing
CLAUDE.mdmid-session neither applies nor invalidates the current cache. The new content loads on the next/clear,/compact, or restart. - Agent teams are expensive. The docs say agent teams use roughly 7x more tokens than standard sessions when teammates run in plan mode, because each teammate keeps its own context window. Do not spin up a team for a small task.
The official docs include a sample /usage output with 91% of input tokens served from cache. That is a documentation example, not your data, but it shows how much the bill structure can change when the hit rate is high. Check the Prompt cache (main) line in your own /usage output for the hit rate and miss count.
4. Batch and off-peak: reduce LLM API cost on non-urgent work
If a job can wait, do not pay the interactive price. Batch endpoints are built for work that can wait: you send a batch, then collect the results later. Anthropic's page says batch processing saves 50%. Kimi's page says batch inference costs 60% of the standard price.
Good batch candidates: mechanical refactors across a repository, migrations, documentation generation, test generation, log analysis, and codebase scans. Bad candidates: interactive debugging, autocomplete where you need the result now, and pair-programming sessions.
Off-peak pricing is another form of batching. DeepSeek's page says off-peak rates are half of peak rates, and lists peak hours as 01:00–04:00 and 06:00–10:00 UTC, Monday through Friday, excluding Chinese public holidays. Schedule nightly scans, periodic jobs, and batch generation outside those windows.
Batch work is not free. Results need validation, and failures need reruns. Saving 50% on a job that needs an extra round of rework can be a wash. Cut the work into verifiable pieces before queuing it.
5. Token billing vs per-use billing: where LLM API cost hides
Model usage and tool usage are separate line items.
Token billing covers input, output, cache reads, and cache writes. You pay for the tokens actually processed. It fits conversation, code generation, and reasoning.
Per-use billing covers web search, web fetch, file parsing and OCR, text-to-speech, and speech-to-text. These are billed per search, page, character, or hour. On DeepSeek's page, search is $0.75 per 1,000 searches, web fetch is $0.75 per 1,000 fetches, file parsing is $0.225 per 1,000 pages, TTS is $0.45 per 10,000 characters, and ASR is $0.116 per hour. Anthropic charges $10 per 1,000 web searches.
Watch two places in particular: search and file parsing. An agent that searches the web and parses PDFs while debugging can stay well under its token budget and still blow past its per-use budget. Track search calls and parsed pages alongside tokens.
There is also the subscription-vs-API distinction. Anthropic's pricing page says Claude Code is included in paid plans and shares usage limits with chat; heavy sessions can switch to pay-as-you-go API credits. The Codex CLI repository says you can sign in with a subscription account or use an API key, and the API-key path needs additional setup. Neither option is universally cheaper. A subscription gives you a fixed monthly price; API billing tracks usage. Which is cheaper depends on your active days, token volume, and task mix. Run the numbers on your own usage instead of copying someone else's conclusion.
6. Estimate your monthly LLM API cost
Collect three inputs:
- Active developers and active days per month.
- Tokens per developer per day: uncached input, cache write, cache read, and output. The Session block in
/usagegives you the current session; team usage can come from the provider dashboard, gateway logs, or OpenTelemetry. - Today's prices: the four token prices, plus peak/off-peak, batch, and per-use rates.
The formula is straightforward:
Monthly bill (estimate) ≈ input tokens × input price + cache-write tokens × cache-write price + cache-read tokens × cache-read price + output tokens × output price + per-use charges.
Prices are per million tokens, so divide token counts by 1,000,000 first. This formula does not include taxes, minimum spend, or subscription fees; add those separately.
Here is an example with explicit assumptions. A team of five, each working 20 active days a month. Per developer-day: 4M input tokens, 0.2M cache-write tokens, 8M cache-read tokens, and 0.1M output tokens. Use the mid-tier prices from Anthropic's page on November 15, 2026: $2 input, $2.50 cache write, $0.10 cache read, $10 output, per MTok.
| Item | Usage per developer-day | Price | Cost |
|---|---|---|---|
| Input | 4.0M | $2.00 | $8.00 |
| Cache write | 0.2M | $2.50 | $0.50 |
| Cache read | 8.0M | $0.10 | $0.80 |
| Output | 0.1M | $10.00 | $1.00 |
| Total | $10.30 |
Five developers × 20 days = 100 developer-days, or about $1,030 a month. The same usage on the flagship tier ($8 / $10 / $0.20 / $40) comes to $39.60 per developer-day, or about $3,960 a month. That is nearly 4x. These are assumptions, not a forecast for your team; replace them with your own /usage numbers.
Use the official anchor as a cross-check. Claude Code's docs say enterprise deployments average around $13 per developer per active day and $150–250 per developer per month, with 90% of users below $30 per active day. If your estimate is an order of magnitude higher, look at four things first: long sessions, cache misses, subagents or agent teams, and per-use search calls.
Do not wait until the end of the month to check. /usage shows token usage and a local cost estimate for the current session. The Prompt cache (main) line shows the hit rate and misses. /context shows what is filling the context window. For a team, set workspace budgets in the provider console or export OpenTelemetry metrics (a standard way to export usage and cost data). Review four numbers every week: the most expensive session, the cache hit rate, the model mix, and the number of per-use calls.
7. A 7-day and 30-day checklist
Today
- Run
/usageand find the most expensive session. Decide whether it was long context, a cache miss, or the wrong model. - Copy the four prices for your main tier from the official page into the formula above.
This week
- Make the mid-tier model your default. Use the flagship only for planning and hard problems.
- Cut
CLAUDE.mdto 200 lines or less and move project-specific workflows into skills. - Run
/clearwhen you switch tasks; run/compactat a natural break. - Disable unused MCP servers and add a hook that trims test output.
This month
- Move batch work to a Batch API and schedule what you can into off-peak hours.
- Set a workspace budget and review it weekly.
- Recalculate the monthly bill with real usage and compare it with the official anchor.
Every action maps to a line on the bill: model tiering lowers the unit price, context and caching lower input volume, batch and off-peak lower the unit price, and monitoring catches runaway loops. That is how you reduce LLM API cost for coding agents without guessing.
If you are new to Claude Code, start with Claude Code Tutorial: From Install to Your First Code Change.
FAQ
Does a cheaper model write worse code?
Sometimes. Rework, retries, and misread files all add to the total. Use a cheaper model for bounded, verifiable work such as classification, format conversion, log summaries, and test generation. Keep architecture and multi-step reasoning on the flagship. Add a verification step before the output reaches the main branch.
Is caching automatic?
Claude Code manages prompt caching automatically, but a hit depends on an exact prefix match. Model switches, tool-set changes, system-prompt changes, and long breaks can invalidate the cache. Check the Prompt cache (main) line in /usage; if cache writes stay high, the prefix is changing.
What is a Batch API good for?
Jobs that can wait: batch refactors, migrations, documentation generation, test generation, and log analysis. It is a poor fit for interactive debugging or anything that needs an immediate result. Leave time for validation and reruns.
Is a subscription cheaper than API billing?
There is no universal answer. Claude Code is included in paid plans and shares usage limits with chat; heavy sessions can switch to API credits. Codex CLI supports subscription sign-in and API keys. Compare on your active days, daily token volume, and task mix, not just the monthly plan price.
Why is my bill higher than the unit price suggests?
Common causes: output tokens have a higher unit price than input, cache writes get ignored, thinking tokens are billed as output, subagents and agent teams each add usage, web search and file parsing are billed per use, retries send another request and add to the call count, and long sessions resend the whole conversation every turn. Match each item against /usage and the provider bill; start with the largest line item.
Sources
- Anthropic official pricing, fetched November 15, 2026.
- DeepSeek official pricing, fetched November 15, 2026.
- Kimi official pricing, fetched November 15, 2026.
- Claude Code cost management docs and prompt caching docs, fetched November 15, 2026.
- Codex CLI official repository, fetched November 15, 2026.
Prices and rules change; use the current official pages when you make a decision.