← Building with AI

Estimating cost

Prices are per million tokens, separate for input and output.

Start this lesson

Providers usually charge per million tokens, with one price for input and a higher price for output. To find the cost of a request, divide each token count by 1,000,000 and multiply by its price, then add the two. Doing this arithmetic before you launch something tells you whether it costs pennies or a lot.

# Example prices (made up for practice; check your provider's pricing page):
PRICE_IN = 3.00    # dollars per million input tokens
PRICE_OUT = 15.00  # dollars per million output tokens

input_tokens = 2000
output_tokens = 500
cost = input_tokens / 1_000_000 * PRICE_IN + output_tokens / 1_000_000 * PRICE_OUT
print(round(cost, 4))   # 0.0135 dollars, about 1.4 cents

1_000_000 is just 1000000 with underscores to make it readable. Python ignores the underscores.

Prices differ a lot between models. Smaller, faster models are often far cheaper and good enough for simple jobs like labelling.

Read usage from each real reply and add it up to see what you actually spend.