contenox

AI coding costs: why agents burn tokens and how to cut it

Updated

MODELS AND COST AI coding costs

AI coding costs come mostly from what the agent reads, not from the code it writes. One prompt from you turns into dozens or hundreds of requests to the model, and every request sends the whole conversation again: the instructions, the tool definitions, every file the agent opened, every test log. A coding session of eight prompts can send 300 million input tokens. Whether that costs one dollar or eighty depends on the model and on prompt caching.

Why does one session use so many tokens?

There are two kinds of “turn”, and the bill counts the second:

  • Your prompts. “Fix the failing checkout test.” You might type eight in a session.
  • Model requests. To answer one prompt, the agent reads files, searches, runs tests, edits and runs the tests again. Every one of those steps is a separate request, and each sends everything so far. One prompt easily becomes 50 to 150 requests.

The context grows with every step. With models that read up to a million tokens, a working session sits at hundreds of thousands of tokens per request. The arithmetic adds up fast:

8 prompts × 100 requests × 350,000 tokens per request ≈ 280 million input tokens

Our own numbers, from one month of DeepSeek API use: 23,815 requests and 7.86 billion tokens, about 330,000 tokens per request on average.

What this costs, measured in our own work in 2026, with prompt caching and the other habits below in place:

ModelWhat it cost us
Claude Fable 5.1Around $80 per coding session
Gemini on Vertex AI$8 to $20 per developer per working day
DeepSeek V4 Flash (now V4.1 Flash)Under $1 per coding session

The same kind of session, about two orders of magnitude apart between the top and the bottom row. DeepSeek has since replaced V4 Flash with V4.1 Flash in the same price class. The ratio is the point: the model you pick for routine work decides the bill more than anything else.

Without prompt caching, all of these would be far higher. Most of those hundreds of millions of tokens are the same conversation start, sent again and again, and a cache bills them at a fraction of the normal input price.

What actually drives the bill?

Roughly in order of impact:

  1. The model. As the table shows, the same work can cost a hundred times more on a top model than on a small one.
  2. Cache misses. Providers bill a repeated start of the conversation at a fraction of the normal price when it comes from their cache. Edit an early part of the conversation, or step away longer than the cache lasts, and the next request pays full price for everything.
  3. Number of requests. A vague task leads to exploring, guessing and retrying, and every step resends the whole context.
  4. Big tool results. A full test log or a large JSON response stays in the conversation for every later request.
  5. Fixed overhead. The system prompt, tool definitions and your project instructions (AGENTS.md or CLAUDE.md) ride along on every request.
  6. Thinking. Reasoning tokens are billed as output, even when you only see a summary.

A long session is also worse for quality, not only cost. Anthropic’s docs call it “context rot”: as the context grows, accuracy and recall drop.

How do I cut AI coding costs?

Start a new session for each new task. Old context costs money on every request and helps nothing. In Claude Code, /clear; in Codex, /new.

Compact long sessions you want to keep. /compact in Claude Code and Codex summarizes the conversation so far. It is itself one large request, so use it when you will keep working, not as a habit.

Write a tighter task. Name the file, the expected behavior and how to check it. “Add input validation to login() in auth.ts; npm test -- auth must pass” takes far fewer requests than “improve the login code”. See how to write good tasks for coding agents.

Keep tool output small. Run the one test file you care about, not the whole suite, and cut long logs down:

npm test -- auth
go test ./internal/auth/...
pytest tests/test_auth.py -x 2>&1 | tail -40

Keep your instructions file short. AGENTS.md is loaded every session. Put the commands and rules there, not the history of the project. See AGENTS.md explained.

Turn off MCP servers you are not using. Their tool names and descriptions take space in the context. Claude Code loads full definitions only when a tool is used, but each server still adds to the baseline. If the agent can run a CLI such as gh instead, that is often cheaper. See What is MCP?

Match the model and thinking level to the task. Use the strong model for planning and hard bugs, and a cheaper model or lower reasoning setting for renames, tests and boilerplate. /model switches in both Claude Code and Codex; Claude Code also has /effort.

Stop early when it goes wrong. Interrupt the agent as soon as it heads the wrong way (Escape in Claude Code). Ten wasted requests at 300,000 tokens each cost more than a fresh start.

How do I see what a session cost?

  • Claude Code: /usage shows token use for the session, including cache reads and writes, and on subscription plans a breakdown of what used your limits. /context shows what is filling the context.
  • Codex: /status shows the current token usage.
  • API keys: the provider’s console shows spend per day and per model. Set a monthly spend limit there before you start.

Subscription, API key or your own model?

SubscriptionAPI keyRun the model yourself
You payA flat monthly feePer tokenHardware you own, or GPU hours you rent
When you hit the limitYou wait for the window to reset, or buy moreYour own spend limit stops youYour GPUs are busy; requests queue until you add capacity
ModelsThat provider’sAny provider you sign up forOpen-weight models
Where your code goesThe providerThe providerYour machine, or the GPUs you rent

A subscription suits daily use. The bill is fixed, and long tasks cost the same as short ones until you reach the plan’s limits. Those limits usually reset over a window of a few hours, with a weekly cap on top (Claude’s Ultra plan drops the short window for verified accounts and keeps the weekly one), and agent work uses them far faster than chat. Codex is included in several ChatGPT plans; Claude Code in Claude’s paid plans. Check the current plan pages for what each includes, or see the AI coding subscription comparison.

An API key suits uneven use, automation, and mixing models from several providers. You pay exactly for what you use, which is great for light weeks and painful for a runaway session. Aggregators such as OpenRouter let one key reach many providers.

Running the model yourself suits private code and steady, heavy use. On your own computer, every token is free once you own the hardware. On rented GPUs, you pay by the hour, so it gets cheaper the busier you keep them; a team sharing one vLLM server can come out well ahead of per-token prices. Either way, open-weight models are still weaker than the top hosted ones at long agent tasks. See how to run local LLMs for coding.

Can I use my subscription in another tool?

It depends on the provider:

  • ChatGPT: OpenAI offers “Sign in with ChatGPT”, so Codex, OpenCode and Contenox can run on your plan.
  • Claude: the plan works in Claude Code, also when another app runs Claude Code for you, as Contenox does. Anthropic forbids other tools from signing in to your plan directly. Max, Ultra and Team plans also include monthly API credits for an Anthropic API key in other agents; they don’t cover Claude Code itself. See Anthropic.
  • GitHub Copilot: OpenCode signs in with it; Contenox only as an unofficial sign-in you enable. See GitHub Copilot subscription.
  • Google AI Pro and Ultra: include monthly Google Cloud credits through the Google Developer Program premium benefit, which you apply to a Cloud billing account.

Check the provider’s current terms before you build your workflow on it.

Credits you may already have

Before you pay per token, check what is already covered:

  • Claude Max, Ultra and Team: monthly API credits, claimed by linking a Claude Console organization. They pay for API keys, not for Claude Code, and don’t roll over. See Anthropic.
  • Google AI Pro and Ultra: monthly Google Cloud credits through the Google Developer Program premium benefit. You choose the billing account they go to on the program’s benefits page.
  • Startups: AWS Activate credits cover Amazon Bedrock, and the Google for Startups Cloud Program gives Google Cloud credits, which Vertex AI bills against. For a young company, they can cover a large share of model costs while they last. Check whether partner models, such as Claude on Vertex AI, count.

The fine-print trap: credits are often tied to specific products. Google’s “Trial credit for GenAI App Builder”, for example, is meant for its search services, not for Gemini API calls from your agent. Look at each credit’s scope on the billing account’s credits page before you count on it. See GenAI app builders.

How do I estimate before I commit?

  1. Pick three tasks you do often: a bug fix, a small feature, a test.
  2. Run each once on a pay-per-token key, with the provider’s usage page open.
  3. Write down input, cached input and output tokens for each.
  4. Multiply by how often you do that kind of task in a month.
  5. Compare with the subscription plans, and with what it would cost to run an open model yourself, on your own hardware or on rented GPUs.

Your own numbers beat any calculator, because your codebase and habits decide the request count.

When cutting costs is the wrong goal

An agent that saves you an hour is cheap at almost any token price. Downgrading to a model that fails twice before it succeeds costs more, in tokens and in your time. Cut waste first (stale sessions, huge logs, vague tasks). Downgrade the model only for work where the cheaper one already succeeds.

Related

Esc to close