Understanding Token Billing: How to Do More With Fewer Tokens in AI Coding

    An AI coding session can rack up nearly 10 million tokens and look alarming at first glance—yet the actual bill may be only a fraction of what the raw number suggests. This article explains how token billing really works across the four token categories (input, cache creation, cache read, and output), why a cache read can cost roughly one-tenth of standard input, and what actually inflates your context window. It closes with practical strategies for structuring your prompts, trimming logs, and shifting from "total-token" thinking to "cost-structure" thinking—so you can get more done with fewer tokens.

    1. Starting From “Nearly 10 Million Tokens”: Don’t Panic at the Surface Number

    A newcomer to AI-assisted coding tools racked up nearly 10 million tokens over a long session. Before opening the detailed usage report, the first instinct is usually panic—that many tokens must be burning a fortune, right? But once you actually spread out the report and look closely, things turn out to be far less alarming. Those nearly 10 million tokens are distributed very unevenly across a few categories: direct input makes up a small share, model output makes up an even smaller share, and the single largest category—close to 90% of the total—is cache read.

    Here lies a key point that most beginners overlook: cache reads are typically priced at only a small fraction of the standard input rate (a common industry practice is around one-tenth of the input price, sometimes even lower). In other words, while it looks like you “burned nearly 10 million tokens,” the actual cost may be just a fraction of that headline number. Grasping this is the first step every developer who wants to control AI coding costs must take—to evaluate cost, you can’t just look at the total token count; you have to look at the token “structure.”

    2. The Four Identities of a Token: Wildly Different Costs

    To truly understand billing, you first need to recognize that the tokens in a single request are not all “the same thing.” In the billing models of mainstream large-model APIs, tokens fall into roughly four categories, and their prices differ dramatically:

    1. Input: The context actually sent to the model in each request—your prompts, the code you paste in, prior conversation, and so on. This is standard pricing, usually the most expensive “baseline” of the four.

    2. Cache Creation: When a segment of context needs to be reused and exceeds a certain length threshold, the model service “writes” that segment into the cache for fast retrieval later. This write is billed separately, and the price is often slightly higher than direct input (since it also includes storage overhead).

    3. Cache Read: When a later request hits already-cached content, you pay only the cache read rate. This rate is significantly lower than direct input, and it’s the underlying reason why “the longer the session, the lower the per-unit cost.”

    4. Output: The content the model actually generates. It’s usually several times the input price—the highest per-unit rate of the four. But in “read a lot, write a little” scenarios like AI coding, output typically accounts for a small share of the total.

    Here’s a common price relationship to help you remember (the exact multipliers vary by provider; this is illustrative only):

    1. Cache Read ≈ Input × 0.1 ← cheapest
    2. Input = Input × 1.0 ← baseline
    3. Cache Creation ≈ Input × 1.25 ← slightly pricier than input
    4. Output ≈ Input × (3~5) ← most expensive, but usually a small share

    The core rule boils down to one sentence: the higher the share of cache reads, the lower the actual cost for the same total token count. Conversely, if your usage report shows a low share of cache reads and a high share of direct input, that’s the real “money-burning” signal.

    3. What Does Prompt Caching Actually Cache?

    Prompt caching isn’t magic. It solves one very concrete engineering problem: avoiding the need to “tell” the model the same large chunk of content over and over on every turn.

    In a typical AI coding workflow, a lot of content is “carried every time but rarely changes,” such as:

    • A long system prompt or role definition;
    • The project’s directory structure, dependency list, and coding conventions;
    • Core source files that have been read in and referenced repeatedly;
    • A block of code context that takes multiple rounds of follow-up to finish editing.

    If all of this is re-sent as ordinary input on every request, the cost grows linearly—or even super-linearly—with each turn. Once it’s written into the cache, however, each subsequent turn reuses it at the very low cache read rate. This also explains the “paradox” at the start of this article: a session that consumes nearly 10 million tokens may cost very little, because most of it is cheap cache reads rather than expensive direct input or model output.

    One caveat: caches usually have a minimum length threshold (generally on the order of a thousand tokens), so context that’s too short isn’t worth caching. Caches also often have an expiration—leave them unused for too long and they expire and must be written again. So the prerequisite for content being “cacheable” is that it’s stable enough, large enough, and reused repeatedly within the validity window.

    4. What the Real Data Reveals: What’s Actually Inflating Your Context?

    Go back and line up each “cache creation peak” in the usage report, and you’ll often find that the culprits inflating the context are quite concentrated:

    • Repeatedly re-reading the same set of large files: pasting the entire codebase again every time a requirement is confirmed, causing the context to balloon;
    • Pasting lengthy error logs and dependency output: dragging in a multi-thousand-line build log in full, when only a few lines may actually matter;
    • Long sessions that never converge: topics keep piling up in a single session, and early, irrelevant content keeps occupying the context window;
    • Unclear problem boundaries: vague requirements force the tool to probe and read repeatedly, passively inflating the input.

    Once you see these patterns clearly, the direction for optimization becomes obvious: get “stable, large, reusable content” into the cache, and keep “temporary, irrelevant, ever-changing content” as lean as possible.

    5. Practical Strategies: Get the Most Done With the Fewest Tokens

    Building on the principles above, here are a few tactics beginners can apply right away:

    1. Put stable context up front, variable content at the end. Group relatively fixed content—the system prompt, project conventions, core files—at the front of the context so it’s easy to hit the cache, and put the question description that changes every time at the very end. The more turns you go, the greater the benefit from cache reads.

    2. State your requirements clearly once, and cut down on back-and-forth probing. Clearly defining the task boundary (which file to change, what effect to achieve, what constraints apply) can significantly reduce the input consumed by repeated reads and confirmations. Better to write a couple of extra sentences up front than to let the tool keep guessing.

    3. Trim logs and irrelevant code promptly. Keep only the key stack trace and the relevant code snippets—don’t mindlessly paste the whole log or the entire repository. Every line of context should “earn its place.”

    4. Enjoy the cache benefits of long sessions, but know when to converge. Continuous follow-ups on the same topic can often enjoy the low cost of cache reads within a long session; but once you switch to a completely unrelated new task, starting a fresh session is usually cheaper than continuing to stack old context.

    5. Keep an eye on output cost—but don’t let it scare you. In coding scenarios, asking the model to “give only the key code and a brief explanation” is usually more economical than asking for “a full, long-winded explanation,” because output is the most expensive of the four token types. If something can be resolved with a short confirmation, don’t make it write at length.

    6. Build a “usage–structure” review habit. Make it a habit to check the usage report regularly—the point isn’t the total, but the proportions of the four token categories. High cache reads with controllable input and output indicate a healthy cost structure; if not, trace back to find which operations are generating expensive input.

    6. Conclusion

    In a session of nearly 10 million tokens, what triggers panic usually isn’t the tokens themselves—it’s a lack of understanding of how billing works. Controlling the cost of AI-assisted coding is essentially a “context structure optimization problem”: let stable content enter the cache to enjoy low-cost reads, keep temporary content lean, and make every input count. Once you shift from “total-volume thinking” to “structure thinking,” the number of problems a given budget can cover will far exceed your expectations.