AI Coding Token Cost Breakdown: 693M Tokens and $505 Across 52 Working Hours

    This article breaks down the real token and cost structure of a single AI coding session that spanned 24 calendar days but only about 52 hours of active model time, processing roughly 693 million tokens for $505.21. It shows why calendar duration is the wrong budgeting denominator, how cached reads account for 88.2% of all tokens while new input is only 2.7%, and how cost splits across a main, lightweight, and high-capability model. Five practical optimization layers are included: context budgeting, prefix stability for cache reuse, tiered task routing, retrieval instead of full-repo feeding, and session splitting with per-model accounting.

    1. The Bottom Line: Calendar Span Is Not Compute Consumption

    The complete bill for one AI coding session looks like this: a calendar span of just over 24 days, roughly 52 hours of cumulative time in which the model was actually working, about 693 million tokens processed, and a cost of $505.21.

    Put together, these three numbers invite the most common misreading: treating the 24 days as the cost period. In reality, the human only steps in when a decision, a review, or additional information is needed. The rest of the time the session sits idle and generates no calls at all. So cost is distributed in a highly bursty pattern, not as a flat daily rental. When budgeting, the denominator should be “model working hours,” not calendar days.

    Dividing $505.21 by 52 hours gives roughly $9.7 per working hour; dividing it by 693 million tokens gives roughly $0.73 per million tokens. The latter is a blended unit price. It collapses four very different token streams into a single number, which makes it useful only for rough estimates, not for optimization decisions.

    2. Token Structure: Ninety Percent Is Re-Reading, Not New Writing

    The actual scale and share of the four token types are roughly as follows:

    Type Scale Share Meaning
    Cached reads ~611 million 88.2% Repeatedly loading the already-cached context prefix
    Cache writes ~53.84 million 7.8% Writing the context into cache for the first time
    New input ~18.67 million 2.7% New user instructions and tool results for the current turn
    Model output ~9.52 million 1.4% Generated code, explanations, and plans

    This table overturns a common intuition: the cost driver in AI coding is not “generating code” but making the model see the entire project again on every turn. Cached read volume is 32 times the new input and 64 times the output.

    The reason lies in the turn structure of the session. Every turn resubmits the system prompt, project conventions, directory structure, files already read, conversation history, and tool return values. The model itself is stateless; what looks like “remembering” is just the prefix being recomputed or hitting the cache. The more turns and the longer the context, the more re-reading accumulates in a roughly linear fashion. 611 million cached reads within 52 hours works out to about 19.6 million tokens re-shuffled every minute.

    Cache writes of 53.84 million are nearly twice the 18.67 million of new input, which indicates the context prefix was rebuilt multiple times. This usually corresponds to three kinds of events: a change in prefix content that invalidated the cache, resuming after a session interruption, or switching models or configuration so the cache could no longer be reused.

    3. Cost Attribution: Three Model Classes, Three Roles

    The cost distribution is $348.34 for the main general-purpose model (68.9%), $84.40 for the lightweight model (16.7%), and $72.47 for the high-capability model (14.3%).

    The order by unit price does not match the order by cost, and that mismatch is exactly what exposes the division of labor:

    • The main model handles the vast majority of coding and refactoring turns. It is the largest contributor to cached reads and the absolute cost center.
    • The lightweight model has the lowest unit price yet spends $84.40, which means auxiliary tasks (retrieval and location, batch summarization, formatting cleanup, simple classification) are called extremely often. This is “high-frequency, low-value-density” consumption.
    • The high-capability model costs only $72.47, the smallest share, and is used for low-frequency, high-value judgment such as architecture trade-offs, diagnosing difficult defects, and generating key implementation approaches.

    A reusable rule of thumb: if the output of a certain class of call can be replaced by rules or a cheaper model, it should not occupy the main model’s context. A high share for the lightweight model often means task routing has not been tiered.

    4. Five Layers of Practical Optimization

    4.1 Put the Context on a Budget

    Set a token ceiling for each turn’s request, and when it is exceeded, evict historical content by “relevance to the current task” rather than appending endlessly. Illustrative logic:

    1. def build_context(items, budget):
    2. # items are already sorted by relevance, descending
    3. kept, used = [], 0
    4. for it in items:
    5. cost = estimate_tokens(it)
    6. if used + cost > budget:
    7. break
    8. kept.append(it)
    9. used += cost
    10. return kept, used

    4.2 Keep the Prefix Stable to Reuse the Cache

    Move volatile content (current time, temporary variables, debug output) to the end of the prompt, and pin stable content (conventions, directory layout, interface contracts) at the top. Once the prefix changes, the entire cache is invalidated and turns into an expensive cache write.

    4.3 Tiered Task Routing

    Send retrieval, location, and summarization to the lightweight model; implementation and refactoring to the main model; and solution arbitration to the high-capability model. Routing rules should be configured explicitly rather than left to default behavior.

    4.4 Use Retrieval Instead of Full-Context Feeding

    Use keyword or vector retrieval to pull only relevant fragments, keep intermediate artifacts in object storage, decouple long-running jobs with a message queue, and observe call volume with logging and monitoring/alerting. This avoids “stuffing the entire repository into the context.”

    4.5 Session Splitting and Settlement

    Split sessions by deliverable goal and end them as soon as the task is done, which reduces long-tail re-reading. At the same time, account separately by model and by token type, otherwise the real cost hotspots cannot be located.

    5. How This Maps onto Baidu AI Cloud

    In engineering practice on Baidu AI Cloud, the methods above map to a combination of general capabilities: object storage to hold code and intermediate artifacts, a container platform to run retrieval and preprocessing jobs, a message queue to smooth out long-running work, and logging plus monitoring and alerting to build a dashboard for tokens and cost along with threshold alerts. The core idea is unchanged: turn usage into observable metrics first, then talk about optimization.

    6. Three Conclusions to Watch Out For

    First, a high share of cached reads does not equal waste. It is the unavoidable price of maintaining coherence in a long session; it can be optimized but not eliminated. Second, a blended unit price hides structural problems, so accounting must be done separately by token type and by model. Third, the 24-day calendar span shows how elastic the cost of this kind of tool is; the real leverage lies in task splitting and context governance, not in compressing the length of a single output.