---
title: "How to Calculate LLM API Costs: A 4-Step Estimation Formula"
description: "How to calculate LLM API costs: input tokens × input price + output tokens × output price. A 4-step method and worked table for per-call and monthly cost."
url: https://cdnping.org/en/blog/llm-api-cost-estimation-method
language: en
published: 2026-11-24
category: "AI concepts"
tags: ["API cost","tokens","billing","cost estimation","beginner guide"]
source: cdnping.org
license: Free to quote and summarize with a link to the url above.
---
# How to Calculate LLM API Costs: A 4-Step Estimation Formula

How do you calculate LLM API costs? The basic formula is one line: cost per call = input tokens × input price + output tokens × output price. Monthly cost is the cost per call times the number of calls. The formula isn't the hard part. The hard part is getting the three inputs: token counts, unit prices, and call volume.

This article doesn't list prices for any specific model. Prices change at any time, so always go by the official pricing page. What follows is a method you can fill in yourself, and every number in the examples is hypothetical.

## What goes into the bill?

Most services bill by token. Pricing pages usually quote "price per million tokens" and price input and output separately. Output generally costs more than input; see [why output tokens cost more than input](/en/blog/why-output-tokens-cost-more) for the reasons.

Besides those two line items, your bill may also include:

- Cached input: some services charge a lower rate for a repeated prompt prefix. Whether that's supported and how big the discount is depends on the official docs.
- Thinking (reasoning) tokens: for reasoning models, the thinking process is usually billed as output, even if you never see it in the reply. See [how reasoning tokens are billed](/en/blog/reasoning-tokens-billing).
- Extras such as tool calls, web search, and image input: rules differ by provider, so check the official docs.

If tokens are still unfamiliar, read [what a token is in an LLM](/en/blog/what-is-token-in-llm) first, then come back to the steps below.

## How do you estimate step by step?

### Step 1: Pull three numbers from the official pricing page

Open the official pricing page for the service you plan to use and write down:

1. Input price (per million tokens)
2. Output price (per million tokens)
3. Currency and unit (USD or CNY, per million or per thousand)

Units are the easiest thing to misread. Normalize everything to "per million tokens" before you calculate.

### Step 2: Estimate input and output tokens for one call

Input includes the system prompt, conversation history, any documents you paste in, and the current question, not just your last sentence. Output is the length of the model's reply; for reasoning models, count the thinking tokens too.

The most reliable approach is to measure: run a few real tasks, read the usage fields returned in the response (field names are in the official docs), and take the average. If you can't measure yet, use the provider's token-counting tool or tokenizer to get an estimate, then leave some headroom. Different models tokenize differently, so converting from character or word counts is only a rough guide.

### Step 3: Apply the formula to get the cost per call

Cost per call = input tokens ÷ 1,000,000 × input price + output tokens ÷ 1,000,000 × output price

### Step 4: Multiply by call volume, then add a buffer

Monthly cost = cost per call × calls per day × number of days. Then multiply by 1.2 to 1.5 to cover retries, long contexts, and the occasional oversized request. How much buffer to use is a judgment call; there's no standard answer.

## What does a full worked example look like?

All numbers below are hypothetical and only demonstrate the arithmetic. They don't reflect the price of any real model.

Assume an input price of 3 and an output price of 15 (same currency, per million tokens). An average call uses 2,000 input tokens and 500 output tokens.

| Item | Calculation | Result |
| --- | --- | --- |
| Input cost | 2,000 ÷ 1,000,000 × 3 | 0.006 |
| Output cost | 500 ÷ 1,000,000 × 15 | 0.0075 |
| Total per call | 0.006 + 0.0075 | 0.0135 |
| 200 calls per day | 0.0135 × 200 | 2.7 |
| 30 days | 2.7 × 30 | 81 |
| Plus a 30% buffer | 81 × 1.3 | about 105 |

Notice that output is only 500 tokens here, yet it accounts for more than half of the cost. So when you want to cut costs, capping output length and trimming prompts is often more direct than switching models.

## What makes an estimate come out too low?

- Multi-turn conversations: every turn resends the history as input, so the more turns, the larger the input.
- Agent-style tasks: a single task calls the model many times and may read files over and over. For estimating these, see [why AI agent tasks use so many tokens](/en/blog/estimate-ai-agent-task-cost).
- Retries and failures: a retry after a timeout can be billed again. Which failures are not billed is stated in the official docs.
- Thinking tokens: you can't see them, but you pay for them.

## What to do once you have a monthly estimate

If you have no usage history, use the [three-step logging method](/en/blog/estimate-monthly-token-usage) to record a week of real usage, then plug it into the formula above. Once you have a budget, set a usage cap or alert in the provider's console. See [how to control API spending](/en/blog/control-ai-api-spending) for how.

If you're comparing several providers, don't look only at the per-million-token price. Caching, thinking tokens, and the input-to-output ratio all change the result. See [how to compare LLM API prices](/en/blog/llm-api-pricing-how-to-compare).

## What if you don't want to work through several pricing pages yourself?

The upside of per-token billing is that you pay for what you use. The downside is that you only learn the bill at the end of the month, and each provider has its own currency and payment methods. Some aggregation gateways instead use a monthly subscription with a quota, which fixes the budget.

AGI Plan is one such service: a monthly subscription paid in RMB (Chinese yuan) with no overseas credit card required, where one subscription can switch between multiple capability groups, and tools like Claude Code and Codex only need a changed endpoint URL. The quota unit is the CU, and 1 CU equals 1,000 output tokens of the baseline model. Disclosure: AGI Plan is a commercial partner of cdnping. AGI Plan is not an officially authorized channel, and some models are available only outside mainland China; check the [models page](https://agiplan.dev/models) for specifics. To learn how to connect, see the [setup guide](https://agiplan.dev/startup).

You can still use the method in this article to decide whether it fits you: convert your monthly token usage into quota, then compare it with what direct billing from the official API would cost.

## Summary and next steps

1. Open the official pricing page and note the input and output prices and the unit.
2. Measure 5 to 10 real tasks and average the input and output tokens.
3. Use the formula for the cost per call, multiply by call volume, and leave a buffer.
4. Set a usage cap, and after a month calibrate your estimate against the real bill.

To see how the model APIs connect from your network, try the [cdnping online speed test](/en); for provider availability and price changes, see [model monitoring](/en/models). If this is your first time with an API, start with [how to use an LLM API](/en/blog/llm-api-first-request-guide). Get a key, send your first request, and then come back to build the budget.
