Home / Blog

· 6 min read · Gate 3, Cost

LLM cost per request: a worked breakdown

Most teams know their monthly LLM bill and not their cost per request. A line-by-line breakdown of one RAG request, what it means per customer, and the five levers that cut it by more than half.

When I ask a SaaS team what their AI feature costs, the answer is almost always the monthly invoice from their model provider. That number is useful for finance and useless for product decisions. It does not tell you which customers are profitable, which feature is expensive, or what happens to your margin when usage grows ten times.

The number that answers those questions is cost per request, and then cost per customer. This post walks through one realistic request line by line, scales it to a customer, and shows the levers that bring it down.

The example: a RAG assistant inside a B2B product

The setup is common. A B2B SaaS product has an assistant that answers questions about the customer's own documents: policies, contracts, tickets, product data. Each user question goes through four steps:

  1. Query rewrite. A small model turns the user's message plus recent history into a standalone search query.
  2. Retrieval. The query is embedded and the top six chunks are pulled from a vector index.
  3. Answer. A mid-tier model gets the system prompt, the retrieved chunks, the conversation history and the question, and writes the answer.
  4. Check. A small model checks that the answer is grounded in the retrieved chunks before it is shown.

To keep the arithmetic readable I use round, illustrative prices, roughly in the range of current mid-tier and small models. Model prices change often, so plug in your own:

ModelInput, per 1M tokensOutput, per 1M tokens
Mid-tier model (answer)$3.00$15.00
Small model (rewrite, check)$0.40$1.60
Embedding model$0.02n/a

One request, line by line

Here is a typical mid-conversation request, measured in tokens:

StepInput tokensOutput tokensCost
Query rewrite (small)2,20050$0.00096
Embed query100n/a$0.000002
Answer (mid-tier): system prompt 1,500 + 6 chunks × 500 + history 2,000 + question 1006,600400$0.02580
Grounding check (small)3,50050$0.00148
Retries, 3% of answer calls$0.00077
Total≈ $0.029

About three cents. Three things stand out.

Input dominates. The answer step reads 6,600 tokens and writes 400. Even though output tokens cost five times more, input is 77% of that step's cost. Most cost work is therefore about what you send, not what you get back.

Retrieved context is the biggest single line. Six chunks of 500 tokens is 3,000 tokens, almost half the input. Most teams pick "top 6" or "top 10" once in the prototype and never revisit it.

History grows. I used 2,000 tokens of history, which is about turn three or four. By turn ten, history is closer to 8,000 tokens, the answer step costs $0.044, and the whole request costs about 60% more. A user who keeps one conversation open all week is your most expensive user, and nothing in the invoice tells you that.

From request to customer

Now take a customer with 200 seats. Each user asks 15 questions per working day, 21 working days a month:

  • 200 × 15 × 21 = 63,000 requests a month
  • 63,000 × $0.029 = about $1,830 a month in model cost

If that customer pays $30 per seat, revenue is $6,000 a month. The AI feature alone costs 30% of it, before hosting, the vector database, support and everything else. A typical SaaS gross margin target is 75 to 80%. This feature makes that impossible.

Then look at the distribution, not the average. One power user who sends 300 requests a day costs about $180 a month on a $30 seat. An agent that loops on a failing tool call can do the same in an afternoon. An average cost per seat hides both.

Five levers, and what they are worth

Here is the same request after five changes, all of which I have seen work in production systems.

1. Cache the static prefix. The system prompt is the same on every request. Most providers now offer prompt caching, where repeated prefix tokens are billed at a steep discount. Assuming cached reads cost 10% of the normal input price (check your provider: discounts differ, and some charge extra to write the cache), the 1,500-token system prompt drops from $0.0045 to $0.00045 per request. Put everything static at the start of the prompt so the cache can be reused.

2. Retrieve less, rank better. Going from six chunks to four, with a reranker choosing which four, takes 1,000 tokens out of every request. Measure it with your retrieval evals first: if recall drops, the saving is not worth it.

3. Summarise history. After a few turns, replace old messages with a short running summary. Capping history at about 1,200 tokens stops the growth from turn ten onwards and often improves answers, because the model reads less noise.

4. Route easy questions to the small model. Many questions ("what is our refund policy?") do not need the mid-tier model. A router, which can be a simple classifier or the small model itself, sends them to the cheaper one. In this example I assume 40% of traffic can go to the small model and still pass its evals. That is the important part: routing is only safe if each route is evaluated.

5. Check a sample, not everything. Run the grounding check on 20% of traffic plus every answer the user flags, instead of on every request. For some products, such as anything medical, legal or financial, you will want to keep checking everything. That is a product decision, and it should be made with the cost in front of you.

The result:

BeforeAfter
Answer step, blended$0.0258$0.0099
Rewrite + embed$0.0010$0.0010
Grounding check$0.0015$0.0003
Retries$0.0008$0.0003
Cost per request≈ $0.029≈ $0.011
Cost for the 200-seat customer≈ $1,830 / month≈ $720 / month
Share of that customer's revenue30%12%

About 60% cheaper, with no change the user would notice, and in two cases (history and reranking) likely better answers.

How to measure it in your own system

You cannot manage what you only see on an invoice. The minimum setup I recommend:

  • Log every model call with: request ID, tenant ID, user ID, feature, step (rewrite, answer, check), model, prompt version, input tokens, cached input tokens, output tokens, latency and outcome. Providers return token counts in every response. Store them.
  • Compute cost when you write the log, using a price table in your own code, so a price change does not rewrite history.
  • Aggregate per tenant and per feature daily. This is the table your CEO and your pricing page need.
  • Set budgets and hard limits per tenant and per API key, with an alert at 80% and a cap that degrades gracefully, not a surprise bill.
  • Put cost into your eval run. When a prompt or model change raises cost per request above an agreed limit, it needs a sign-off, the same as a drop in quality.

A minimal version is one table and a few lines of code around your model client:

PRICES = {  # USD per 1M tokens; keep in code, version with git
    "mid-tier": {"in": 3.00, "cached_in": 0.30, "out": 15.00},
    "small":    {"in": 0.40, "cached_in": 0.04, "out": 1.60},
}

def call_cost(model, usage):
    p = PRICES[model]
    fresh = usage.input_tokens - usage.cached_input_tokens
    return (fresh * p["in"]
            + usage.cached_input_tokens * p["cached_in"]
            + usage.output_tokens * p["out"]) / 1_000_000

def log_call(ctx, model, usage, latency_ms, ok):
    db.insert("llm_calls", {
        "request_id": ctx.request_id, "tenant_id": ctx.tenant_id,
        "feature": ctx.feature, "step": ctx.step, "model": model,
        "prompt_version": ctx.prompt_version,
        "input_tokens": usage.input_tokens,
        "cached_input_tokens": usage.cached_input_tokens,
        "output_tokens": usage.output_tokens,
        "cost_usd": call_cost(model, usage),
        "latency_ms": latency_ms, "ok": ok,
    })

Field names differ by provider SDK. The idea does not.

The question to answer before you scale

The Cost gate of the 5 Gates Framework asks one question: does every request make money? It has two blocker checks. Cost per request and per customer is measured in production, not estimated in a spreadsheet. And AI cost per customer stays within your target gross margin at ten times current usage.

Run the numbers in this post on your own product. If the answer at 10x is "we would lose money on our biggest customers", it is much cheaper to find out now than in the month you sign them.

If you want a second pair of eyes on it, the two-week AI Production Readiness Audit includes an LLM cost model at 10x usage, built from your real traces. And if your prototype has other problems besides cost, start with why AI prototypes break at 100 users.

About the author

Yevhenii Datsiuk (Євгеній Дацюк) is an AI-to-Production CTO: CTO at i3 Engineering and Engineering Lead at PettersonApps. He takes AI prototypes to production for B2B SaaS companies and startups, and created the 5 Gates Framework for AI Production Readiness.

Keep reading

  • · 7 min read

    Why your AI prototype breaks at 100 users

    An AI prototype built in Lovable, Cursor, Bolt or n8n usually works for ten testers and fails at a hundred real users. The nine failures I see most, and the order to fix them.