How to Calculate AI API Costs
AI API costs can add up fast if you're not paying attention. Here's exactly how to calculate your costs, predict monthly spend, and optimize your budget.
The examples below use GPT-4o's published rates as a teaching case. Model pricing shifts often — check live rates for the latest models in the Model Comparator.
The Basic Formula
AI pricing is based on tokens per million. The formula is:
Cost = (Input Tokens × Input Price / 1,000,000) + (Output Tokens × Output Price / 1,000,000)
For example, with GPT-4o ($2.50 input / $10.00 output per million tokens):
500 input tokens: 500 × $2.50 / 1,000,000 = $0.00125 1,000 output tokens: 1,000 × $10.00 / 1,000,000 = $0.01 Total per request: $0.01125
Monthly Cost Estimator
Use this table to estimate your monthly costs based on usage:
| Requests/Day | GPT-4o | Claude 3.5 | Gemini Pro | GPT-4o Mini |
|---|---|---|---|---|
| 100 | $34 | $50 | $19 | $2 |
| 500 | $169 | $248 | $94 | $10 |
| 1,000 | $338 | $495 | $188 | $20 |
| 5,000 | $1,688 | $2,475 | $938 | $101 |
| 10,000 | $3,375 | $4,950 | $1,875 | $203 |
Based on 500 input tokens + 1,000 output tokens per request.
Hidden Costs You Might Miss
- System prompts: Charged as input tokens on every request.
- Conversation history: Each message in the context adds to input cost.
- Retries: Failed requests still cost tokens.
- Long outputs: Open-ended generation can produce 2,000+ tokens per response.
- Multi-turn conversations: Cost multiplies with each back-and-forth.
5 Ways to Cut AI Costs
- Use cheaper models for simple tasks: GPT-4o Mini ($0.15/M) is 90% cheaper than GPT-4o.
- Set max_tokens: Prevent runaway output costs.
- Optimize prompts: Shorter prompts = fewer input tokens = lower cost.
- Cache responses: Don't reprocess identical requests.
- Batch processing: Process multiple items in one request instead of one at a time.
Real-World Example: Chatbot Application
Let's say you're building a customer support chatbot:
- 500 conversations/day
- 5 messages per conversation (average)
- 300 input tokens per message (system + user + history)
- 200 output tokens per message
Daily: 500 × 5 × (300 × $2.50 + 200 × $10.00) / 1M = $6.25 Monthly: $6.25 × 30 = $187.50
That's $187.50/month on GPT-4o, or $18.75/month on GPT-4o Mini — same functionality, 10x cheaper.
When to Upgrade Models
Start with the cheapest model that works. Upgrade only when:
- Output quality is consistently poor
- You need a larger context window
- You need specific capabilities (multimodal, function calling)
- Latency requirements demand a faster model
Use our AI Token Counter to estimate costs before committing to a model.
Estimate your AI costs instantly.
Try AI Token Counter →Frequently Asked Questions
How is AI API pricing calculated?
Providers charge per million tokens, with separate rates for input and output. The formula is: (input tokens ÷ 1,000,000 × input rate) + (output tokens ÷ 1,000,000 × output rate). Your system prompt and conversation history count as input every time.
Why are output tokens more expensive than input tokens?
Generating text happens one token at a time, with a full model pass for each token, while input tokens are processed in parallel in a single pass. That makes generation roughly three to four times more expensive than reading.
How much does 1,000 words of AI output cost?
A thousand English words is about 1,333 output tokens. At $15 per million output tokens that is roughly $0.02, and at $75 per million it is about $0.10. Multiply by how often you generate content to get your monthly estimate.
How can I reduce my AI API costs?
Four habits cover most of the savings: trim long prompts, cap responses with max_tokens, send simple tasks to a cheaper model tier, and use prompt caching so repeated context is not billed at full price again.