AI Feature Production Cost: Step-by-Step Guide
In this article
This guide walks you through estimating the total cost of running an AI feature in production, covering compute, storage, data transfer, and maintenance. You’ll learn what to track, how to estimate each component, and how to combine them into a monthly or annual figure.
What You'll Need
- Your AI model’s inference time (average latency per request, in milliseconds)
- Expected request volume (requests per day or month)
- Cloud provider pricing for compute (per hour or per million requests), storage (per GB-month), and data transfer (per GB)
- Model size (number of parameters or GB of memory) to estimate GPU/CPU requirements
- Details on your deployment architecture (serverless vs. dedicated instances, number of replicas)
- Any third-party API costs if you use external services (e.g., LLM APIs)
Step-by-Step
- Define your request volume and usage pattern. Estimate the number of inference requests per month. If you have historical data, use that; otherwise, project based on user growth. Also note peak vs. average load—this affects whether you need autoscaling.
- Measure or estimate inference latency and throughput. Run a benchmark on your target hardware (or use provider benchmarks) to get the average time per request in milliseconds. Also determine how many requests a single instance can handle per second (throughput). This is critical for compute sizing.
- Calculate compute cost. For serverless (e.g., AWS Lambda, Google Cloud Run), cost = (requests per month) × (average execution time in seconds) × (memory allocated in GB) × (price per GB-second). For dedicated instances (e.g., EC2, GKE), cost = (number of instances) × (hours per month) × (instance hourly price). Include GPU instances if your model requires them.
- Add storage costs. Estimate the storage for model weights, embeddings, and any user data. Cost = (storage in GB) × (price per GB-month). Don’t forget backups and snapshots, which typically add 20–50%.
- Include data transfer (egress) costs. Most cloud providers charge for data leaving their network. Estimate the average response size (e.g., 1 KB) and multiply by the number of requests to get monthly egress in GB. Then multiply by the per-GB price. Also include any ingress if you’re moving large datasets.
- Account for development and maintenance. This is often overlooked. Estimate the time spent on monitoring, retraining, updating dependencies, and fixing bugs. Multiply hours by your fully loaded engineering cost (salary + benefits + overhead). This is a real cost, though often not in the cloud bill.
- Add third-party API costs if applicable. If you’re using a hosted LLM or other API, calculate cost = (number of tokens or requests) × (price per token/request). Include both input and output tokens if applicable.
- Sum everything up. Add compute, storage, egress, maintenance, and third-party costs to get a monthly total. Multiply by 12 for annual cost. Don’t forget to include taxes and any committed-use discounts you might have.
- Build a simple spreadsheet model. Create columns for each cost category, input your estimates, and use formulas to sum them. This allows you to adjust assumptions and see the impact on total cost.
Common Mistakes
- Forgetting egress costs: Data transfer out of the cloud can be surprisingly high, especially for image or video AI features.
- Underestimating latency: Using a single benchmark number without considering tail latency (p99) can lead to under-provisioning compute.
- Ignoring idle time: For dedicated instances, you pay for the whole hour even if you use only 10 minutes.
- Not accounting for retraining: Models drift and need retraining, which incurs compute and storage costs.
- Mixing up units: Confusing MB and GB, or milliseconds and seconds, can throw off your calculations by orders of magnitude.
- Assuming linear scaling: Doubling requests may not double cost if you have fixed infrastructure.
Tips
- Use a cost calculator from your cloud provider to get accurate pricing for your region.
- Consider using spot instances or preemptible VMs for non-critical batch processing to save up to 60–90% on compute.
- Implement autoscaling to match capacity with demand, reducing idle costs.
- Monitor your actual usage for the first few months and adjust your estimates accordingly.
- If using a serverless platform, optimize your code to reduce execution time—this directly reduces cost.
- Set up budget alerts in your cloud account to avoid surprise bills.
Troubleshooting
- Costs are higher than expected: Check for hidden costs like logging, monitoring, and container registry storage. Also review your autoscaling policies—they might be too aggressive.
- Estimates are wildly inaccurate: Revisit your request volume assumption. If you’re in early stages, use a range (low, medium, high) and calculate for each.
- Cannot get a consistent latency number: Run benchmarks under load, not just with a single request. Use a load testing tool to simulate realistic traffic.
- Third-party API costs vary: Many APIs have tiered pricing. Check if you’re in a higher tier after a certain volume and adjust your estimate.
- Not sure about instance sizing: Start with a conservative estimate (e.g., one GPU instance) and scale as you collect real usage data.
Frequently Asked Questions
How do I estimate the number of requests per month?
Use your analytics or product metrics. If you’re pre-launch, estimate based on expected user count and average usage per user. Multiply daily active users by average requests per user per day, then by 30.
Should I include development time in the cost?
Yes, if you want a total cost of ownership. Development, maintenance, and monitoring are real costs. Many teams separate them for budgeting, but they should be part of the overall calculation.
What if my model uses both CPU and GPU?
You’ll need to account for both. For example, a GPU instance might have CPU cores included, but if you need additional CPU for preprocessing, add that separately.
How do I handle costs for multiple environments (dev, staging, prod)?
Calculate production costs as the main figure, but add a percentage (e.g., 10–20%) for dev and staging environments that run intermittently.
Can I use a simple formula for compute cost?
For serverless: Cost = (requests per month) × (average duration in seconds) × (memory in GB) × (price per GB-second). For dedicated: Cost = (number of instances) × (hours per month) × (instance price).
How often should I recalculate?
At least quarterly, or whenever your request volume changes significantly. Also review after any major infrastructure changes.