AI API Cost Calculator
Estimate the cost of any OpenAI or Anthropic API call by entering your token usage. Compare GPT-4o, GPT-4o-mini, Claude Sonnet 4, and Claude Haiku 3.5 side by side.
Reviewed by the ToolNestr Editorial Team — July 2026
Prices reflect published rates as of June 2026. Actual billing may vary based on caching, batch discounts, and regional pricing.
How AI API cost calculation works
AI API providers charge based on the number of tokens processed by the model. Each API call has two components: the input (or prompt) and the output (or completion). Input tokens are the text you send to the model, including the system prompt, conversation history, and user message. Output tokens are the text the model generates in response. Providers like OpenAI and Anthropic set separate prices per million tokens for input and output because generating output tokens is computationally more expensive — the model must run a full forward pass for each token it produces.
The per-token price is derived by dividing the per-million-token rate by 1,000,000. For example, GPT-4o costs $2.50 per million input tokens, which is $0.0000025 per token. If your prompt uses 1,000 input tokens and the response uses 500 output tokens, the input cost is 1,000 × $0.0000025 = $0.0025 and the output cost is 500 × $0.00001 = $0.005 (at $10 per million output tokens). The total per-call cost is the sum of these two, then multiplied by the number of calls you make.
Worked example
GPT-4o cost for a customer support summarization task
Developer
Estimates API costs during development and production. Compares model pricing to choose the most cost-effective option for each feature. Monitors token usage to optimise prompt design.
Product Manager
Projects monthly API spend for feature planning and budgeting. Evaluates the cost impact of switching between models or adjusting response lengths to meet cost targets.
Startup Founder
Calculates per-user or per-transaction AI costs to validate unit economics. Determines whether GPT-4o-mini or Claude Haiku can meet requirements at scale without compromising quality.
Solution Architect
Designs multi-model systems that route simple queries to cheap models and complex reasoning to premium models. Uses cost data to architect tiered AI pipelines.
Tips for managing API costs
Match model capability to task complexity
Do not use GPT-4o or Claude Sonnet 4 for every task. Simple classification, extraction, or moderation can be handled effectively by GPT-4o-mini ($0.15/$0.60) or Claude Haiku 3.5 ($0.80/$4), which are 10 to 20 times cheaper. Reserve the most powerful models for tasks that genuinely require deep reasoning.
Optimise your prompt structure
Every input token costs money. Keep system prompts concise, trim conversation history to the most recent relevant turns, and avoid repeating instructions. A well-structured prompt that reduces input tokens by 30% cuts input costs by the same amount without affecting output quality.
Limit output length explicitly
Set the max_tokens parameter to the minimum viable response length. Models tend to generate verbose output by default, and output tokens are the most expensive component. For example, reducing output from 500 to 200 tokens cuts the output cost by 60%.
Leverage caching and batching
Some providers offer prompt caching that discounts repeated input tokens, and batch API endpoints that process requests at half the price with delayed responses. For production workloads at scale, these features can reduce total costs by 40% to 50%.
Model pricing comparison
Current per-million-token pricing for popular AI models as of June 2026.
| Model | Provider | Input (per 1M tokens) | Output (per 1M tokens) |
|---|---|---|---|
| GPT-4o | OpenAI | $2.50 | $10.00 |
| GPT-4o-mini | OpenAI | $0.15 | $0.60 |
| Claude Sonnet 4 | Anthropic | $3.00 | $15.00 |
| Claude Haiku 3.5 | Anthropic | $0.80 | $4.00 |
How token pricing affects your bill
The cost of running AI features in your application depends directly on three factors: the number of tokens per request, the price per token of your chosen model, and the volume of requests. A standard GPT-4o conversation with 2,000 input tokens and 500 output tokens costs about 1 cent per exchange. At 100,000 conversations per month, that is $1,000 in API costs. Using GPT-4o-mini for the same workload drops the cost to around $0.07 per 1,000 conversations — a dramatic reduction that makes AI features viable at much larger scales.
Output tokens dominate costs for most applications because they are priced 2 to 5 times higher than input tokens and because responses often contain substantial generated content. In a typical customer support bot, the input might be a short user query plus a long system prompt, while the output is a detailed reply. Optimising the system prompt length and limiting the response length are the two most effective ways to reduce spending. This calculator helps you model these trade-offs before deploying to production, so you can predict your bill accurately and choose the right model for every use case.
Related tools
Frequently asked questions
How is AI API cost calculated?
AI API costs are calculated by multiplying the number of input tokens by the input price per token, adding the number of output tokens multiplied by the output price per token, then multiplying the result by the number of API calls. Prices are set per million tokens by providers. For example, GPT-4o charges $2.50 per million input tokens, so a single input token costs $2.50 ÷ 1,000,000 = $0.0000025. The calculator applies this formula automatically for every model.
What is the difference between input and output tokens?
Input tokens (also called prompt tokens) are the text you send to the model, including the system prompt, conversation history, and the user message. Output tokens (also called completion tokens) are the text the model generates in response. Output tokens typically cost more than input tokens because generating tokens requires more computation than processing existing ones — the model must predict each token sequentially rather than simply encoding the input in parallel.
Why do output tokens cost more than input tokens?
Output tokens are more expensive because text generation is computationally intensive. During inference, the model must run its full forward pass for every single output token produced, whereas input processing can leverage parallelization (the transformer architecture processes all input tokens simultaneously). This means generating a 500-token response requires roughly 500 sequential passes through the model, making it significantly more resource-intensive than processing the same number of input tokens.
Which model should I choose for my use case?
The best model depends on your priorities. GPT-4o offers the best balance of capability and speed for most production use cases at $2.50/$10 per million tokens. GPT-4o-mini at $0.15/$0.60 is ideal for high-volume, simpler tasks like classification, extraction, or summarization where you need low latency and cost. Claude Sonnet 4 at $3/$15 excels at complex reasoning, coding, and analysis. Claude Haiku 3.5 at $0.80/$4 is Anthropic's fastest and most affordable model, great for simple Q&A, moderation, and real-time applications.
How many tokens does a typical prompt use?
Token counts vary by language and content. English text averages about 1.3 to 1.5 tokens per word, so a 100-word prompt uses roughly 130 to 150 tokens. Code tends to be more token-efficient at around 1 token per 1 to 2 characters. A typical ChatGPT conversation might use 500 to 2,000 input tokens for the history plus 100 to 500 output tokens per response. The calculator lets you experiment with different values to estimate costs across all these scenarios.
How accurate are these cost estimates?
These estimates are accurate to the published pricing for each model as of 2026. Actual costs may differ slightly because tokenization varies — the exact number of tokens a model uses for a given text depends on the model's tokenizer, and different models may tokenize the same text differently. Additionally, some providers offer batch API pricing at 50% discount or have caching tiers that reduce costs. The calculator provides a solid baseline estimate for standard API usage.
How can I reduce my API costs?
There are several strategies to reduce costs: use smaller models (GPT-4o-mini or Claude Haiku) for simpler tasks; keep system prompts concise; cache common responses; use shorter conversation histories by summarizing previous turns; batch requests when possible for lower per-token pricing; implement semantic caching to avoid repeating identical queries; and monitor your token usage with tools like the Prompt Token Counter to identify wasteful patterns.