GuideBeginnerPricing

How to Calculate LLM API Costs for Your App (Complete Guide)

Understanding token pricing doesn't have to be complicated. Here is the step-by-step guide to estimating input tokens, output tokens, and your total monthly API spend.

September 7, 2026·10 min read

When building an application powered by Large Language Models (LLMs) like GPT-4o, Claude Sonnet, or Gemini, the biggest unknown is often the infrastructure cost. Unlike traditional cloud computing billed by time or bandwidth, LLMs are billed by "tokens."

In this guide, we'll break down exactly how tokens work, the formula for calculating costs, and how to estimate your monthly budget before you write a single line of code.

1. What is a Token?

A token is the fundamental unit of data an LLM reads and generates. It's not quite a word, and it's not quite a character. Think of it as a syllable or a chunk of a word.

The Golden Rule of Tokens:

  • 1 Token ≈ 4 characters in English
  • 1 Token ≈ 0.75 words
  • 100 Tokens ≈ 75 words

Keep in mind that this rule applies to standard English text. Code, structured data (like JSON or XML), and non-English languages often consume tokens less efficiently.

2. Input vs. Output Tokens

All major API providers (OpenAI, Anthropic, Google) split their pricing into two categories:

  • Input Tokens (Prompt Tokens): Everything you send to the model. This includes your system instructions, the user's message, and any context or documents you append.
  • Output Tokens (Completion Tokens): Everything the model generates and sends back to you.

Why does this matter? Generating output is computationally much heavier than reading input. As a result, Output Tokens are almost always 3 to 5 times more expensive than Input Tokens.

3. The Cost Calculation Formula

API providers quote prices "per 1 Million tokens" (denoted as /1M). The universal formula to calculate the cost of a single API request is:

Total Cost =
  ((Input_Tokens / 1,000,000) * Input_Price)
+ ((Output_Tokens / 1,000,000) * Output_Price)

4. A Real-World Example

Let's say you are building an app that summarizes customer service emails using GPT-4o mini.

  • GPT-4o mini pricing: $0.15 / 1M Input, $0.60 / 1M Output
  • Average email (input): 800 words ≈ 1,066 tokens
  • System prompt (input): 100 words ≈ 133 tokens
  • Average summary (output): 100 words ≈ 133 tokens

Calculations for one email:

  • Total Input Tokens: 1,066 + 133 = 1,199 tokens
  • Input Cost: (1,199 / 1,000,000) * $0.15 = $0.00017985
  • Output Cost: (133 / 1,000,000) * $0.60 = $0.0000798
  • Total Cost per Email: ~$0.00026

If you process 100,000 emails a month, your total monthly API bill for this feature would be just $26.00.

Don't want to do the math manually? Use our free calculator →

Open Calculator

Frequently Asked Questions

How are LLM API costs calculated?
LLM API costs are calculated based on the number of tokens processed. You are charged separately for 'input tokens' (the prompt you send) and 'output tokens' (the response the model generates). The total cost is: (Input Tokens / 1,000,000 * Input Price) + (Output Tokens / 1,000,000 * Output Price).
What is a token in an LLM?
A token is a piece of a word used by the language model to process text. A helpful rule of thumb is that 1 token is approximately 3/4 of a word in English, or roughly 4 characters. Therefore, 1,000 tokens equal about 750 words.
Are input tokens cheaper than output tokens?
Yes, almost always. For major providers like OpenAI, Anthropic, and Google, input tokens are typically 3 to 5 times cheaper than output tokens. This is because generating new tokens (output) requires significantly more compute power than reading existing tokens (input).
How can I estimate my monthly LLM API spend?
To estimate your monthly spend: 1) Estimate the average input and output tokens per user action. 2) Multiply by the expected number of actions per user per month. 3) Multiply by your total active users. 4) Apply the model's pricing formula. Using a token cost calculator tool is the easiest way to model this.