devtools.codes

Estimating GPT API costs before you build

Your tool input is processed locally in your browser and is not intentionally uploaded to our servers. Advertising and analytics providers may still process normal page, device, cookie and network information.

Most cost surprises are not caused by the price per token. They are caused by volume assumptions that were never written down, and by token counts that turned out to be larger than anyone estimated.

Four variables determine the bill: tokens in per request, tokens out per request, requests per month, and the model. Everything else is secondary. Write all four down with the reasoning behind them, because the reasoning is what you will revisit when the estimate turns out to be wrong.

Three things are routinely forgotten. The first is the system prompt, which is sent on every single request and is often longer than the user message. The second is retrieval context: a RAG pipeline that injects five chunks of eight hundred characters each adds meaningfully to every call. The third is retries — any pipeline that validates output and retries on failure consumes tokens for the failed attempt too.

Model choice usually matters more than optimisation. Moving a classification task from a frontier model to a smaller one can change the cost by an order of magnitude, where trimming a prompt might save a few per cent. Before optimising tokens, check whether the task needs the model you have chosen.

Build the estimate as a range rather than a single number. A low case with your expected volume and a high case with conservative token counts and a realistic retry rate will tell you more than a precise-looking point estimate. If the high case is affordable, you can stop worrying; if the low case is not, you have a design problem rather than a pricing problem.

More on estimating GPT API costs before you build

How accurate can an estimate be before I have written any code?

Accurate enough to make a decision, which is all it needs to be. A range built from a representative prompt, a representative response and an honest volume assumption will usually land within the right order of magnitude. That is sufficient to tell you whether the design is affordable, which is the only question at this stage.

Is a cheaper model always the right way to cut costs?

Not always, but it is the first thing to test. Model choice moves cost by an order of magnitude where prompt trimming moves it by a few per cent. The risk is a smaller model that fails more often, because retries and fallbacks to a larger model can quietly return the cost you thought you had saved.

How should I account for retries in the estimate?

Multiply by your expected attempts per successful call rather than adding a flat margin. A pipeline that validates structured output and retries once on failure with a ten per cent failure rate costs about 1.1 times a single call. Include the failed attempt in full: it consumed both input and output tokens.

Do free tiers and trial credits belong in the estimate?

Leave them out of the baseline. They expire, they are capped, and a design that is only affordable while credits last is a design problem you want to see now. Build the estimate on standard list pricing, then treat any free allowance as a temporary discount against a number you already know you can live with.

The tool behind this, and related guides