AI Coding Token Costs Explained: A 24-Day, 52-Hour Breakdown
An analysis of real usage data from 24 days of AI-assisted coding shows that token costs are driven mainly by repeated context reads rather than model output. This article breaks down the four token categories, explains why a tiered model strategy controls spending, and offers five practical levers plus a team checklist for managing AI coding costs.
AI Coding Token Costs: A 24-Day, 52-Hour Breakdown
1. A Real Sample Worth Reviewing
Consider aggregated data from a real usage log: the usage cycle spanned just over 24 days, the AI’s cumulative model working time was about 52 hours, total tokens processed reached roughly 693 million, and the final bill was $505.21.
The most telling part of these numbers is not the total, but three structural facts:
- Calendar time and actual working time are badly mismatched: across 24 days, compute was consumed for only about 52 hours, roughly 9% of the span. AI coding is a process of humans and models taking turns—time spent thinking, writing code, and verifying far exceeds model working time.
- Total tokens are huge but extremely lopsided: about 611 million were cache reads, roughly 88% of the total.
- Cost is not dominated by “output” but by repeated reads of context.
Put together, these three points lead to the core conclusion of this article: in long-cycle, multi-turn AI coding, the deciding variable for cost is neither the model’s unit price nor how much code was generated, but how many times context was read again and again.
2. The Four Token Categories: Getting the Math Right First
To optimize cost, you first need a correct measurement model. The common industry approach breaks a single call into four token categories:
| Type | Usage in This Sample | Share | Meaning |
|---|---|---|---|
| Cache read | ~611 million | ~88.2% | Cache hit; re-reading existing content |
| Cache write | ~53.84 million | ~7.8% | Writing context to cache for the first time |
| New input | ~18.67 million | ~2.7% | Genuinely new questions and material this turn |
| Model output | ~9.52 million | ~1.4% | Code and text generated by the model |
This table reveals a counterintuitive fact: the genuinely “newly produced” information (new input + output) totals only about 28.19 million tokens, roughly 4% of the total. The remaining 96% is repeated shuttling of existing context.
The following illustrative pseudocode expresses this call structure:
# Every turn re-sends the full contextfor turn in turns:request = {"system_prompt": SYSTEM, # unchanged over the long term"history": all_previous_messages, # keeps accumulating"new_input": turn.user_message, # new this turn, a tiny share"cache": True # billed as a read on cache hit}call_model(request)
Inside the loop, only new_input actually changes, yet what gets billed repeatedly is history. The longer the context and the more turns there are, the larger the volume of repeated reads—which is exactly where the 611 million cache reads come from.
3. Why Cost Concentrates on the Main Model: Division of Labor, Not Stacking
The cost distribution in the sample was: $348.34 for the main general-purpose model, $84.40 for a lightweight model, and $72.47 for a high-capability model.
This distribution follows a mature engineering principle: route by task difficulty rather than sending every request to the strongest model.
- The main general-purpose model handles the bulk of coding and rewriting tasks and is the cost center, about 69% of the total. Its call volume and context length together set the billing baseline.
- The lightweight model handles auxiliary tasks such as retrieval, locating, batch reading, and formatting. Usage is not small but the unit price is low, accounting for only about 17% of the total. This is a typical “push high-frequency, low-value-density tasks down” strategy.
- The high-capability model is called only for complex reasoning, architecture decisions, and hard defect localization. It has the least usage yet accounts for about 14% of cost, showing that a small number of high-difficulty calls can significantly raise unit-price spending.
The scheduling logic can be abstracted as:
def route(task):if task.type in ("search", "read", "format", "summarize"):return light_model # high frequency, low difficultyif task.complexity >= 3 or task.risk == "high":return strong_model # low frequency, high difficultyreturn general_model # main model
It is worth stressing that tiered scheduling optimizes the cost structure rather than compromising capability. When auxiliary tasks are done by the lightweight model, the main model can reserve its context budget for the parts that genuinely need reasoning.
4. Five Levers to Bring Down Long-Cycle Costs
1. Control context size, not the number of turns
Since 88% of spending is cache reads, compressing the context carried per call pays off far more than reducing the number of questions. Concrete steps include: loading only the file fragments relevant to the current task, using retrieval to locate instead of scanning the whole repository, and summarizing long documents before putting them into context.
2. Improve cache hit rate
The unit prices of cache writes and reads usually differ markedly, so a stable context prefix is critical. Placing long-term-unchanged project conventions, directory descriptions, and coding standards at the front and keeping their order stable, while putting volatile content at the back, can significantly raise the hit rate.
[stable prefix] project standards + directory structure + interface conventions[semi-stable] design notes for the current module[volatile] new requirements and temporary material this turn
3. Task splitting and phasing
Break a large task spanning 24 days into small tasks with clear boundaries, each carrying only the necessary context, to avoid unlimited accumulation of history. The 52 hours of actual working time show the model is not the bottleneck; how tasks are organized is.
4. Establish usage observability
No measurement, no optimization. It is advisable to log and monitor call volume, the four-category token composition, model distribution, and per-task cost, and to set threshold alerts through logging and monitoring capabilities so you can step in promptly when costs grow abnormally.
5. Make output more “reusable”
Although output tokens are only 1.4%, rework amplifies both input and output at the same time. Requiring the model to produce structured, testable, incrementally modifiable results and reducing the “generate—overturn—regenerate” loop is a high-leverage move for lowering total cost.
5. A Cost Governance Checklist for Teams
- Measurement first: distinguish cache reads, cache writes, new input, and output before talking about optimization.
- Tiered scheduling: push high-frequency auxiliary tasks down to the lightweight model, and hand high-difficulty decisions to the high-capability model.
- Context budget: set an upper limit on context per task, and trigger retrieval and summarization once it is exceeded.
- Stable prefix: put fixed content in front to improve cache hits.
- Threshold alerts: use monitoring alerts to set daily and per-task cost caps.
- Review mechanism: compare the share of each token category week over week to identify sources of abnormal growth.
6. Conclusion
$505.21, 693 million tokens, and 52 hours together show that the cost of AI coding is not mysterious—it is highly explainable, attributable, and optimizable. When teams shift their attention from “how many times the model was used” to “how much context was read repeatedly,” cost governance turns from passive payment into active design. In general engineering practice on cloud platforms such as Baidu AI Cloud, combining measurement, logging, monitoring, and tiered model scheduling is the right way to make AI coding sustainable over the long term.
