Updated 2026-07-28

How to Calculate AI API Costs: Step-by-Step

Understanding Tokens: The Basic Unit

Before you can calculate costs, you need to understand tokens — the unit AI companies use for billing. A token is a small chunk of text, roughly ¾ of an English word. You can think of it this way: 1 token ≈ 0.75 words, or equivalently, 1 word ≈ 1.3 tokens.

Every piece of text you send to an AI model gets broken into tokens before processing. The model's response is also measured in tokens. AI companies charge per token (usually quoted per million tokens), so converting your content into token counts is the first step to estimating costs.

For a deeper dive into how tokenization works, see our guide on what is a token in AI.

Content TypeAmountApproximate Tokens
100 wordsA short paragraph~133
1 page (500 words)Single-spaced page~667
1 novel~90,000 words~120,000
100 lines of codeA small script~1,000
1 imageTypical resolution~1,000
1 minute of speech~150 words~200

The Cost Formula

AI API pricing is simple once you know the formula. Every model has two prices: an input price (what you send to the model) and an output price (what the model generates back). Output tokens typically cost 3–6× more than input tokens because generating text is far more computationally expensive than reading it.

The formula

Cost = (number_of_tokens / 1,000,000) × price_per_1M_tokens

Step 1: Count (or estimate) how many tokens of input and output your task requires.

Step 2: Look up the model's input and output price per million tokens.

Step 3: Calculate each cost separately, then add them together.

Quick example:

Say you want to summarize 10 pages of text using Gemini 3 Flash. That's 6,670 input tokens, and let's assume the summary is about 200 output tokens.

  • Input cost: (6,670 / 1,000,000) × $0.50 = $0.00
  • Output cost: (200 / 1,000,000) × $3 = $0.00
  • Total: $0.00

Now let's see how this plays out in real-world scenarios across all 12 major models.

ModelProviderInput / 1MOutput / 1M
Gemini 3 FlashGoogle$0.50$3
GPT-5.6 LunaOpenAI$1$6
Claude Haiku 4.5Anthropic$1$5
Gemini 3.5 FlashGoogle$1.50$9
Claude Sonnet 5Anthropic$2$10
Gemini 3.1 ProGoogle$2$12
GPT-5.6 TerraOpenAI$2.50$15
GPT-5.6 SolOpenAI$5$30
GPT-5.5OpenAI$5$30
Claude Opus 4.8Anthropic$5$25
Claude Fable 5Anthropic$10$50
GPT-5.5 ProOpenAI$30$180

Prices range from $0.50 to $30 per million input tokens. See our full pricing comparison for more detail.

Example 1: Processing 100 PDFs

Scenario: You have 100 PDF documents, each about 20 pages long. You want to send each to an AI for summarization. The output summaries are short, so we'll focus on input cost.

  • Pages: 100 PDFs × 20 pages = 2,000 pages
  • Tokens: 2,000 pages × 667 tokens/page = 1,334,000 input tokens
ModelInput Price / 1MCost for 1,334,000 tokens
Gemini 3 Flash$0.50$0.67
GPT-5.6 Luna$1$1.33
Claude Haiku 4.5$1$1.33
Gemini 3.5 Flash$1.50$2.00
Claude Sonnet 5$2$2.67
Gemini 3.1 Pro$2$2.67
GPT-5.6 Terra$2.50$3.33
GPT-5.6 Sol$5$6.67
GPT-5.5$5$6.67
Claude Opus 4.8$5$6.67
Claude Fable 5$10$13.34
GPT-5.5 Pro$30$40.02

The cheapest option (Gemini 3 Flash at $0.50/1M) costs just $0.67, while the most expensive (GPT-5.5 Pro) costs $40.02 — a 60x difference.

Example 2: Building a Customer Support Chatbot

Scenario: You're building a chatbot that handles 100 customer conversations per day for 30 days. Each conversation has 10 user messages and 10 bot responses.

  • User messages: ~30 words each ≈ 40 tokens × 10 = 400 input tokens/conversation
  • Bot responses: ~150 words each ≈ 200 tokens × 10 = 2,000 output tokens/conversation
  • Total conversations: 100/day × 30 days = 3,000
  • Total input: 3,000 × 400 = 1,200,000 tokens
  • Total output: 3,000 × 2,000 = 6,000,000 tokens
ModelInput CostOutput CostTotal / Month
Gemini 3 Flash$0.60$18$18.60
GPT-5.6 Luna$1.20$36$37.20
Claude Haiku 4.5$1.20$30$31.20
Gemini 3.5 Flash$1.80$54$55.80
Claude Sonnet 5$2.40$60$62.40
Gemini 3.1 Pro$2.40$72$74.40
GPT-5.6 Terra$3$90$93
GPT-5.6 Sol$6$180$186
GPT-5.5$6$180$186
Claude Opus 4.8$6$150$156
Claude Fable 5$12$300$312
GPT-5.5 Pro$36$1080$1116

Notice how output cost dominates — the bot generates 5× more tokens than it reads. For chatbots, the output price is the bigger cost driver.

Example 3: Analyzing 1,000 Product Images

Scenario: You need to analyze 1,000 product images. Each image is processed as ~1,000 input tokens, and the model writes a ~100-token description for each.

  • Input: 1,000 images × 1,000 tokens = 1,000,000 input tokens
  • Output: 1,000 images × 100 tokens = 100,000 output tokens
ModelInput CostOutput CostTotal
Gemini 3 Flash$0.50$0.30$0.80
GPT-5.6 Luna$1$0.60$1.60
Claude Haiku 4.5$1$0.50$1.50
Gemini 3.5 Flash$1.50$0.90$2.40
Claude Sonnet 5$2$1$3
Gemini 3.1 Pro$2$1.20$3.20
GPT-5.6 Terra$2.50$1.50$4
GPT-5.6 Sol$5$3$8
GPT-5.5$5$3$8
Claude Opus 4.8$5$2.50$7.50
Claude Fable 5$10$5$15
GPT-5.5 Pro$30$18$48

Image analysis is input-heavy: 1,000,000 input tokens vs. 100,000 output tokens. The cheapest option (Gemini 3 Flash) totals just $0.80.

Tips for Reducing AI API Costs

  1. Use cheaper models for simple tasks. Not every task needs a frontier model. Classification, extraction, and simple summarization work well on budget models like Gemini 3 Flash at $0.50/1M input — 60x cheaper than GPT-5.5 Pro.
  2. Batch your requests. Group multiple items into a single API call where possible. Processing 10 short texts in one prompt is cheaper than 10 separate calls because you avoid repeating system prompts and instructions.
  3. Cache responses. If the same input might come up again, store the response. A simple key-value cache can eliminate duplicate API calls entirely.
  4. Write shorter prompts. Every word in your system prompt and instructions costs tokens. Trim unnecessary examples, reduce verbose instructions, and keep context windows lean. At 1.3 tokens per word, cutting 100 words saves ~133 tokens per request.
  5. Pick the right model tier. Start with a budget model and move up only if quality is insufficient. Most teams find 80% of their API calls work fine on balanced or budget models.

Try our interactive calculator to estimate costs for your specific project.

Open the AI token calculator — pick a model, set a budget, and see exactly how many words, pages, or lines of code you get.