Introduction
Welcome to your next lesson in the "AI Economics & Cost Optimization" module.
In our last session, we established the fundamental drivers of AI costs: token-based pricing, the price difference between input and output, and the role of the context window. You now understand why costs accrue when using Large Language Models.
Today, we move from theory to practice. Our goal is to answer a critical question for any product architect: "What will this AI feature cost to run each month?" Your learning outcome is to calculate the monthly inference cost for an AI feature given a user base, usage patterns, and token count.
This skill is essential for your role. Before you design an elaborate, stateful AI chat experience, you need to model its financial viability. This calculation allows you to build a business case for your design decisions, balancing user experience with economic reality.
1. The Core Formula for a Single AI Request
Let's start with the cost of a single interaction with an AI model. As we discussed, the total cost is the sum of what you pay to send information to the model (input) and what you pay to get a response from the model (output).
Most AI providers, like OpenAI and Anthropic, price their models per 1 million tokens. Therefore, the formula for a single request looks like this:
- Input Cost = (
Number of Input Tokens/ 1,000,000) ×Price per 1M Input Tokens - Output Cost = (
Number of Output Tokens/ 1,000,000) ×Price per 1M Output Tokens - Total Cost per Request =
Input Cost+Output Cost
This article provides a very clear template for this calculation.
AI Token Cost Calculator (2025): Formula + Free Tools - Evalics
The article 'AI Token Cost Calculator' from Evalics lays out the fundamental formula for calculating token costs. It includes a simple table that makes the components of the calculation easy to understand.
Please read the section titled 'Token Cost Calculator: Formula + Template'. Focus on the 'The Formula' and 'Copy/Paste Template' parts. You don't need to read the 'Quick Example' just yet, as we will build our own.
To see this formula in action, let's watch a short video segment that walks through a live calculation for a single API call.
LLM Pricing Explained (OpenAI API Pricing)
In this clip from 'LLM Pricing Explained', Tommy Eberle demonstrates exactly how to apply the token prices to the token counts from a real API call to find the total cost of one interaction.
Watch the segment from 05:37 to 06:27. Notice how he takes the input and output token counts and combines them with the price-per-million-tokens to arrive at the final cost for that single API call.
2. From a Single Request to Monthly Operational Cost
Calculating the cost for one request is useful, but the real power comes from scaling this up to predict the monthly operational cost of a feature across your entire user base. This is how you forecast budgets and determine if a feature is sustainable.
To do this, we need three additional pieces of information:
- Number of Users: How many people will use this feature?
- Usage Frequency: How often will each person use it?
- Time Period: We'll be calculating for a month (typically assumed to be 30 days).
The scaled-up formula is:
Total Monthly Cost = Cost per Request × Number of Users × Avg. Requests per User per Month
Let's look at a comprehensive example that puts all these pieces together.
LLM Cost Estimation Guide: From Token Usage to Total ...
The article 'LLM Cost Estimation Guide' provides an excellent, detailed walkthrough of calculating the monthly cost for a hypothetical recommendation system. It clearly shows the transition from cost-per-query to total monthly spend.
Please read the section titled '2. Cost Calculation Table:'. It's located under the main 'Cost Calculation for a LLM based System' heading. Focus on how the author scales the 'Cost per Query' up to the 'Total Monthly Cost' using the number of users and daily queries.
As the article demonstrates, the process is straightforward:
- Calculate the cost for a single, representative query.
- Determine the total number of queries per day (
Users×Queries per User per Day). - Multiply the daily query count by 30 to get the monthly query count.
- Multiply the total monthly queries by the cost per query to find the total monthly cost.
The table in the article also effectively highlights the dramatic cost difference between a high-end model (GPT-4o) and a more economical one (GPT-4o-mini), a crucial architectural trade-off we'll explore more in the next lesson.
3. Guided Practice: Modeling a Fintech AI Assistant
Now, let's apply this yourself. Imagine you are the architect for a new feature in a fintech mobile app: an "AI Financial Assistant" that users can chat with to ask questions about their spending habits.
Let's define the parameters for our cost model.
Feature Scenario: AI Financial Assistant
- User Base: The app has 10,000 active users who will have access to this feature.
- Usage Pattern: On average, an active user makes 8 requests (asks 8 questions) to the assistant per month.
- Token Count per Request:
- Input: 1,500 tokens. This includes the system prompt ("You are a helpful financial assistant..."), a summary of the last few messages for conversation history, and the user's current question.
- Output: 250 tokens. This is the AI's generated answer.
Model Pricing (Illustrative):
- Model A (Premium): GPT-4o
- Input Price: $5.00 per 1M tokens
- Output Price: $15.00 per 1M tokens
- Model B (Economy): GPT-4o-mini
- Input Price: $0.15 per 1M tokens
- Output Price: $0.60 per 1M tokens
Let's calculate the monthly cost step-by-step.
Step 1: Calculate the Cost per Request for Each Model
Model A (Premium):
- Input Cost: (
1,500/ 1,000,000) * $5.00 = $0.0075 - Output Cost: (
250/ 1,000,000) * $15.00 = $0.00375 - Total Cost per Request (Model A): $0.0075 + $0.00375 = $0.01125
Model B (Economy):
- Input Cost: (
1,500/ 1,000,000) * $0.15 = $0.000225 - Output Cost: (
250/ 1,000,000) * $0.60 = $0.00015 - Total Cost per Request (Model B): $0.000225 + $0.00015 = $0.000375
Step 2: Calculate the Total Monthly Requests
- Total Monthly Requests =
Users×Requests per User per Month - Total Monthly Requests = 10,000 × 8 = 80,000 requests
Step 3: Calculate the Total Monthly Cost for Each Model
Model A (Premium):
- Total Monthly Cost =
Cost per Request×Total Monthly Requests - Total Monthly Cost = $0.01125 × 80,000 = $900 per month
Model B (Economy):
- Total Monthly Cost = $0.000375 × 80,000 = $30 per month
This simple model gives you, the architect, immediate and powerful insight. The choice of model results in a 30x difference in monthly operational cost ($900 vs. $30). This allows you to have an informed discussion with your team: "Is the performance of the premium model worth an extra $870 every month for this feature?"
Conclusion
You can now translate a feature concept into a concrete financial forecast. This is a crucial bridge between design, engineering, and business strategy.
Key Takeaways:
- The Cost Formula is Your Foundation: The total cost of an AI request is always the sum of its input and output token costs.
- Scale with User Data: To find the monthly cost, you scale the single-request cost by your total number of users and their average usage frequency.
- Modeling Informs Decisions: Creating a simple cost model, like the one we just did, is an essential architectural step. It makes the economic trade-offs of your design choices explicit and quantifiable.
- Model Choice is a Key Variable: The cost difference between different tiers of AI models is not incremental; it can be orders of magnitude. Your calculations will directly inform which model is appropriate for a given task.
Next Steps
Now that you can calculate costs, the next logical question is how to manage them strategically. In the next lesson, we will delve into model tiering, a powerful strategy for balancing cost and performance by intelligently routing different types of user requests to different AI models.