AI API cost comes down to one formula: the input tokens you send times the input price, plus the output tokens you get back times the output price, with prices quoted per million tokens. Output almost always costs several times more than input. Once you know the token counts and the model's prices, the cost of any request is simple arithmetic. Here is how to work it out, step by step.
The formula
Cost of a request equals (input tokens divided by 1,000,000 times input price) plus (output tokens divided by 1,000,000 times output price). A token is roughly three quarters of a word, so a page of text is about 500 tokens. Everything you send, the prompt, instructions and any documents, counts as input; everything the model writes back is output.
Step 1: count the tokens
Estimate the input by adding up your prompt, system instructions and any attached context, then estimate the output from how long the answer typically is. For a rough figure, take your word count and divide by about 0.75 to get tokens. Most providers also offer a token counter if you want an exact number before committing.
Step 2: apply the per-model price
Look up the model's input and output price per million tokens and plug them into the formula. The model choice matters enormously: the cheapest and most expensive models can differ by fifty times for the same task. Our breakdown of Claude API pricing shows how far apart the tiers sit.
A worked example
Say each request sends 1,500 input tokens and returns 500 output tokens, on a model priced at 2 dollars input and 10 dollars output per million. Input is 1,500 divided by a million times 2 dollars, which is 0.003 dollars. Output is 500 divided by a million times 10 dollars, which is 0.005 dollars. So about 0.008 dollars per request, or 8 dollars per thousand requests. To skip the maths, our free AI cost calculator does it across every major model, and our guide to reducing AI API costs covers how to bring the number down.
Saraswati Stitch®contact@saraswatistitch.com