Contents
Key concepts
Token arithmetic
Cost per request = input tokens × input price + output tokens × output price; output costs several times more per token (5× across Anthropic’s current price list). Count everything that is sent: system prompt, tool definitions, retrieved context, conversation history, retries, evaluation and judge traffic, and hidden reasoning tokens, which are billed as output. Tokenisers differ (Anthropic notes its newer tokeniser produces about 30% more tokens for the same text), so compare models on measured cost per task, not on list price per token.
Flow · 4 stepsFrom everything sent to cost per task
- Count everything sent Count the system prompt, tool definitions, retrieved context, history, retries, eval and judge traffic, and hidden reasoning tokens (billed as output).
- Price the request Cost per request = input tokens × input price + output tokens × output price; output costs several times more per token (5× across Anthropic's list).
- Measure cost per task Tokenisers differ (Anthropic's newer tokeniser produces about 30% more tokens for the same text), so compare on measured cost per task.
- Compare on task Compare models on measured cost per task, not on list price per token.
Data
| Step | Title | What happens |
|---|---|---|
| 1 | Count everything sent | Count the system prompt, tool definitions, retrieved context, history, retries, eval and judge traffic, and hidden reasoning tokens (billed as output). |
| 2 | Price the request | Cost per request = input tokens × input price + output tokens × output price; output costs several times more per token (5× across Anthropic's list). |
| 3 | Measure cost per task | Tokenisers differ (Anthropic's newer tokeniser produces about 30% more tokens for the same text), so compare on measured cost per task. |
| 4 | Compare on task | Compare models on measured cost per task, not on list price per token. |
Source: This page's text
| Box | Group | Detail |
|---|---|---|
| Everything sent | Input | system prompt, tools, context, history, retries |
| Token count | Compute | count everything sent |
| Cost per request | Compute | input × input price + output × output price |
| Measure cost per task | Compare | Anthropic's newer tokeniser: ~30% more tokens |
| Compare models | Compare | measured cost per task |
Source: This page's text
Cost per successful outcome
The unit that matters is cost per resolved ticket, accepted summary or approved document: model cost divided by success rate, plus human review, escalations and the cost of errors. Compare it with the value per outcome to get a margin, and track that margin as usage and prices change.
Prompt and prefix caching
Providers and self-hosted engines reuse computation for an identical token prefix. On Anthropic’s API, a 5-minute cache write costs 1.25× the base input price, a 1-hour write 2×, and a read about 0.1× (lower on some newer models); other providers discount cached tokens automatically. Put static content first (instructions, tools, documents) and variable content last, keep history append-only and never put timestamps or request IDs at the top. A semantic response cache is different: it returns stored answers for similar questions and risks wrong or cross-tenant answers.
Batch APIs
For work that can wait, OpenAI’s and Anthropic’s batch APIs charge 50% of the synchronous price, with results within 24 hours (often much sooner). Nightly enrichment, evaluation runs, backfills and non-urgent triage are natural fits; batch and caching discounts can stack.
Routing, cascades and distillation
Send easy requests to a cheap model and hard ones to an expensive model, either with a learned router (RouteLLM trains routers on preference data) or a cascade that escalates when a verifier or calibrated confidence check fails (FrugalGPT). Plot quality against cost across thresholds and account for the latency and double cost of escalated requests. For narrow, high-volume tasks, distil a large model’s outputs into a small fine-tuned model, checking the provider’s terms first.
Self-hosting economics
Self-hosted cost per request = GPU cost per hour ÷ requests served per hour at the utilisation you actually achieve. Capacity must cover peaks and redundancy, so average utilisation sits well below capacity (about one-third if you provision for peaks at 3× the average), and on-call, upgrades and evaluation need people. Self-hosting tends to win on cost only at high, steady volume, or when residency, latency control or customisation force it; hybrids are common.
Agent and reasoning multipliers
Reasoning modes add output tokens you do not see; agents re-send a growing context at every step, so input grows roughly quadratically with step count, and Anthropic reported agents using about 4× and multi-agent systems about 15× the tokens of a chat. Budget steps and tokens per task, and cache the shared prefix. Effort or thinking-budget settings are now the main dial: Anthropic reported Opus 4.5 at medium effort matching Sonnet 4.5’s best SWE-bench Verified score with 76% fewer output tokens, so measure cost per task at each effort level.
ROI and budgets for leads
Take a baseline before rollout, use controlled comparisons (A/B tests, staggered rollouts, difference-in-differences), count full cost (people, compute, licences, change management) and separate adoption, productivity and business impact; be candid about attribution limits. A budget usually has lines for API and GPU spend, people, data and labelling, evaluation, tooling, security and compliance, and a contingency for price and volume changes.
Worked examples
Estimate an email-triage bill, then cut it five-fold
An email-triage feature handles 200,000 emails a day at about 1,500 input and 200 output tokens each. Estimate the monthly cost at $3/$15 per million input/output tokens (a mid-tier model) and at $0.25/$1.25 (a small model). Then cut the mid-tier bill at least five-fold. Prices are assumptions; check current list prices.
Volume. Input 200,000 × 1,500 = 300M tokens a day; output 200,000 × 200 = 40M a day. Over 30 days: 9B input and 1.2B output tokens.
Baseline.
- Mid-tier: 9,000M × $3/M = $27,000; 1,200M × $15/M = $18,000 → $45,000 a month
- Small: 9,000 × $0.25 = $2,250; 1,200 × $1.25 = $1,500 → $3,750 a month
Note that output is only 12% of the tokens but 40% of the mid-tier bill.
Cutting the mid-tier bill, lever by lever:
| Lever | Assumption | Monthly cost |
|---|---|---|
| Start | $45,000 | |
| Cache the static 1,000-token prefix | effective input = 500 + 1,000 × 0.1 = 600 tokens (40%); input $27,000 → $10,800 | $28,800 |
| Shorter structured output | 200 → 60 tokens; output $18,000 → $5,400 | $16,200 |
| Batch API for non-urgent mail | 60% of volume at 50% off: × (0.4 + 0.6 × 0.5) = × 0.7 | $11,340 |
| Route to a small model | 70% handled by a model 12× cheaper, 10% of those escalate and pay twice | ≈ $4,860 |
Routing arithmetic: the expensive model still sees 30% + 7% = 37% of traffic → 0.37 × $11,340 = $4,196; the small model sees 70% at 1/12 the price → 0.7 × $11,340 / 12 = $662. Total ≈ $4,860, about 9× cheaper. With a 2.3-emails-per-second steady flow, the 5-minute cache stays warm, so cache writes are negligible. Rules that skip newsletters and auto-replies before any model call cut further.
Guard quality: run the regression eval suite on each lever, especially routing thresholds.
Follow-up: the bill doubles while traffic grows 10%. Attribute cost by feature, model and tenant, then check prompt growth (new few-shot examples, unbounded history), a collapsed cache-hit rate (someone put a timestamp at the top), retry storms, a routing change, longer outputs, eval jobs on production keys and abuse.
Flow · 6 stepsCutting the email-triage bill five-fold
- Baseline Start at $45,000 a month: 9B input and 1.2B output tokens over 30 days.
- Cache Cache the static 1,000-token prefix; effective input drops to 600 tokens, input $27,000 → $10,800.
- Shorter output Cut output from 200 to 60 tokens; output $18,000 → $5,400.
- Batch Send 60% of volume through the batch API at 50% off, a ×0.7 multiplier.
- Route Route 70% to a small model 12× cheaper; 10% of those escalate and pay twice.
- Result Total ≈ $4,860, about 9× cheaper; run the regression eval suite on each lever.
Data
| Step | Title | What happens |
|---|---|---|
| 1 | Baseline | Start at $45,000 a month: 9B input and 1.2B output tokens over 30 days. |
| 2 | Cache | Cache the static 1,000-token prefix; effective input drops to 600 tokens, input $27,000 → $10,800. |
| 3 | Shorter output | Cut output from 200 to 60 tokens; output $18,000 → $5,400. |
| 4 | Batch | Send 60% of volume through the batch API at 50% off, a ×0.7 multiplier. |
| 5 | Route | Route 70% to a small model 12× cheaper; 10% of those escalate and pay twice. |
| 6 | Result | Total ≈ $4,860, about 9× cheaper; run the regression eval suite on each lever. |
Source: This page's text
| Box | Group | Detail |
|---|---|---|
| Baseline bill | Baseline | $45,000 a month |
| Cache static prefix | Levers | input $27,000 → $10,800 |
| Shorter output | Levers | 200 → 60 tokens |
| Batch API | Levers | 60% of volume at 50% off |
| Route to small model | Levers | 70% at 1/12 price |
| ≈ $4,860 a month | Result | about 9× cheaper |
Source: This page's text
When does self-hosting beat the API?
Compare a hosted small model at $0.25/$1.25 per million tokens with self-hosting an open-weight model of similar quality. Requests average 1,500 input and 200 output tokens. Assume a rented GPU costs $2.50 an hour and sustains 5 requests a second for this request shape (measure this in a load test), capacity is provisioned for peaks at 3× average with at least 2 replicas, and operating it takes half an engineer ($100k a year, about $8,300 a month). Find the break-even daily volume.
Hosted cost per 1,000 requests: 1.5M × $0.25/M + 0.2M × $1.25/M = $0.375 + $0.25 = $0.625.
Self-hosted cost per 1,000 requests at full utilisation: 5 × 3,600 = 18,000 requests per GPU-hour → $2.50 / 18 = $0.139. At the roughly one-third average utilisation that 3× peak provisioning implies: about $0.42. The headline 4.5× saving shrinks to about 1.5× before any staff cost.
Monthly totals (30 days; 720 GPU-hours = $1,800 per GPU per month):
| Daily volume | Hosted | Peak req/s | GPUs | Self-hosted (GPUs + staff) |
|---|---|---|---|---|
| 200k | $3,750 | 6.9 | 2 | $3,600 + $8,300 = $11,900 |
| 1M | $18,750 | 34.7 | 7 | $12,600 + $8,300 = $20,900 |
| 1.5M | $28,125 | 52.1 | 11 | $19,800 + $8,300 = $28,100 |
| 2M | $37,500 | 69.4 | 14 | $25,200 + $8,300 = $33,500 |
Peak req/s = 3 × daily volume / 86,400; GPUs = max(2, ⌈peak / 5⌉).
Break-even ≈ 1.5M requests a day under these assumptions. Below it the API wins clearly; above it self-hosting saves 10–30%, more if batch work fills the night-time troughs. Because hosted prices keep falling, recheck the comparison every quarter. In a UK bank or healthtech the deciding factors are often data residency, latency control and fine-tuning rather than price, and the hybrid answer (a self-hosted small model for the high-volume simple path, a frontier API for the hard cases) is common.
Showing ROI for a coding-assistant rollout
You rolled out an AI coding assistant to 200 engineers: $40 per seat per month in licences plus about $30 per seat per month of usage-based API spend, and half an engineer ($100k a year) for enablement and governance. Loaded engineering cost is about $200k per engineer per year. How do you show whether it paid off?
Full cost. ($40 + $30) × 200 × 12 = $168,000 + $100,000 = $268,000 a year.
Measurement design. Roll out in waves (four cohorts a month apart) and use difference-in-differences: compare each cohort’s change in a basket of delivery metrics (lead time for changes, merged PRs per engineer-week, incident and rollback rate as a quality guardrail) with not-yet-treated cohorts over the same weeks. Suppose treated cohorts improve throughput by 12% and controls by 3%: an effect of 9%, 95% confidence interval 4%–14%, with no rise in change-failure rate.
Value. Engineering spend is 200 × $200k = $40M a year.
- Point estimate: 9% × $40M = $3.6M of capacity → ROI = (3.6 − 0.268) / 0.268 ≈ 12×
- Lower bound: 4% × $40M = $1.6M → ROI ≈ 5×
Lead with the conservative figure.
Candour about limits. Capacity is not cash: value is realised only if freed time goes to roadmap work or avoids hiring. PR counts can be gamed, novelty effects fade, and rework or security issues add hidden cost, so re-measure at six months, keep the quality guardrails and report adoption (weekly active users), productivity and business impact separately.
What changed recently
Frontier models are now sold on cost per task
Anthropic priced Claude Opus 5.5 at $4/$20 per million input/output tokens, 20% below Opus 5, but led with claims that at default settings it costs 40% less than Opus 5 on typical workloads and matches or beats rivals on several benchmarks at 20–40% of their cost per task. Default effort is medium, while most headline scores use max effort. Compare models on measured cost per successful task at the effort you will actually run, not on list price.
Effort settings become the main cost dial
With Claude Opus 4.5, Anthropic cut Opus pricing to $5/$25 (from $15/$75) and added an effort parameter; at medium effort it matched Sonnet 4.5’s best SWE-bench Verified score while using 76% fewer output tokens. Reasoning budgets now move cost per task more than list prices do, so cost models must include effort level, output length and retries.
Sparse attention arrives with a 50% price cut
DeepSeek released V3.2-Exp with DeepSeek Sparse Attention and cut its API prices by more than 50% while reporting benchmark parity with the previous model. It is a clear case of architecture changes for cheaper long-context inference flowing straight into price, and a reason to assume continued falls for a fixed capability in multi-year plans.
AI Index 2025: 280-fold fall in inference cost
Stanford’s AI Index reported that the cost of querying a model at GPT-3.5 level fell more than 280-fold between November 2022 and October 2024, with hardware costs falling about 30% a year and energy efficiency improving about 40% a year. Use such figures to argue for short payback periods and price-review clauses, while noting that reasoning and agent workloads can still raise total spend.
Pitfalls
- Forgetting that output tokens cost several times more than input, or leaving out tool definitions, history, retries and reasoning tokens.
- Comparing per-token list prices across models whose tokenisers and verbosity differ instead of measuring cost per task.
- Comparing a GPU-hour price with an API price without utilisation, redundancy and staff.
- Putting timestamps, user IDs or retrieved documents at the start of the prompt, which destroys prefix-cache hits.
- Downgrading to a cheaper model without a regression eval, or a one-off cost cut with no ongoing per-feature cost visibility.
- Reporting usage or licences as value; ignoring human-review and rework costs.
How interviewers probe it
- ‘Estimate the monthly cost’: show the arithmetic aloud, state price assumptions, then give a sensitivity range.
- ‘Cut it five-fold’: list levers in order of effort and saving, with the quality checks for each.
- ‘The bill doubled while traffic rose 10%’: a cost-attribution debugging exercise.
- ‘Should we self-host?’: break-even with utilisation, redundancy and staff; residency and customisation; the hybrid option.
- Lead: ‘The CFO wants spend halved in two quarters’, ‘Draft next year’s AI budget’, ‘Prove the copilots paid off’.
- Product: ‘Does this AI feature make economic sense?’ — cost per successful outcome against value and pricing.
Quiz
Three questions from this guide. Answer each in your head or out loud, show the model answer, then rate yourself. The cards join your practice deck and come back when they are due.
Estimate the monthly LLM cost of an email-triage feature handling 200k emails a day at about 1,500 input and 200 output tokens each. Then cut it five-fold. Follow-up: next month the bill doubles while traffic grows 10% — what do you check?
Model answer, written in a candidate's voice
- Volume math: 200k/day × 1,500 in + 200 out = 300M in + 40M out per day → ~9B in + 1.2B out per month (30-day month)
- Prices are explicit assumptions, not verified current list prices: at $3/M in and $15/M out ≈ $27k + $18k ≈ $45k/month; at $0.25/M in and $1.25/M out ≈ $3.75k/month — verify against current provider pricing
- Five-fold cut: small/fine-tuned model first with escalation to a larger model, shorter prompts and fewer examples, prompt caching for the static prefix, batch discounts for non-urgent work, short structured outputs, rules to skip auto-replies
- Include retries, judge/eval traffic and peaks in the estimate, not just the happy path
- Follow-up: bill doubles with only 10% traffic growth — attribute cost by feature/model/tenant, then check prompt growth, unbounded history, agent loops/retries, broken cache hits, routing changes, eval jobs on prod keys, and abuse
How do provider prompt caching and self-hosted prefix caching work, how do you structure prompts to benefit, and how is a semantic response cache different?
Model answer, written in a candidate's voice
- Prefix caching reuses KV for identical token prefixes, exact match from the start, with provider-specific TTLs and discounted cached-token pricing at some providers
- Self-hosted prefix caching does the same idea inside your own serving stack, with your own eviction/TTL and operational control
- Structure prompts static-first: system prompt, tools, documents, few-shot examples, then variable content last; no timestamps/random IDs early; append-only history
- Semantic caches return stored answers for similar queries, not reused computation; risks include wrong answers, cross-user leakage, staleness
- Mitigate semantic cache with similarity thresholds, tenant/user scoping, TTLs, invalidation, and track hit rate and savings
When would you self-host an open-weight model instead of using a hosted API? Walk through the decision for a UK healthtech or bank.
Model answer, written in a candidate's voice
- Lead with the decision rule: self-host only when residency/control or sustained cost beats the operational burden.
- UK healthtech/bank: start with UK GDPR/patient or financial data, zero-retention terms, regional endpoints and cloud-hosted models in UK/EU regions before self-hosting.
- Latency control and customisation: private network, predictable p99, fine-tuning, logits, constrained decoding and auditability.
- Cost at scale is utilisation-driven: idle GPUs are expensive; include autoscaling, on-call, upgrades, monitoring and security patching in break-even maths.
- Vendor dependence and quality gap: avoid lock-in, but do not self-host to chase frontier quality; small models may be worse.
- Hybrid pattern: frontier API for hard tasks, small self-hosted model for high-volume simple tasks, with a measured break-even.
You have finished this topic.
Reading
- Pricing (Claude API documentation)A current, detailed price sheet showing input/output, cache, batch and tool-use pricing in one place.
- Prompt caching (Claude API documentation)How prefix caching works, write and read multipliers, minimum lengths and how to structure prompts for hits.
- Batch API (OpenAI documentation)The asynchronous 50%-discount route for work that can wait up to 24 hours.
- FrugalGPT: How to Use Large Language Models While Reducing Cost and Improving PerformanceCascades, prompt adaptation and approximation as systematic cost levers.
- RouteLLM: Learning to Route LLMs with Preference DataHow to train and evaluate a strong/weak model router on a quality–cost curve.
- Distilling Step-by-Step! Outperforming Larger Language Models with Less Training Data and Smaller Model SizesEvidence that small distilled models can match large ones on narrow tasks.
- LLM inference prices have fallen rapidly but unequally across tasksTask-dependent rates of price decline, a nuance to add to the 10× rule of thumb.
- Effort (Claude API documentation)How effort levels trade output tokens for capability, which is why cost per task, not price per token, is the unit to compare.
Practise this topic
- Estimate the monthly LLM cost of an email-triage feature handling 200k emails a day at about 1,500 input and 200 output tokens each. Then cut it five-fold. Follow-up: next month the bill doubles while traffic grows 10% — what do you check?
- How do provider prompt caching and self-hosted prefix caching work, how do you structure prompts to benefit, and how is a semantic response cache different?
- When would you self-host an open-weight model instead of using a hosted API? Walk through the decision for a UK healthtech or bank.
- Design a router that sends easy requests to a cheap model and hard ones to an expensive model. How do you train and evaluate it?
- Your feature works with a large frontier model but costs too much. How would you distil it into a smaller model, and how do you know it’s good enough?
- Choose between three hosted models and one self-hosted open-weight model for a summarisation feature at 2 million requests a day. Describe the bake-off.
- LLM inference spend tripled in a quarter as usage grew. The CFO wants it halved within two quarters without hurting the product. Plan it.
- How do you tell whether an AI feature makes economic sense?
- How do you show that an AI investment paid off, including spread-out benefits such as staff copilots or coding assistants?
- When would you run open-weight models yourselves instead of calling a commercial API?
- Explain how a subword tokeniser such as byte-level BPE is trained and applied, then tell me how the choice of tokeniser shows up in cost, latency and quality for a product that serves Welsh, Turkish and English users, source code and numbers.
- Models now accept hundreds of thousands of tokens. When would you put everything in the context window instead of building retrieval, and what failure modes would you watch for?
- When is an orchestrator-plus-sub-agents architecture worth its cost compared with a single agent holding more tools?
- When does asking a model to reason step by step, or enabling a reasoning mode, help — and what does it cost?
- Your coding agent is connected to 25 MCP servers exposing about 300 tools, and tool definitions alone consume tens of thousands of tokens before the user’s request. Latency, cost and tool-selection accuracy are all suffering. What would you change?
- A document-QA product re-sends the same 60k-token contract across many sessions spread over hours, so GPU prefix-cache hits are rare. Would you offload KV cache to CPU memory or SSD and reload it instead of recomputing? Show the arithmetic.
- Model A costs $3 per million input tokens and $15 per million output tokens; model B costs $1 and $5. On your agentic task, A at medium reasoning effort averages 40k input and 6k output tokens with an 85% success rate; B averages 60k input and 14k output tokens with a 70% success rate. Each failure costs $2 of human handling. Which is cheaper per resolved task, and what else would you test?
- Design a pipeline that turns 50 million PDFs (born-digital reports, scanned forms, papers with tables and equations) into clean text for pretraining and retrieval. Choose between heuristic extractors and a vision-language OCR model, estimate the cost, and explain how you would measure quality.
- You are planning a three-year LLM roadmap. Epoch AI estimated that the price of reaching a fixed capability level fell between 9× and 900× per year depending on the benchmark. How should that shape decisions on self-hosting, long-term contracts and fine-tuning investments?
- Your coding agent runs for 300 turns and its context fills with tool output. Design a context-management strategy using what model APIs now offer (context editing, compaction, memory files), and explain how you keep prompt-cache hits high and check that nothing important is lost.
- Your product serves a 70B model in FP8 on Hopper GPUs. Leadership asks whether moving to Blackwell with NVFP4 weights will halve the serving cost. Explain what NVFP4 is and how you would answer.
- A product team wants an orchestrator–worker multi-agent ‘deep research’ feature. Given published figures that multi-agent systems use around 15 times the tokens of a chat turn, how would you decide whether it is worth building, and which levers would you use to control cost and latency?
- GPT-5 shipped as a fast model, a deeper reasoning model and a real-time router between them. Design and evaluate a similar router for your own assistant, which today sends every request to an expensive reasoning model.
- You run a coding-agent product on a flat £20-a-month plan. Your heaviest 5% of users now cost more in model spend than they pay, because long agentic tasks cost many times more than simple requests. Cursor’s 2025 move from request quotas to usage-based credit pools ended in an apology and refunds. Redesign your pricing and plan the rollout.
- After DeepSeek-R1 (MIT licence, January 2025) and OpenAI’s gpt-oss (Apache 2.0, August 2025), your CFO asks why you still pay a frontier API for an internal assistant handling 2 billion tokens a day. The 2026 AI Index says the best closed model leads the best open one by only about 3%. Make the recommendation.