Medium6 min readUpdated 2026-08-12

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.

Hand-drawn diagram showing model, infra, and usage boxes and arrows connecting them
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:

  1. Model inference cost: either third-party API pricing (usually tokens or calls) or self-hosted compute (instance hours, GPU utilization). Use whichever applies.
  2. Infrastructure and storage: instance costs, container orchestration, vector database storage and queries, egress fees.
  3. 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 tint_{in} and output tokens toutt_{out}, and API prices be pinp_{in} per 1k input tokens and poutp_{out} per 1k output tokens. For self-hosted inference, use instance cost per hour cinstc_{inst} and measured throughput in requests per hour rhr_{h}. Then per-request costs are:

For API model:

costreq=tin1000pin+tout1000poutcost_{req}=\frac{t_{in}}{1000}p_{in}+\frac{t_{out}}{1000}p_{out}

For self-hosted model:

costreq=cinstrh+coststorage\/req+costegress/reqcost_{req}=\frac{c_{inst}}{r_{h}}+cost_{storage\/req}+cost_{egress\,/req}

Add operational overhead amortized per request. If monthly fixed operational cost is CfixedC_{fixed} and expected monthly requests are NN, add Cfixed/NC_{fixed}/N to each request.

Worked example: suppose you use a hosted LLM with pinp_{in} = 0.02 USD per 1k tokens and poutp_{out} = 0.06 USD per 1k tokens. Typical request has tin=800t_{in}=800 and tout=400t_{out}=400. Expected monthly volume N=200,000N=200,000 requests. Monthly fixed costs CfixedC_{fixed} = 2,000 USD for monitoring, storage, and backups.

Compute per-request API cost:

costreq=8001000×0.02+4001000×0.06=0.016+0.024=0.04cost_{req}=\frac{800}{1000}\times0.02+\frac{400}{1000}\times0.06=0.016+0.024=0.04

Add amortized fixed cost:

Cfixed/N=2000200000=0.01C_{fixed}/N=\frac{2000}{200000}=0.01

Total per-request = 0.050.05. Monthly forecast = 0.05×2000000.05\times200000 = 10,000 USD.

If you instead self-host on an inference fleet where one GPU instance costs cinstc_{inst} = 3.50 USD per hour and supports rh=720r_{h}=720 requests per hour (roughly one request every five seconds including batching), then instance portion per request is 3.50/7203.50/720 = 0.00486 USD. Add storage and egress say 0.0030.003 per request and the same 0.010.01 amortized fixed cost, total about 0.0180.018. Monthly cost would be 0.018×2000000.018\times200000 = 3,600 USD plus instance reservation or autoscaling overhead.

OptionPer-request costMonthly 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:

OptimizationTypical per-request reduction
Prompt trimming10-40% fewer tokens
Caching common responsesup to 90% requests avoided for repeated queries
Batching on GPU20-60% lower instance cost per request
Model distillation30-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.

Unexpected spikes in usage or a shift to longer outputs are the most common causes of runaway bills. Add hard limits and billing alerts, and model fallback to a cheaper tier when you approach thresholds.

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

#llmops#cost-estimation#inference-cost#infrastructure

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.

Follow along for new questions and explainers:Instagram