The Cost of Code Generation with Generative AI
What is the real cost of a user story?
1First Generation Code Factory
Between March and July 2026, a production application with 861,601 lines of code was developed. This process included 696 user stories and 779 merged pull requests. However, the cost is unknown because the first-generation autonomous SDLC framework did not record usage data. Claude Code's 30-day transcript retention period also erased the only record.
2Second Generation Factory
The second-generation factory records its own costs while working. Each stage attempt writes its tokens (input, output, cache read, cache write), cost, model, and failure category to a ledger. While the first-generation application left no records, this generation cannot run without keeping them.
3User Story Definition
In this pipeline, a story is a small requirement decomposed from an epic. Acceptance criteria give the agent its stopping condition. The Definition of Done allows the machine to know when it's finished. Humans batch stories into sprints to manage delivery.
4Story-Build Process
A story-build is a story going through its own full delivery cycle. This process includes writing tests first, the build, a coverage gate, review by a dedicated reviewer agent, and the merge. It also includes bug fixes and repeat requests when an agent's reply is malformed.
5Dataset and Models
The dataset in the article covers every story built in one repository between June 25 and July 18, 2026. This includes 17 runs, 193 story-builds, 374 stage attempts, and 336 session logs. June runs used Claude Opus 4.8, July runs used Claude Fable 5, and smaller parts were handled by Claude Haiku 4.5.
6Story Cost
The factory consumed 595.7 million tokens to ship 77 stories, 7.7 million tokens per delivered story: at list prices for those models, $837.53, or $10.88 per story. The numerator includes every token thrown away, the five stories that ended FAILED, the 22 failed stage attempts, bug fixes, and re-ask loops; the denominator counts only shipped stories.
7Cost Estimates
In a previous essay, I estimated my factory’s stories at 'a few dollars to a few tens of dollars.' The meter’s answer is $3.02 to $43.24 with a median of $9.56, so my estimates were valid. Story points barely predict cost because the medium and large bands are only 8% apart at the median.
8Most Expensive Story
The most expensive story was $43.24 for a 3-pointer that hit a review retry and a bugfix loop. The wall-clock mean is roughly two and a half times the median because the overnight run hit the subscription plan’s rate-limit window twice and stalled for hours. This was a billing artifact rather than an agent one.
9Cache Management
An agent resends the same instructions and repository context on every turn. The API caches that stable context, which makes a cached reread cost a tenth of fresh input, though it charges a premium to write new content into the cache. 95.4% of all tokens are cache reads. The factory rereads about 73 cached tokens for every new token it writes or receives.
Original article: O'Reilly Radar — Generatif AI ile Kod Üretiminin Maliyeti