How do you estimate the cost of running an AI-powered feature in production?
Estimate the cost of running an AI-powered feature in production by modeling per-request compute, storage, and operational overhead. Learn a practical formula, worked example, and common optimizations to forecast monthly spend and control surprises.

TL;DR
- Break cost into model API or self-host compute, infrastructure and storage, and operational overhead like monitoring and retraining.
- Compute per-request cost from tokens or inference time, then multiply by expected volume and add fixed monthly costs.
- Use caching, batching, quantization, and lower-cost models to reduce per-request spend without harming SLAs. Key tradeoffs: accuracy and latency versus cost; one-time training amortization versus ongoing inference fees.
In this question, we will learn how to estimate the cost of running an AI-powered feature in production so you can give a clear forecast and justify architectural choices.
We will cover the following:
- Direct answer
- The intuition (an analogy that makes it click)
- How it actually works (a concrete worked example)
- Cost comparison and optimization levers
- Tradeoffs and failure modes
- Questions the interviewer might ask
Direct answer: Estimate per-request cost by summing the model inference cost and infrastructure amortized cost, then multiply by expected request volume and add fixed operational overheads. Present a best, expected, and worst monthly scenario and show sensitivity to tokens, latency, and peak load.
The intuition (an analogy that makes it click)
Think of the feature like running a cafe. Each customer order is a request. The ingredients and labor per order are the model compute and instance time. Rent, utilities, and staff training are the fixed operational overheads. If orders get larger or more frequent you need more cooks or faster machines, and your per-order cost changes. We want a recipe that converts order size and rate into a monthly bill.
How it actually works (the real mechanics, with one concrete worked example)
There are three main buckets to estimate:
- Model inference cost: either third-party API pricing (usually tokens or calls) or self-hosted compute (instance hours, GPU utilization). Use whichever applies.
- Infrastructure and storage: instance costs, container orchestration, vector database storage and queries, egress fees.
- Operational overhead: monitoring, logging, SRE time, backups, retraining and dataset storage, and an error buffer.
We create a per-request formula. Let the per-request inference resource usage be input tokens and output tokens , and API prices be per 1k input tokens and per 1k output tokens. For self-hosted inference, use instance cost per hour and measured throughput in requests per hour . Then per-request costs are:
For API model:
For self-hosted model:
Add operational overhead amortized per request. If monthly fixed operational cost is and expected monthly requests are , add to each request.
Worked example: suppose you use a hosted LLM with = 0.02 USD per 1k tokens and = 0.06 USD per 1k tokens. Typical request has and . Expected monthly volume requests. Monthly fixed costs = 2,000 USD for monitoring, storage, and backups.
Compute per-request API cost:
Add amortized fixed cost:
Total per-request = . Monthly forecast = = 10,000 USD.
If you instead self-host on an inference fleet where one GPU instance costs = 3.50 USD per hour and supports requests per hour (roughly one request every five seconds including batching), then instance portion per request is = 0.00486 USD. Add storage and egress say per request and the same amortized fixed cost, total about . Monthly cost would be = 3,600 USD plus instance reservation or autoscaling overhead.
| Option | Per-request cost | Monthly cost (200k req) |
|---|---|---|
| Hosted API | $0.05 | $10,000 |
| Self-host GPU | $0.018 | $3,600 |
Cost comparison and optimization levers
The main levers you can pull are:
- Reduce tokens per request by trimming prompts, templates, or compressing conversation history.
- Cache repeated queries or deterministic responses to avoid repeated inference.
- Batch requests on self-hosted GPUs to improve throughput and lower per-request instance cost.
- Use smaller or distilled models for lower-criticality paths.
- Quantize models to run on cheaper instances or CPUS when latency and accuracy allow.
- Negotiate volume discounts with API providers or buy reserved instances for predictable self-hosted workloads.
Table of typical savings:
| Optimization | Typical per-request reduction |
|---|---|
| Prompt trimming | 10-40% fewer tokens |
| Caching common responses | up to 90% requests avoided for repeated queries |
| Batching on GPU | 20-60% lower instance cost per request |
| Model distillation | 30-80% compute reduction at some accuracy loss |
Tradeoffs and failure modes
Every optimization changes other properties. Smaller models may increase hallucinations. Caching improves cost but can return stale data. Batching improves cost but can add latency at low traffic. Always measure impact on error rates, latency percentiles, and user experience.
Questions the interviewer might ask
Some follow-up questions you might get:
How do you estimate peak versus average cost? Estimate both a baseline and a 95th percentile peak. Use traffic patterns, seasonal multipliers, and a safety margin. Model autoscaling behavior to account for cold starts and provisioning time.
How would you amortize a one-time training cost? Divide the training cost by the expected useful lifetime or expected number of predictions that benefit from the training. Present scenarios with conservative and optimistic usage forecasts.
When should we choose hosted API versus self-hosting? Use hosted APIs for fast time to market and low operational burden. Self-host when volume and latency needs make per-request prices prohibitive or when you need data control and custom models.
How do you account for monitoring and SRE work? Put realistic salaries or SRE team allocation into fixed monthly costs. Include alerts, on-call rotations, and incident response amortized into the feature cost.
How do you avoid surprises from long-tail requests? Enforce max token limits, implement quotas, and have a cheaper fallback. Track tail percentiles of output length and cost to detect trends.
Some things to note:
- Use sensitivity analysis: show how costs change if tokens or volume shift by 20 to 50 percent.
- Include a 10 to 30 percent buffer in early forecasts to account for unknowns.
What the interviewer is really testing
They want to see you break a complex system into measurable cost drivers and produce a defensible forecast. You should demonstrate awareness of operational realities like variability, SLAs, and tradeoffs between accuracy, latency, and spend. Clear assumptions, a worked example, and mitigation strategies are what make the answer practical and trustworthy.
Related questions
How would you rate the quality of this article?
Prepare for your AI engineering interview
This is one of many detailed questions and explainers on StudyAIDesign. Browse the full set, work through the curriculum, and walk into your interview ready.