AI Coding Costs Explained: What Building a 3D Web Page for a Few Cents Teaches About Real Spend
AI coding agents can now spin up an interactive 3D web page for just a few cents, yet a low per-token price doesn't guarantee a low bill. This article breaks down the true cost structure of general-purpose LLM coding agents—why input tokens and iteration count often matter more than unit price, and how to measure cost per successful task rather than cost per call. It offers six practical techniques for improving token efficiency, explains why agents get stuck re-checking the same file, and walks through shipping a 3D interactive page from a precise spec. A ready-to-use cost-control checklist closes the piece.
Introduction: A 3D Web Page for a Few Cents—and What It Really Costs
What can a few cents buy? Not even a bottle of water. Yet that’s already enough for an AI coding agent to produce, from scratch, an interactive 3D web page that rotates, zooms, and responds to clicks. Cases like this are becoming more common, driven by two forces: the steady decline in per-token prices, and the growing ability of agents to plan, write code, call tools, and verify their own work.
But if you focus only on “model X got cheaper” or “model Y is free for a limited time,” you’ll miss the engineering questions that actually matter:
- Why can a lower per-token price still lead to a higher total bill?
- Why do some agents spend half an hour re-checking the same file?
- How do you turn a vague requirement into a task an agent can get right on the first try?
This article evaluates no specific product. Instead, it focuses on general-purpose LLM coding agents, dissects their cost structure and efficiency bottlenecks, and offers methods you can apply directly.
1. Why a Low Unit Price Doesn’t Mean It’s Actually Cheap
1.1 An Agent’s Cost Is Built Up Through Iteration
A traditional model call usually handles a single prompt and returns a single answer. An agent works in a “think–act–observe” loop: the model reads files, breaks down the task, writes code, invokes tools to run and check the result, and then decides the next step. At every step, the model re-ingests its entire history along with the new input.
This leads to a structural feature that’s easy to underestimate: input tokens grow roughly with the square of the step count. Assume each step adds 1,000 input tokens and 1,000 output tokens. After n steps, cumulative input is on the order of 500n(n+1) tokens while cumulative output is on the order of 1,000n tokens. By n = 10, input tokens already outweigh output tokens by more than 50×, and the gap widens with every additional iteration.
Here is a simple estimate that’s useful for investigating an abnormal bill:
Task cost = iterations × avg input tokens per iteration × input price+ iterations × avg output tokens per iteration × output price
When a price rises by some multiple but the bill climbs noticeably more, the cause almost always lies in the iteration count. For example, one iteration introduces a huge file or log, and every iteration after that re-carries it.
1.2 Output Tokens: Fewer of Them, but the Highest Unit Price
Generating tokens requires sequential computation and can’t be parallelized the way input processing can, which is why output prices in the industry are typically much higher than input prices.
The share of cost also depends on the shape of the task:
- Q&A and analysis tasks: heavy input, light output—optimizing the input side (context management, prefix reuse) yields the most benefit;
- Code-generation tasks: output’s share rises, so whether the model stays concise and avoids large rewrites becomes critical;
- Long-chain agent tasks: input gets amplified by the iteration count and becomes the dominant expense—reducing wasted iterations pays off most.
1.3 More Important Than Unit Price: Cost per Successful Task
The most practical metric for whether a coding agent is worth it is cost per successful task:
Cost per successful task = total spend to complete tasks / number of successfully completed tasks
A model that’s 30% cheaper per call but succeeds on only half as many tasks as another can end up 1.4× more expensive. So a claim like “model X costs a fraction of model Y per task” carries an implicit assumption: that both are compared on the same workload at the same success rate. In other words, the numbers are only meaningful when you run both models on the same batch of representative real tasks.
1.4 A Sample Calculation
Suppose a 3D web page task completes successfully after 18 iterations, with an average of 22,000 input tokens per iteration (context accumulating as iterations progress) and an average of 2,200 output tokens per iteration:
Total input = 18 × 22,000 = 396,000 tokensTotal output = 18 × 2,200 ≈ 40,000 tokensCost = 396,000 × input price + 40,000 × output price
Plugging in illustrative prices, input tokens are clearly the main source of cost:
| Scenario | Input price (¥/1M tokens) | Output price (¥/1M tokens) | Task cost (¥) |
|---|---|---|---|
| A: input 0.5 / output 2 | 0.5 | 2 | ~0.28 |
| B: input 0.2 / output 1 | 0.2 | 1 | ~0.12 |
| C: B’s prices, but 36 iterations after rework | 0.2 | 1 | ~0.23 |
Starting from B, doubling the iteration count pushes the cost to about 1.9× the original—nearly canceling out the savings from the lower unit price.
Two conclusions follow:
- It’s the iteration count, not the unit price, that is the primary lever on an agent’s cost.
- Billing structures differ across models: some have cheap input and expensive output, others the reverse. When choosing a model, match it against your own input/output ratio, and if needed, use the online price calculators that each platform provides to run the numbers.
2. Token Efficiency: Why the Same Job Costs More Tokens
2.1 What Token Efficiency Means
Token efficiency is the number of tokens needed to complete a task at a given quality. There are two common ways to read it:
- At equal quality, who uses fewer tokens;
- At an equal token budget, who produces a better result.
Improving token efficiency is fundamentally about balancing information density against reasoning overhead. Information density is the amount of useful information carried per unit of context; reasoning overhead is the extra reasoning tokens and iterations a model spends to finish the task.
2.2 Common Sources of Low Efficiency
- Redundant context: pasting the same log over and over, dumping an entire large file at once, or leaving unrelated exploration in the conversation;
- Wasted exploration from missing information: without an interface contract or a directory description, the model can only “guess and try,” and every failed attempt burns another round of input;
- Overthinking: spinning out long chains of reasoning even for a simple change, pushing up both reasoning tokens and output length;
- Rework: getting it wrong once, fixing it, then fixing it back—costs roughly double, sometimes more.
2.3 Six Ways to Improve Token Efficiency
1) Subtract: keep only what the current task requires. Every extra round a piece of information stays in context, it gets billed once more. Clear out irrelevant content in long conversations, or start a fresh session on a regular basis and carry only a trimmed task summary.
2) Structure it: keep the prefix as stable as possible. Most mainstream model services offer context caching, which reuses computed results for repeated prompt prefixes and typically cuts the input cost of the cached portion substantially. Ordering your prompt by “rate of change” is the key to a higher hit rate:
[Fixed] System prompt, coding conventions, project architecture notes[Stable] This task's acceptance criteria and constraints[Volatile] New user requests, latest file contents, error messages
Put volatile content at the top and the stable content after it can no longer be reused.
3) Give a spec: write the requirement as an executable task brief.
- List features and interaction behaviors item by item;
- Specify the target runtime environment and version;
- Provide measurable acceptance criteria;
- State what to avoid.
A good spec keeps the model from taking wrong turns; a vague “make it look nice” can only converge through repeated trial and error.
4) Provide scaffolding: don’t hand deterministic work to the model. Directory structure, dependency versions, build configuration, and base styles can be generated first with a script or template. Let the model handle only what it’s good at: business logic, interaction design, and fine polish. The better the scaffolding, the fewer tokens the model wastes “guessing what the project looks like.”
5) Provide acceptance checks: make success automatically decidable. Give the task automated verification—type checking, unit tests, builds, static analysis; UI tasks can add screenshot comparison and interaction tests. If the check passes, finish; if it fails, retry with the specific error. This is cheaper and more reliable than having the model repeatedly “self-check.”
6) Set a budget: let the agent know when to stop. Explicitly cap the maximum number of iterations, maximum token consumption, or maximum runtime. A budget not only prevents cost overruns but also forces the model to prioritize the critical path instead of getting lost in details.
3. Why Agents Are Always Slow and Never Finish
Open an agent’s execution log and you’ll often see this: read files, break down the task, write code, call tools, check results… tens of minutes go by and the model is still re-checking the same file—sometimes even reverting a problem it just fixed. This isn’t just a matter of “slowness”; it’s a cost problem.
3.1 Three Typical Low-Efficiency Behaviors
- Spinning in place: without a clear stopping condition, the model keeps “confirming one more time”—marginal benefit approaches zero while input tokens keep piling up;
- Revert-style fixing: a change that fixes problem A breaks feature B; the model fixes B and may break A again, forming a “fix–break–fix” loop. Without regression tests, this is the most common hidden source of rework;
- Completion illusion: declaring “done” or “tests pass” without actually running verification, delivering artifacts with hidden defects that often surface only during human acceptance.
3.2 Four Engineering Responses
- Small commits: break each requirement into several independently verifiable small changes, each with its own tests, isolating problems to the smallest possible scope;
- Regression safety net: automatically run the full test suite after every change to ensure “what’s fixed stays fixed”;
- Traceable process: keep each round’s tool calls and execution results so that when a regression occurs, you can quickly pinpoint which step introduced it rather than starting over;
- Human–agent rhythm: have the agent first output a plan and a change list during the planning phase, and let a human confirm key decisions before it acts. This adds a low-cost “gate” in front of high-risk operations.
4. From Requirement to Delivery: Building a 3D Interactive Web Page from Scratch
4.1 Translating “Build a 3D Web Page” into a Spec
“Build a cool 3D web page” can’t be verified, so it can’t be reliably delivered. A better description is: “On load, the page shows a rotatable cube; dragging changes the viewing angle; the scroll wheel zooms; clicking the cube switches its color; the page shows no horizontal scrollbar; the console shows no errors.” Every item is observable and testable.
You can use the spec template below:
# Task: 3D Interactive Showcase Page## GoalBuild a single-page 3D interactive showcase from scratch, for product concept display.## Functional Requirements1. On first load, show a cube that slowly auto-rotates2. Press and drag the mouse: rotate the view; scroll wheel: zoom3. Click the cube: toggle a highlight color4. On narrow screens (<=768px), the layout adapts and the canvas fills the visible area## Technical Constraints- Runs in modern browsers; provide two paths - a 3D rendering library and a 2D fallback- No backend dependency; the build output is pure static files## Acceptance Criteria- All interaction behaviors above work- No horizontal scrollbar; no console errors- Desktop interaction frame rate >= 50fps (measured on a dev machine)- Displays a static preview image in environments with no graphics interface## Deliverables- Source code (with dependency declarations and build config)- Local run instructions- Change notes: what changed in each file and why
4.2 Key Code the Agent Generates
In a 3D interactive page, a few engineering details usually determine performance and experience: capping the pixel ratio, pausing rendering for invisible pages, and throttling high-frequency callbacks. The following is an illustrative page skeleton showing how these points land in code:
// Illustrative code: the actual rendering logic is handled by a general-purpose 3D rendering library; this only demonstrates engineering pointsimport { createRenderer } from './renderer.js';const container = document.querySelector('#scene');const canvas = document.createElement('canvas');container.appendChild(canvas);// 1. Cap the pixel ratio: on high-DPI screens, per-pixel shading cost grows with the square of the resolutionconst DPR_LIMIT = 2;const renderer = createRenderer(canvas);const resize = () => {const dpr = Math.min(window.devicePixelRatio || 1, DPR_LIMIT);renderer.setSize(container.clientWidth, container.clientHeight, dpr);};new ResizeObserver(resize).observe(container);resize();// 2. Throttle: dragging and zooming are high-frequency events, so batch them per framelet pending = null;const queueUpdate = (fn) => {pending = fn;};renderer.onFrame(() => {if (pending) { pending(); pending = null; }});// 3. Pause: stop rendering when the page is not visible, saving GPU and batterylet running = true;document.addEventListener('visibilitychange', () => {running = !document.hidden;});renderer.onFrame(() => {if (!running) return;renderer.render();});
The core point this code makes is: whether the code an agent produces is reliable doesn’t depend on how fast it wrote it, but on whether it covers the boundary conditions. Pixel-ratio caps, page visibility, high-frequency events, and container resize are exactly the lines between “it runs” and “it’s good to use.” Spelling these boundaries out in the prompt is far cheaper than having the agent patch them repeatedly after the fact.
4.3 Start from a Minimum Viable Version and Iterate
Having the agent generate an entire project in one shot makes debugging costly and the rework scope large once errors appear. A more robust path is to proceed in stages, each reaching a “runnable and verifiable” state:
- Minimum runnable version: get the build pipeline working and display one rendered object on the page;
- Basic interactions: add rotation, zoom, and picking interactions;
- Visuals and experience: tune materials, lighting, and animation timing, and add mobile adaptation;
- Performance and compatibility: compress asset sizes, handle fallback paths, and verify frame rate.
4.4 How to Ensure Generation Quality
For AI-generated code, run it through at least four gates:
- Build and static checks: confirm the code compiles and passes type checking and lint rules;
- Unit tests: cover pure logic such as interaction state and coordinate conversion, reducing repetitive visual-level debugging;
- Human code review: focus on security (external input validation, dependency trustworthiness) and maintainability (clear structure, no redundancy);
- Real-environment verification: operate it on the target devices and browsers to confirm interactions are smooth and assets load correctly.
5. Managing the Cost: An Actionable Checklist
- Build a baseline: pick 10–20 representative real tasks (e.g., generating a page, fixing a defect, completing tests, refactoring a module), and record each model’s number of successful tasks and total spend per task type to derive cost per successful task;
- Give a spec: constrain task inputs with the section 4 template to reduce wasted exploration;
- Control context: clear redundant history promptly and put fixed content in the prefix;
- Set a budget: cap iterations and spend per task, and pause for human intervention when exceeded;
- Enforce verification: make automated checks part of the task loop to reduce “completion illusion”;
- Observe continuously: log input, output, and cached-hit tokens per call, aggregate the analysis by task, and pinpoint abnormal iterations;
- Trial responsibly: the limited-time free quota when a new model launches is well suited to running baseline evaluations, not to taking on critical production work directly.
Conclusion
Building a 3D web page for a few cents shows that AI coding is now cheap enough to “just try.” But as the cost curve moves down, engineering capability is what sets the ceiling on delivery quality. Unit prices will keep falling, but whoever writes clear specs, keeps context clean, and makes acceptance solid will get more reliable results within the same token budget. For developers and businesses alike, writing both cost awareness and engineering discipline into everyday workflow is the sustainable way to make the most of AI coding agents.
