AI Coding Cost Breakdown: 24 Days, 52 Hours, and $505.21
This article breaks down the real cost of an AI-assisted coding effort that spanned 24 days and 52 active model hours, totaling about $505.21 and roughly 693 million tokens. It explains why token structure, not the number of prompts, drives the bill; how the four token categories differ in price and purpose; how model tiering by cognitive difficulty controls spend; and which session and context practices keep long-running AI coding work affordable.
1. Start With the Conclusion: The Bill Is Not a Function of Prompt Count
A single AI-assisted coding effort spanning more than 24 days cost about $505.21, with the model actively working for a cumulative total of roughly 52 hours. Dividing the two gives an average of about $9.7 per hour, but the metric that actually explains the bill is not an hourly rate. It is the token structure.
According to the records, the effort processed about 693 million tokens in total: roughly 611 million cache reads (about 88% of the total), about 53.84 million cache writes, about 18.67 million new input tokens, and about 9.52 million output tokens. In other words, the information that was genuinely new (new input plus output) accounted for less than 4% of total usage. The vast majority was repeated reading of context that already existed.
This explains a common source of confusion: why the bill is high even when the number of questions is small. In AI coding work, cost is driven approximately by the formula below, not by the number of prompts:
total cost ≈ Σ(context length per turn × turns) × price of the corresponding tier
Turns and context length are multiplicative, so as context grows, cost rises superlinearly.
2. The Four Token Categories and What They Mean for Cost
Understanding the bill starts with separating four token categories, which differ completely in unit price and in why they are generated:
- New input: the instructions, code snippets, logs, and error messages genuinely added in the current turn.
- Cache write: registering a piece of context as reusable cache for the first time, usually at a higher unit price than a cache read.
- Cache read: referencing already-cached context again in later turns, at a unit price significantly lower than new input, but billed repeatedly.
- Output: the code, explanations, and refactoring results the model generates, usually at the highest unit price.
The 611 million cache reads in this data set show that the working style was not “one question, one answer,” but long sessions that continuously carried a large amount of existing content: repository structure, the full text of multiple files, prior decisions, and records of failed attempts. Caching lowered the unit price but did not reduce the multiplier of “read count × context length,” so the total was still amplified into the hundreds of millions.
A rough but practical rule of thumb: if cache reads account for more than 80% of total usage, the optimization focus should be on “carrying less per turn” and “converging sessions sooner,” not on further tightening the wording of prompts.
3. Model Tiering: Primary, Auxiliary, and Hard-Judgment Models
The cost distribution also shows a clear division of labor: the primary model accounted for about $348.34, the auxiliary model about $84.40, and the high-capability model about $72.47.
- The primary model handled the bulk of code generation and modification. It is the cost center, so it offers the largest optimization payoff.
- The auxiliary model has a low unit price and takes on mechanical tasks such as retrieval, locating code, bulk reading, and formatting, trading low cost for throughput.
- The high-capability model was used the least but has the highest unit price, reserved for architecture trade-offs, root-cause analysis of difficult defects, and review of key refactoring plans.
The essence of this tiering is “pricing by cognitive difficulty”: grading tasks by the depth of reasoning they require, avoiding high-priced models for low-value repetitive work and avoiding low-capability models for complex judgment. In engineering terms, a routing layer can implement this:
def route(task):if task.kind in {"search", "locate", "summarize"}:return "small" # auxiliary tierif task.risk == "high" or task.need_deep_reasoning:return "large" # high-capability tierreturn "mid" # primary tier
Routing decisions should be based on task type, blast radius, and reversibility, not on subjective preference.
4. 52 Hours Over 24 Days: The Hidden Cost of Session Rhythm
The 24-day span alongside 52 hours of actual work shows that cost was not evenly distributed but concentrated in a few long sessions. The problem with long sessions is that context only grows: every additional turn forces all prior content to be read again, forming a “context ratchet.”
Improvements include:
- Session sharding: split work into small, independently verifiable goals, output a summary of conclusions at the end of each session, and carry only the summary into the next session.
- Context allowlist: explicitly declare which files and directories may be carried, and retrieve everything else on demand.
- Staged persistence: write decisions, interface agreements, and to-dos into in-repository documents that tools read instead of relying on model memory.
- Timely termination: end as soon as the goal is met, avoiding a casual “one more question” that triggers a full context re-read.
An illustrative context budget constraint:
context_budget:max_files_per_turn: 6max_turns_per_session: 20summary_on_exit: truecache_write_threshold_tokens: 20000
5. An Actionable Cost Governance Checklist
- Measure first: track tokens and cost separately by model tier, task type, and session to locate the real cost center.
- Retrieval over full text: prefer precisely locating snippets instead of repeatedly pulling whole files into context.
- Fix prompts and conventions: put coding standards and directory conventions into long-term documents to reduce repeated explanation.
- Constrain output: require minimal necessary changes and a diff explanation to cut ineffective output.
- Calibrate caching strategy: register only stable, unchanging content as cache; repeatedly writing frequently changing content costs more.
- Budget guardrails: set per-session and per-day quota thresholds that trigger splitting or downgraded routing when exceeded.
6. Conclusion
$505.21, 693 million tokens, and 52 hours point to one conclusion: the core of AI coding cost lies in context governance and task tiering, not in the model’s unit price itself. Three main lines make cost controllable while preserving output quality: splitting long sessions into shorter ones, compressing carried content to the minimal necessary set, and routing tasks by difficulty to the appropriate tier. In engineering practice on cloud platforms such as Baidu AI Cloud, this kind of usage data can likewise be continuously observed and optimized through logging services and monitoring and alerting systems.
