How do you estimate LLM API cost before you send the prompt?

Cost = (input tokens x input price) + (output tokens x output price), with prices quoted per 1M tokens. Estimate tokens at about 4 characters per token for English text, then run the formula.

The formula

cost = input_tokens  x input_price_per_1M  / 1,000,000
     + output_tokens x output_price_per_1M / 1,000,000

Input and output are priced separately, and output is usually the expensive half. Providers quote prices per 1M tokens, so divide by a million.

Estimating tokens in your head

For English text, one token is about 4 characters, or roughly three quarters of a word. Code and non-English text tokenize worse, so pad the estimate. Our calculator uses (chars/4 + words x 1.3) / 2, which lands close to the common tokenizers for mixed text. It is an estimate, not the provider's tokenizer.

Worked example

Say a model charges $1 per 1M input tokens and $4 per 1M output tokens (example rates, not a real model). A call with 2,000 input tokens and 500 output tokens costs:

2000 x 1 / 1e6  = $0.002
 500 x 4 / 1e6  = $0.002
total per call   = $0.004  (about 250 calls per $1)

Providers change prices without notice, so check current rates before you budget. The calculator below keeps a checked-date table for GPT, Claude, Gemini and DeepSeek models.

Do the math with your own numbers:

LLM Token & API Cost Calculator →

Free, runs in your browser. Nothing you type is sent anywhere.

Advertisement