Deconstructing a 24-Day, 52-Hour AI Coding Bill: Where LLM Token Costs Actually Come From

    This article breaks down a real usage record from 24 days of AI-assisted coding: roughly 693 million tokens, about 52 hours of actual model inference time, and a $505.21 total. It explains why 88% of consumption came from cache reads rather than prompts, how the four billed traffic categories differ in economic nature, when prompt caching pays off, how to route tasks across model tiers, and which observability metrics and optimization practices actually move cost. You'll also find concrete guidance on stabilizing cacheable prefixes, a cost checklist grouped by context, caching, scheduling, and observability, plus five common misconceptions about AI coding spend.

    1. The Bottom Line First: Four Counterintuitive Facts From a Real Bill

    Let’s start with the numbers. This is a complete usage record accumulated over 24-plus consecutive days of working with an AI coding tool. The data comes from the tool’s built-in session statistics, and the amounts reflect only the accounting convention of this particular test. Pricing varies significantly across providers and across time periods, so this is not an official billing explanation in any way — it is used here purely as an analytical sample:

    Traffic type Order of magnitude Share of total tokens
    Cache read ~611 million 88.2%
    Cache write ~53.84 million 7.8%
    New input (tokens that missed the cache) ~18.67 million 2.7%
    Model output ~9.52 million 1.4%
    Total ~693 million 100%

    Three accompanying facts: a total bill of $505.21; a natural time span of 24-plus days; and roughly 52 hours of cumulative time in which the model was actually doing inference work.

    From these numbers we can derive a few more informative second-order metrics:

    • Blended cost intensity: 505.21 / 693 million ≈ $0.73 per million tokens.
    • Effective output intensity: treating new input (18.67 million) + output (9.52 million) = 28.19 million as “the traffic that actually carries new information,” 505.21 / 28.19 million ≈ $17.9 per million effective tokens. The two figures differ by roughly 24x.
    • Cache reuse multiplier: 611 million / 53.84 million ≈ 11.3x, meaning every unit of context written to cache was replayed an average of more than 11 times.
    • Model time as a share of calendar time: 52 / 576 ≈ 9%.
    • Average inference throughput: 693 million / 52 hours ≈ 13.3 million tokens/hour, or about 3,700 tokens/second.

    These produce four counterintuitive conclusions:

    First, the bulk of the bill is not “asking questions” — it’s “re-reading.” 88% of consumption came from repeatedly reading already-cached context. The developer’s actual prompts (new input) accounted for only 2.7%. Advanced AI coding workflows are therefore not question-and-answer exchanges at all; they are long-horizon processes that hold a large working context open and replay it over and over.

    Second, the cheapest component is precisely the one that generates all new value. Model output was only 1.4% of token volume, yet it carried every line of new code, every new document, and every new judgment produced over those 24 days. Treating “fewer tokens” as “cheaper” is a misreading of the bill.

    Third, calendar duration is not resource consumption. Of 24 days, only 52 hours were spent driving the model — about 9% utilization. The other 91% went into reading diffs, running tests, looking things up, meetings, and thinking. Evaluating AI coding cost “per day” is therefore badly distorted; the correct time units are model working hours and number of tasks.

    Fourth, the cost structure is a direct function of context management strategy. Cache reads dominating at 88% means the cost curve is determined almost entirely by how context is organized and replayed — not by how many questions were asked.

    2. What the Four Token Traffic Types Actually Mean: Knowing Which Segment Costs Money

    To get cost under control, you first need to distinguish the four traffic categories in a billing model, because their economic properties are entirely different:

    New input. Tokens that miss the cache and must be fully encoded by the model. This is the only cost item that grows linearly with the diversity of your questions. Ask the same question ten times and this line item grows tenfold.

    Cache write. A one-time charge for storing a stable prefix into cache. The common industry practice is that write pricing is higher than read pricing, and that the segment to be cached must reach a minimum length threshold and stay byte-for-byte identical within a minimum lifetime (exact values are defined in each provider’s documentation). This is a prepaid cost whose payoff comes from subsequent reuse.

    Cache read. Tokens replayed at a discounted rate after hitting a prefix cache. Its unit price is typically well below that of new input, but because it is still billed per token, total volume can be enormous. That is exactly how this sample reached 611 million: the unit price is low, but volume alone can’t be held down.

    Output. Content generated by the model, usually the highest unit price and not cacheable, making it the only linear cost that cannot be amortized.

    Understanding these four surfaces a key technical constraint: mainstream prefix caching implementations are based on exact prefix matching. This imposes two hard engineering requirements:

    1. The prefix must be stable. Any change inserted at the front invalidates all subsequent cache. Typical killers include: concatenating a current timestamp, session ID, randomly ordered file list, or randomly sampled examples into the system prompt.
    2. Stable content must come first. The correct ordering is: system-level rules → tool/interface definitions → long-term project conventions and directory notes → long-term source context → retrieval snippets → files newly added this round → the user’s current request → volatile fields such as timestamps.

    One counterintuitive implication: putting a timestamp at the very top of the system prompt is one of the most expensive patterns in a long session. It doesn’t help the model understand anything, yet it can drive the cache hit rate of the entire session to zero.

    3. The Cache Amortization Model: When Writing to Cache Actually Pays

    Whether caching is worth enabling can be decided with a minimal test. Let c_w be the cache write unit price, c_r the cache read unit price, c_i the new-input unit price for the equivalent prefix, and N the number of times a given prefix is reused within a session:

    1. Cost without caching: N * L * c_i
    2. Cost with caching: L * c_w + (N - 1) * L * c_r
    3. where L is the token length of the prefix
    4. Caching pays off when: c_w + (N - 1) * c_r < N * c_i

    The measured reuse multiplier for this bill was about 11.3x, which falls clearly inside the “worth it” region. That also explains why the developer was willing to absorb 53.84 million write tokens in exchange for 611 million discounted reads.

    Conversely, which scenarios should not obsess over caching:

    • One-off scripts and single batch jobs: the reuse multiplier is naturally 1, so writing to cache is pure waste.
    • Exploratory retrieval: context differs substantially each round, the prefix is broken repeatedly, and hit rates are low.
    • Highly parallel but non-overlapping task sets: every task is an independent prefix, so no cache can be shared.

    The more practical engineering approach is not a global “on/off” switch but selecting a strategy per session type: enable caching and freeze a stable prefix for long-horizon refactoring tasks; disable it outright for short question-answering tasks to avoid paying the write tax.

    4. Model Tiering: Make Routing an Engineering Concern, Not a Habit

    The model cost distribution for this bill was: mid-tier workhorse model $348.34 (~68.9%), lightweight model $84.40 (~16.7%), high-end model $72.47 (~14.3%).

    This distribution is quite representative, and it reflects a healthy three-tier structure:

    Light tier (16.7%): high volume, low unit price, simple tasks. It handles file reading and summarization, keyword and symbol retrieval, log and error message classification, format conversion, and bulk field extraction. These tasks need high throughput rather than deep reasoning — using a high-end model for them is pure waste.

    Main tier (68.9%): where the absolute workload sits. Everyday feature implementation, unit test generation, code review, documentation completion, routine bug fixes. It absorbs the vast majority of token consumption and is the main battlefield for cost optimization.

    Deep tier (14.3%): low frequency, high value. Architecture trade-offs, cross-module refactoring design, root cause analysis of difficult problems, complex algorithmic derivation. Usage is small but unit price is high, because each call substitutes for expensive human thinking.

    Making routing explicit — rather than relying on developers manually switching models — reliably captures these gains:

    1. from enum import Enum
    2. class Tier(Enum):
    3. LIGHT = "light" # retrieval, reading, formatting, classification
    4. MAIN = "main" # implementation, tests, review, routine fixes
    5. DEEP = "deep" # architecture design, root cause, complex refactoring
    6. def route(task) -> Tier:
    7. # 1. Pure information movement and structural transformation: prefer the lowest-cost tier
    8. if task.kind in {"read_file", "search_symbol", "summarize_log",
    9. "format_convert", "extract_fields"}:
    10. return Tier.LIGHT
    11. # 2. Cross-module impact assessment, or repeated past failures: escalate
    12. if task.cross_module or task.retry_count >= 2:
    13. return Tier.DEEP
    14. # 3. Everything else at the code level goes to the main tier
    15. return Tier.MAIN

    Three design principles: default to the lower tier (better to escalate than to default to the most expensive); escalation needs explicit triggers (cross-module work, consecutive failures, high-risk changes touching data or permissions); and log every routing decision, otherwise you cannot later reconstruct “why was this particular run so expensive.”

    5. An Actionable Cost Optimization Checklist

    Grouped by area of impact, with the practice, the rationale, and how to verify it.

    Context side

    1. Establish a context allowlist: feed only files directly relevant to the current task into context, and replace full injection with retrieval. Verification: watch whether new input tokens and cache write tokens decline together.
    2. Periodically converge long sessions: every time you complete a verifiable milestone, open a new session and carry the conclusions forward as a structured summary. Rationale: the longer the session, the larger the stable prefix that gets replayed, and cache read volume grows linearly and independently of output.
    3. Emit structured summaries rather than raw snippets: summaries have controllable length and are easier to keep prefix-stable.
    4. Disable “re-sorting the file list every turn”: unstable ordering punches holes directly in the cache.

    Cache side

    1. Freeze the ordering of the stable prefix: system rules, tool definitions, and project conventions first; timestamps and transient data last. This is the single highest-ROI optimization available.
    2. Move volatile content out of the prefix: put time, session IDs, and random IDs at the very end, or don’t inject them at all.
    3. Select cache strategy by session type: on for long-horizon refactoring, off for short question-answering.
    4. Monitor the cache read / cache write ratio. When healthy it is typically above 10; if it stays persistently below the break-even point from the formula above, your caching strategy has stopped working.

    Scheduling side

    1. Batch small tasks together: merge several independent small requests into one call with well-prepared context, reducing repeated prefix encoding overhead.
    2. Parallelize read-only tasks: side-effect-free work such as retrieval, summarization, and format conversion can be launched in parallel, lowering total model working time.
    3. Enforce output budgets: explicitly constrain length and format for generation tasks. Output is the only non-amortizable cost and must be capped explicitly.
    4. Escalate to the deep tier only for high-risk changes, and trigger it with rules rather than instinct.

    Observability side

    1. Record a structured cost log for every call (see the next section). Measure first, optimize second.

    6. Build Your Own Usage Observability

    Without measurement, cost optimization is guesswork. It’s worth writing one structured record per model call, with fields kept vendor-neutral and decoupled from any specific provider:

    1. {
    2. "ts": "2026-08-27T02:01:11.588Z",
    3. "session_id": "s-20260827-a3",
    4. "task_type": "implement|review|search|refactor",
    5. "tier": "light|main|deep",
    6. "model_time_ms": 41230,
    7. "tokens": {
    8. "input_new": 182340,
    9. "cache_write": 0,
    10. "cache_read": 1258900,
    11. "output": 24310
    12. },
    13. "cost_est": 0.418,
    14. "cache_hit_ratio": 0.873,
    15. "retry_count": 0
    16. }

    On top of this, define four north-star metrics:

    • Cost per effective output = total cost / (input_new + output). This is the only metric that should be used to compare “efficiency” across runs; for this sample it was about $17.9 per million effective tokens.
    • Cache reuse multiplier = cache_read / cache_write, which shows whether the caching strategy is working.
    • Effective token share = (input_new + output) / total, about 4.1% here. It is a direct signal of context bloat in long sessions.
    • Median and P95 cost per task: use the median to understand day-to-day spending, and P95 to catch outlier tasks.

    In terms of implementation shape, these logs can be collected and searched with general-purpose cloud log services, threshold alerts configured through monitoring and alerting, and long-term archives kept in object storage to support cross-month cost attribution. Using Baidu AI Cloud as an example, general-purpose capabilities in categories like log service, monitoring and alerting, and object storage can all support this pipeline; see the official documentation for specific integration methods. Alerts should be based on relative rather than absolute amounts — for example, “cache_write for a single session grew 3x versus the previous period,” or “effective token share stayed below 2% for five consecutive tasks.” Formulated that way, the rules are reusable across teams of different sizes.

    7. Five Misconceptions to Avoid

    Misconception 1: judging efficiency by “how much did we spend in total.” The figure $505.21 means nothing by itself. What matters is how much effective output it bought. The same money might correspond to 20 high-value refactors, or to 2,000 repetitive Q&A exchanges.

    Misconception 2: chasing a 100% cache hit rate. Forcing every task into one session and refusing reasonable session splits in order to protect hit rate makes context grow without bound, and total cost eventually rises. Caching is an optimization technique, not the objective function.

    Misconception 3: always using the strongest model. Going from the main tier to the deep tier can multiply cost several times over, while quality improvement on tasks like retrieval and formatting is close to zero. The gains from tiered routing far exceed those from picking a single strongest model.

    Misconception 4: ignoring the fact that output cannot be cached. Cache reads can be amortized; output cannot. Asking the model for long explanations, line-by-line comments, or repeated summaries produces the hardest block of cost on the bill.

    Misconception 5: treating long context as a free resource. Beyond cost, an oversized context also dilutes key information and degrades instruction following. Context has a price and also an attention budget.

    8. Closing Thoughts

    Back to this sample: 693 million tokens, 52 hours of model working time, a 24-day span, $505.21 in total, of which 88% was cache reads while output was only 1.4%, with blended cost intensity of $0.73 per million tokens versus effective output intensity of $17.9 per million tokens. What these numbers really show is this: in long-horizon AI coding scenarios, cost is not a variable you can solve by “asking a bit less” — it is an engineering constraint jointly determined by how context is organized, caching strategy, and model routing.

    Three things you can act on immediately: fix the ordering of the stable prefix and remove volatile content such as timestamps from it; tag tasks with a type and a tier, and make routing rules explicit; and write one structured cost log per call, then make decisions using cost per effective output rather than the total amount. Do these three, and you can usually compress that “read eleven times over” context overhead substantially without compromising task quality.