systemdesign.academyAI EngineeringFree lessonsSign inGet the course
  1. Home
  2. AI Engineering: Evaluation, LLM Ops and Security
Previous lessonLLM Agents in Production: The Model in a LoopNext lessonModel Routing and Cascades: Running Three Models Without Chaos

System Design

  • Foundation
  • Intermediate
  • Advanced
  • Capstone

AI Engineering

  • Foundation
  • Data, RAG and Agents
  • Evaluation, LLM Ops and Security

systemdesign.academy

  • Home
  • Glossary
  • Interview prep
  • Reviews
  • About
  • Pricing
  • Privacy
  • Terms
  • Refunds
  • Delivery
  • Contact
  • LLM and GenAI Ops
  • Token Cost Engineering: Where the LLM Bill Actually Goes
  • AI Engineering · Llm Genai Ops

    Token Cost Engineering: Where the LLM Bill Actually Goes

    Free preview: the first part of this 15-part lesson.

    Already bought the course? Sign in to read the whole lesson.

    this lesson is part of

    AI Engineering

    Unlock this lesson and the 199 other paid lessons

    • 210 lessons in 16 chapters
    • 118 lessons built on a lab that really ran
    • An AI tutor beside every lesson that answers and draws
    • Lifetime access, every new lesson included

    $49 once, by PayPal

    See the AI Engineering course

    The rest of this lesson

    1. The Sticker Price and the Real Price
    2. Why the Loop Resends Everything
    3. The Levers, In Order of Leverage
    4. Prompt Caching: What Actually Gets Cached
    5. Cache Lifecycle, TTL, and When It Fails to Pay
    6. Run the Bill Decomposition
    7. Slimming: Caching Made It Cheap, Not Free
    8. Output Length: The Expensive Token
    9. Batching: Half Price for Work No One Is Waiting On
    10. Right-Sizing, and the Bridge to Routing
    11. Cost Per Token Is the Wrong Unit
    12. What a Task Really Costs
    13. How Teams Actually Hold the Line
    14. Knowledge Check

    read the rest of this lesson in

    AI Engineering

    Unlock this lesson and the 199 other paid lessons

    • 210 lessons in 16 chapters
    • 118 lessons built on a lab that really ran
    • An AI tutor beside every lesson that answers and draws
    • Lifetime access, every new lesson included

    $49 once, by PayPal

    See the AI Engineering course

    Continue this lesson

    in Llm Genai Ops

    This lesson is part of the AI Engineering course. Unlock the full course, a separate one-time payment, for lifetime access.

    One-time payment. Lifetime access. No subscription.
    Global
    $49/lifetime

    One-time payment by card or PayPal

    Get Lifetime Access
    Foundation lessons free, try before you buy
    India Special
    India
    ₹999/lifetime

    One-time payment: UPI, card or netbanking

    Get Lifetime Access
    Foundation lessons free, try before you buy
    Every ML Platform lesson, Foundation to Advanced
    Real architecture diagrams with real tool logos
    MLOps, LLMOps, and data engineering in depth
    Quizzes with instant feedback
    Built and reviewed by senior engineers
    Lifetime access, all future content included

    Foundation lessons of this course are free, no payment needed. Try them now

    Most of the Bill Is Tokens You Resend

    Here is the part of a production LLM bill that surprises people. Most of the tokens you pay for are not the ones your user typed. On an agentic feature they are the system prompt and the tool descriptions, resent on every step of the loop, plus a conversation history that grows and gets replayed each step, plus output tokens that are priced several times higher than input. The user's actual question is often the smallest line item on the invoice.

    That matters because the shallow version of this topic ends at "use a cheaper model" or "the price is a fraction of a cent per thousand tokens." Both are true and both miss the point. The price per token is the least useful number in the whole exercise, because it tells you nothing about how many tokens a real outcome takes. A single support task handled by an agent can bill fifty thousand input tokens across its steps while returning a two-sentence answer. Quote the sticker price and you will under-forecast the bill by a large multiple.

    Stacked decomposition bar of one agent task's token bill: a 32k resent system prefix and a 24.5k replayed history dominate the bar, with 4k of output and only 120 tokens of actual user question, showing the user's question is about 0.2 percent of the task

    This is a different problem from the one the LLM inference optimization lesson solves. That lesson is the serving side: how to push more tokens through a GPU you rent, using the , continuous batching, and quantization. This lesson is the spend side: the token bill itself, which is sharpest when you call a hosted API that meters you per token and where you cannot touch the GPU at all. The two are complementary. You can serve efficiently and still overpay wildly, because you are sending far more tokens than the work requires.

    The plan is to decompose the bill into buckets, then pull the levers in order of leverage. By the end you will have two calculators you can run on your own numbers: one that shows the monthly bill before and after and slimming, and one that shows what a task really costs once retries and reflection are counted.