What actually drives LLM cost?
LLM cost is driven by how many tokens you send, how many times you send them, and which tier of model reads them — in that order of impact. The published price per million tokens is the least interesting variable, because it's the one you can't change and the one everyone fixates on. The mistake I see most often is treating this like a utility bill: pick a cheaper provider, pay less. It doesn't work that way, because the same task can cost twenty times more or less on the same model depending on how the request is built. Two developers on identical plans, doing identical work, routinely see wildly different bills. The difference is almost never the tariff. I build token-reduction tooling, so I spend my weeks looking at where the money actually goes. What follows is the honest breakdown, in the order that matters.Why is input more expensive than output in practice?
Because output is small and input compounds. Per token, output costs more — typically five times input. In total, input usually dominates, because you send it again and again. A single chat exchange bills the input once. An agent doesn't work that way: it plans, calls a tool, reads the result, plans again — and on every one of those steps the model receives the entire conversation so far. A 6,000-token file read on turn two is still in the payload on turn twenty. You paid for it eighteen more times. That's the re-read multiplier, and it's the single most important thing to understand about agentic cost. It's why "ask the model to be brief" is such durable bad advice: brevity trims output, which is the small direction, while the input you keep re-sending goes untouched. Two consequences worth internalising:- A long session is not linearly more expensive than a short one. Cost grows with the accumulated context window, so a session that doubles in length more than doubles in price.
- Early waste is the most expensive waste. A file read at turn two is billed on every subsequent turn; the same read at turn nineteen is billed once.
Does prompt caching make this free?
No, but it changes the arithmetic significantly — a cache read runs at roughly 10% of a fresh input token, which is a real discount on the part of the bill that dominates. The catch is the condition. Prompt caching only applies to a prefix that is byte-identical between turns. Anything that changes the front of your payload invalidates everything after it. In practice that means:- A stable system prompt and a stable
CLAUDE.mdare worth real money — see how a bloated CLAUDE.md inflates your bill. - Editing project instructions mid-session defeats the cache and re-bills the whole prefix at full price.
- An append-and-grow transcript caches well at the front and poorly at the tail, which is where your newest, largest reads live.
Does switching to a cheaper model fix it?
It helps, and it's the lever most people reach for first because it's the easiest — but it treats the symptom. Model tiers differ by roughly an order of magnitude between the cheapest and the frontier. Routing routine work down a tier genuinely saves money, and most sessions have plenty of routine work: reformatting, mechanical edits, straightforward lookups. Where it goes wrong is using tier as a substitute for context hygiene. A wasteful session on a cheap model is still wasteful — you've divided a number you should have been reducing. The order I'd recommend: fix what you send first, then pick the tier. Doing it the other way round means you optimise a multiplier you'll later change anyway, and you never find out what the task actually needed. For the current per-model numbers, LLM API token pricing keeps the table, and AI coding agent token costs works through what real sessions come to. The LLM token cost calculator does the arithmetic on your own numbers.Which levers actually reduce the bill?
Four, in descending order of what they return on a typical coding session. None requires a model change or a cleverer prompt.- Retrieve instead of reading. Point the model at the symbol it needs rather than the file it lives in. Semantic code search returns a relevant fragment instead of six thousand tokens of file.
- Filter tool output. A failed test run can emit 15,000 tokens of which about fifty matter — the failing assertion and its location. Output filtering keeps the signal.
- Bound the session. One transcript per task. Unrelated work carried forward re-bills every early read for the rest of the day, which is the most common avoidable cost there is.
- Prune tool surface. Every connected MCP server advertises its schemas every turn, invoked or not. Disconnect what this session doesn't need.
How do you know what any of this is worth?
Measure before and after on the same task. Not on a benchmark, not on a vendor's number — on your work. The baseline takes two minutes: open a fresh session, look at what's occupying the context before you type anything (system prompt, project instructions, MCP schemas), and note it. That figure is your standing overhead on every turn of every session, and most people are surprised by it. Measuring agent token usage covers the cross-agent version. Then run a representative task and compare. Anyone selling you a reduction who can't show you that comparison — including us — is asking for faith. If you'd rather the levers applied themselves, Tokenade does the four above automatically inside Claude Code, Cursor, Codex, Copilot and Windsurf, and shows measured savings on a dashboard rather than a claim. It's source-available under MIT, so you can read what it does to your context first. The manual route works too, and if you'll actually keep it up, it costs nothing.What goes wrong (anti-patterns)
Shopping for a cheaper price per token. The tariff is the variable you don't control. The volume and the repetition are the ones you do. Optimising output length. It's the small direction, priced higher per token but sent once. Input is the large direction, priced lower and sent repeatedly. Treating a big context window as free capacity. A million-token window doesn't lower the price of what you put in it. It removes the constraint that used to keep you disciplined. Editing project instructions mid-session. Every edit breaks the cached prefix and re-bills it at full price for the rest of the session. Assuming a cheaper model fixes a context problem. It divides the bill; it doesn't diagnose it. The waste is still there, and it comes back the moment you need the frontier tier.Frequently asked questions
Why is my LLM bill higher than my usage feels?
Almost always the re-read multiplier. You think in prompts sent; you're billed on the full context re-sent every turn. A session that feels like twenty questions can be twenty increasingly expensive payloads, each containing everything before it.Is the API cheaper than a subscription?
It depends entirely on volume and on how efficient your sessions are. A subscription is a fixed price with a usage ceiling; the API is pay-per-token with no ceiling. Heavy, well-optimised use often favours the API; light or wasteful use usually favours the subscription. Claude Code subscription vs API works through the crossover.Does a longer context window cost more money?
Only through what you put in it. Vendors don't charge for headroom, and some apply premium pricing above a long-context threshold — check your provider. The real effect of a large window is behavioural: it removes the pressure that kept sessions tidy.What's the cheapest way to run an AI coding agent?
Short sessions, narrow reads, filtered command output and a lean tool surface — on whatever tier the task actually needs. That combination beats any single trick, including model choice, because it attacks the volume that every other factor multiplies.Do these levers work outside coding?
Yes, wherever a model reads a corpus it didn't memorise: document Q&A, support agents, research assistants. The specific techniques shift, but retrieval over dumping, filtering noisy output and pruning stale history are universal to anything with a context window and an invoice.See also:
- LLM API token pricing — the current per-model rates.
- AI coding agent token costs — what real sessions come to.
- How the context window drives your token bill — the arithmetic in depth.
- How to reduce AI coding agent token usage — the six levers, cross-agent.
- LLM token cost calculator — run your own numbers.
Ranked #1 on the Token-Harness Optimizer Leaderboard.
Tokenade ranks #1 in the Token-Harness Optimizer Leaderboard — an end-to-end benchmark of agent token optimizers measured on real coding sessions. Set it up once, it works on every prompt. Works with Claude Code, Cursor, Codex, Copilot & more.