arrow_backAll articles
How to Calculate the Real Cost of Your AI App Before You Launch It
Tutorials

How to Calculate the Real Cost of Your AI App Before You Launch It

Javier Echeverria··6 min read

One of the most common mistakes people make when building something with an AI API is underestimating what it's going to cost in production. It's not because they're careless, it's because the way AI APIs are priced makes it genuinely easy to miscalculate if you're not thinking about it the right way from the start.

You test your app with a handful of requests, the bill looks manageable, and then you launch and suddenly you're looking at numbers that don't match what you expected at all. This article is about how to avoid that situation by building a cost estimate that actually reflects what production looks like.

The basic formula most people skip

The cost of using an AI API comes down to three things multiplied together: how many tokens you send per request, how many tokens you get back per request, and how many requests you send per day. That's it at the core, but each of those three things is less obvious than it sounds.

Most people think about the cost of a single request and then multiply by the number of users or requests they expect. What they miss is that the cost of a single request isn't a fixed number. It depends on how long the conversation history is, how detailed the system prompt is, how much context you're passing in, and how long the model's response ends up being. All of those vary, and they vary in ways that tend to push costs up rather than down as usage grows.

Start with your actual token counts, not estimates

The first thing to do before building any cost model is to measure what a realistic request actually looks like in tokens, not guess based on word counts or character counts.

Take your system prompt and count its tokens. Take a realistic sample of user messages, not the shortest possible ones but something representative of what real users actually send, and count those. Then look at the responses your model generates for those inputs and count those too. Add them all together and you have your baseline tokens per request.

This number is almost always higher than people expect, especially the output side. If you're building something where the model writes long responses, those output tokens add up fast and they're usually priced higher than input tokens.

The Tokens per Dollar Calculator on Prompt Toolbox is useful at this stage because it lets you see exactly how many tokens your budget gets you for each model, which helps you work backwards from a cost target to figure out how much room you have per request.

The conversation history problem

Here's the part of cost estimation that bites people hardest. If your application maintains conversation history, meaning it passes previous messages along with each new request so the model has context, your token count per request grows with every message in the conversation.

The first message in a conversation might cost 500 tokens. The second exchange might cost 900 because now you're passing the first exchange as history. The fifth exchange might cost 2,000 tokens because the history is getting long. If you estimated your costs based on single-turn interactions and you're actually running multi-turn conversations, your real costs could be three or four times your estimate.

The way to account for this is to estimate an average conversation length in exchanges, calculate the token cost for each exchange including the growing history, and then average those out across the conversation. It's a bit more work than a simple per-request estimate but it gives you a number that actually reflects how your app behaves.

Input tokens versus output tokens are not the same price

This is something that catches people off guard when they first look at API pricing. Almost every major AI provider charges different rates for the tokens you send versus the tokens the model generates. Output tokens are typically more expensive, sometimes by a factor of two, three, or more depending on the model.

This means the ratio of input to output in your typical request matters a lot for your cost estimate. An application where users send short questions and get long detailed answers is going to have a very different cost profile than one where users send long documents and get short summaries, even if the total token count per request is similar.

According to Google's AI pricing page for Gemini, the gap between input and output pricing varies by model tier, which is why looking at the full pricing breakdown rather than just a single per-token number is important when you're comparing models for a cost-sensitive application.

How to estimate request volume realistically

The other side of the cost equation is how many requests you actually send. This sounds simple but it has a few traps.

First, think about what counts as a request. In some applications, every user message generates one API call. In others, a single user interaction might trigger multiple calls behind the scenes, for example if you're doing a retrieval step, then a summarization step, then a final response generation step. Each of those is a separate billable request.

Second, think about your peak to average ratio. If your average is one thousand requests per day but you have traffic spikes that hit five thousand requests in an hour, you need to make sure your cost model accounts for those peaks, especially if you're on a pricing tier that charges differently at high volumes.

Third, think about failed requests and retries. In production, some percentage of requests will fail and need to be retried. Those retries cost tokens too, and depending on your retry logic they can add a meaningful amount to your total.

Build a simple spreadsheet before you launch

The most practical thing you can do before launching anything with an AI API is to put together a simple cost model in a spreadsheet. The columns you need are: average input tokens per request, average output tokens per request, input price per thousand tokens, output price per thousand tokens, expected requests per day, and total daily cost.

Run that calculation for your best case, your expected case, and your worst case in terms of request volume and conversation length. The spread between those three numbers tells you a lot about your risk. If the worst case is ten times the expected case, you have a cost structure that could surprise you badly. If the worst case is two times the expected case, you have something more manageable.

Also calculate what happens to your costs as you scale. Some applications have costs that scale linearly with users, which is predictable. Others have costs that grow faster than users because heavier users generate longer conversations, which is harder to plan for.

A few things that consistently blow up cost estimates

System prompts are one. People write detailed system prompts during development without thinking much about the token cost, and then those prompts get sent with every single request forever. A system prompt that's two thousand tokens costs you two thousand tokens on every request, even the simplest ones.

Document context is another. If your application lets users paste in documents or reference materials, the token count per request can jump dramatically. A single page of a PDF might be seven hundred to a thousand tokens. A ten-page document is seven thousand to ten thousand tokens, on top of everything else in the request.

Long model responses are a third. It's easy to underestimate how many tokens a detailed response uses. A thorough answer to a complex question might be eight hundred to twelve hundred tokens, and if that's your typical output length, it's going to dominate your cost structure.

The Token Counter on Prompt Toolbox can help you measure all of these before they become surprises, by letting you paste in your actual prompts and documents and see the real token counts before you build your cost model around guesses.

The cost estimate you do before launch is worth the hour it takes

It doesn't need to be perfect. It needs to be realistic enough that you're not shocked by your first production bill, and specific enough that you know which variables to watch as you scale. Token counts, request volume, conversation length, and the input-output ratio are the four things that determine almost everything about your AI API costs, and all four of them are measurable before you write a single line of production code.

Try the tools