Cost per Request
Attribute token, retrieval, and tool costs to each request for unit economics.
In plain words
Cost per request is how much money one answer costs, adding up everything the AI and its helpers used to make it.
Think of it like…
A restaurant costing a dish: ingredients (input tokens), cooking time and labour (output tokens, compute), packaging (retrieval, tools) and the waste from dishes sent back (retries and failed requests). You price and optimise per plate.
Where you’ve seen it
Illustrative prices: $2.50 per million fresh input tokens, $0.25 per million cached input tokens, $10 per million output tokens. A support request sends 3,100 input tokens (2,400 of them a stable prefix of instructions and policy) and receives 420 output tokens. Without caching the LLM cost is 3,100 × 2.5/1M + 420 × 10/1M = $0.00775 + $0.0042 = $0.01195. Adding $0.002 for reranking and $0.0003 for embedding and vector search gives $0.01425 all-in, or $712.50 a day at 50,000 requests. Enabling prompt caching of the 2,400-token prefix gives 2,400 × 0.25/1M + 700 × 2.5/1M + $0.0042 = $0.00655 for the LLM (−45%). A concise-answer instruction cuts average output from 420 to 300 tokens, so LLM cost becomes $0.00535 and all-in $0.00765, or $382.50 a day: a 46% saving, from $21,375 to $11,475 a month. Cost per resolved conversation (60% resolution) falls from $0.0238 to $0.0128.
Words you’ll hear
- Input vs output token price
- Output tokens are typically several times more expensive than input tokens.
- Cached input price
- A discounted rate for prompt prefixes the provider has seen recently.
- Cost per outcome
- Spend divided by successful results (resolved tickets), not by requests.
- Cost attribution
- Splitting spend by feature, customer, model and prompt version.
Visual diagram
Theory & deep dive
The cost formula and attribution
For each model call: cost = fresh input tokens × input price + cached input tokens × cached price + output tokens × output price (plus any separate price for reasoning tokens, which are billed as output on many models and can dominate a reasoning-heavy request). Add embeddings, vector database and reranker costs, tool and third-party API fees, and a share of infrastructure. For agents, sum over all steps: a loop of 8 model calls with growing context can cost an order of magnitude more than a single call, because each call re-sends the accumulated history.
Compute cost from token usage logged in traces multiplied by a maintained price table (versioned by model and date), and tag each request with feature, customer tier, prompt version and experiment variant so you can attribute spend. Track percentiles as well as the mean (a few long-context or looping requests can dominate the bill), cost per successful outcome, and the cost of failures and retries. Set budgets and alerts per feature and per customer, with hard limits on max tokens, agent steps and context size.
Each step re-sends history: step 1 sends 2,000 tokens, step 2 sends 3,000, step 3 sends 4,000 and so on. An 8-step run sends 2,000 + 3,000 + … + 9,000 = 44,000 input tokens, about $0.11 at $2.50 per million, versus $0.005 for a single 2,000-token call. Prompt caching and context compaction reduce this.
Levers and trade-offs
In rough order of return: prompt caching for long stable prefixes (system prompt, policy, few-shot examples, tool definitions: here a 45% LLM saving); shorter outputs through concise instructions, structured fields and max-token limits; model routing (a small model for easy or classification-like requests, a larger one for hard cases, with a fallback); context trimming (fewer, reranked chunks, summarised history); batch APIs for non-urgent work (typically a substantial discount in exchange for slower turnaround); response caching for repeated questions; distillation or fine-tuning a smaller model for high-volume narrow tasks; and self-hosting only when volume and utilisation justify the infrastructure.
Every lever has a quality or latency trade-off, so measure it: run the golden set and an A/B test before and after, and track cost per *good* outcome rather than raw cost. A cheaper model that resolves fewer tickets raises cost per resolution. Watch the hidden multipliers (retries, tool loops, over-long context, duplicated calls from retries at several layers), re-check prices regularly since they change, and keep a unit-economics view that includes gross margin for paid features.
Option A: $0.00765 per request at 60% resolution = $0.01275 per resolved conversation. Option B uses a cheaper model at $0.0045 per request but resolves 40% = $0.01125 per resolution, a small saving that sacrifices 20 points of resolution, which is usually a bad trade.
How it works, step by step
Step 1 of 41. Log tokens and prices
Record fresh, cached and output tokens per call and keep a versioned price table.
- Include
- retrieval and tools
When to use it & trade-offs
What it is
Cost per request is the all-in spend to serve one user request: input tokens (fresh and cached), output tokens (usually priced several times higher), embeddings, retrieval and reranking, tool and API calls, and infrastructure, summed across every model call an agent makes. Tracking it per request, per feature and per successful outcome turns the AI bill into unit economics: you can see what drives spend, forecast it with volume and price changes, and decide which optimisations (prompt caching, shorter outputs, routing, batching) pay off.
Why it matters: LLM features have real marginal cost: a popular feature can cost more than it earns, an agent loop can multiply spend by ten, and a model upgrade can change prices overnight. Without per-request cost tracking, teams discover problems from the monthly invoice. Understanding the cost formula also guides design: where tokens are spent, which parts are cacheable and when a smaller model is good enough.
When to reach for it
- Forecasting spend and pricing AI features
- Prioritising optimisation work by savings
- Setting budgets and alerts per feature or customer
When to avoid or be careful
- Tracking only the monthly invoice
- Cutting cost with a weaker model without checking resolution rates
- Ignoring agent loops and retries in cost estimates
Cost-reduction levers
Strengths: Large saving with no quality change.
Watch out: Requires prefix stability; cache expiry.
Strengths: Big savings per request.
Watch out: Risk of quality loss; routing logic to maintain.
Strengths: Lower unit price.
Watch out: Slower turnaround; not for interactive use.
Interview signals & numbers to know
When this topic comes up
- “Our LLM bill doubled”
- “What does one conversation cost us?”
- “Cost per resolved ticket”
- Prompt caching
- Agent token blow-up
Benchmarks & rules of thumb
- $0.01425 → $0.00765
- all-in cost per request before and after in the example
- −45%
- LLM cost from caching a 2,400-token prefix
- 46%
- total daily saving from caching plus shorter answers
Common mistakes & follow-ups
Common interview mistakes
- Pricing a feature from the cost of one call when the agent makes eight.
- Optimising cost per request while cost per outcome rises.
- Using stale prices after a provider changes its rate card.
Likely interviewer follow-ups
- How would you reduce the LLM cost of a high-volume feature?
- Why can agents be much more expensive than single calls?
- How do you decide whether a cheaper model is worth it?
Knowledge check
Put it into practice
Practice related interview Q&A
Apply Cost per Request with generative AI interview Q&A and hands-on practice.