AI API Cost Calculator
Estimate API costs for AI services like GPT, Claude, or Gemini.
Formula
Cost = Tokens × Requests / 1000 × Rate
Example
2000 tokens × 500 requests at $0.015/1K → $15/day, $450/month.
AI API costs follow a deceptively simple formula that hides exponential bill growth. Tokens per request × requests per day × cost per token = daily spend. Each of those three numbers is small, but multiplied together they can produce monthly bills in the six figures. The teams that get surprised by their AI bill almost always made the same mistake: scaling one of those three variables without doing the math on the other two.
The three-variable formula
Monthly cost equals (tokens per request × requests per day × cost per 1K tokens × 30) ÷ 1,000. So for a chatbot with 2,000-token average requests, 1,000 daily users, at $0.005 per 1K tokens:
(2,000 × 1,000 × $0.005 × 30) ÷ 1,000 = $300/month
That's manageable. But triple any variable and you triple the bill. Scale by 10× and the bill scales by 10× — there's no economies of scale in raw API pricing. Hit a million daily requests and you're at $300,000/month with no breaks. This is why API costs become a serious operational concern faster than most teams expect.
Realistic price ranges (mid-2025)
| Model category | Per 1K input tokens | Per 1K output tokens |
|---|---|---|
| Frontier (GPT-4o, Claude Sonnet) | $0.0025–$0.003 | $0.010–$0.015 |
| Mid-tier (Gemini Pro, Claude Haiku) | $0.0008–$0.00125 | $0.004–$0.005 |
| Light models (GPT-4o mini, Gemini Flash) | $0.00015–$0.00025 | $0.0006–$0.0010 |
| Open via API (Llama via Together) | $0.0006–$0.001 | $0.0006–$0.001 |
| DeepSeek V3 | $0.00027 | $0.0011 |
| Self-hosted (Llama on owned GPU) | Free (excluding GPU cost) | Free |
The 30× gap between Gemini Flash and Claude Sonnet on input cost is real, and the gap matters most at high volume. A 30× cost difference becomes a $200K/month difference at the volume where it's most painful to notice.
Monthly cost projections at different scales
| Volume tier | Light model (Gemini Flash) | Frontier (Claude Sonnet) |
|---|---|---|
| Hobby (100 req/day, 1K tokens) | $0.30/mo | $36/mo |
| Small SaaS (1K req/day, 2K tokens) | $12/mo | $720/mo |
| Growing app (10K req/day, 3K tokens) | $180/mo | $10,800/mo |
| Production scale (100K req/day, 3K tokens) | $1,800/mo | $108,000/mo |
| Heavy enterprise (1M req/day, 5K tokens) | $30,000/mo | $1.8M/mo |
Stare at that bottom row. A single AI feature on a popular consumer app can hit million-dollar monthly bills using a frontier model. This is why so many companies route different requests to different models depending on complexity — frontier for the hard cases, light models for the easy ones.
Monthly bill at 100K requests/day, varying request size
When self-hosting beats APIs
The math for self-hosting vs API access shifts as volume grows. At low volume, APIs are dramatically cheaper. At high volume, self-hosting wins. The crossover depends on model size and utilization.
| Monthly volume | API cost (GPT-4o-class) | Self-hosted (Llama 70B) | Winner |
|---|---|---|---|
| 1M tokens | $5 | $1,500+/mo for H100 lease | API |
| 10M tokens | $50 | $1,500+/mo | API |
| 100M tokens | $500 | $1,500-3,000/mo | API |
| 1B tokens | $5,000 | $3,000-5,000/mo (with batching) | Self-hosted starts to win |
| 10B tokens | $50,000 | $10,000-20,000/mo | Self-hosted clearly wins |
| 100B tokens | $500,000 | $50,000-100,000/mo | Self-hosted strongly |
The catch with self-hosting: you need engineering capacity to run it. Most teams spend 0.5-1 full-time engineer on inference infrastructure when self-hosting at scale. If that engineer costs $200K/year, you need to be saving at least $200K/year on API costs to break even on the labor.
Cost optimization techniques that actually work
- Model routing. Send simple requests to cheap models, complex ones to expensive models. A classifier (using a cheap model itself) decides which to use. Typical savings: 50-70%.
- Caching identical or near-identical requests. Many user requests are duplicates or near-duplicates. A semantic cache (using vector similarity) catches 20-40% of queries with zero new API cost.
- Prompt engineering for brevity. Shorter system prompts reduce input tokens on every request. A 500-token system prompt vs 200-token one at 1M requests/month = $1,500 monthly savings on input alone.
- Streaming + early stopping. For chat applications, let users see partial responses and let them stop generation when they have what they need. Saves 30-50% on output tokens for many tasks.
- Batch processing where possible. Non-realtime workloads (overnight analysis, daily reports) at 50% off via batch APIs.
- Aggressive max_tokens limits. Letting the model run to natural stop often produces 2× the needed output. Set tight max_tokens; increase only if responses truncate.
Spike protection: avoiding the runaway bill
The cautionary tale every AI startup has heard: "We had a bug. The bill was $40,000 in 3 days." It happens often enough that providers now offer multiple protection mechanisms, but most teams don't enable them until after their first incident.
| Protection | How it works | Implementation effort |
|---|---|---|
| Hard spending limit (provider-side) | API blocks requests once limit hit | 5 min — set in dashboard |
| Daily / monthly budget alerts | Email when spend crosses thresholds | 5 min — set in dashboard |
| Per-API-key spending caps | Different limits for dev vs prod keys | 15 min — multi-key setup |
| Application-level rate limiting | Your app enforces per-user request limits | 1-3 days engineering |
| Cost-per-user metering | Track and bill internal costs to specific users/features | 1-2 weeks engineering |
| Anomaly detection | Alert on unusual spend patterns | 3-7 days engineering or third-party tool |
The bare minimum every production system needs: provider-side spending limits, daily alert thresholds, and per-API-key isolation between dev and prod. These take an hour total to set up and prevent the worst cost incidents.
Per-user cost attribution
At scale, knowing which users drive the most AI cost matters. A small percentage of power users often account for the majority of cost — the classic 80/20 distribution shows up clearly in AI usage. Some users send 10 messages per day; others send 500.
Tracking per-user costs requires structured logging at the API call level. Most teams log requests but not the token counts. Adding per-request token counts to your application logs takes minutes and enables cost analysis that pays back quickly.
Common patterns from per-user attribution: free-tier users typically cost 5-10× their average monthly. The top 1% of power users often consume 30-50% of total API spend. This data is essential for pricing decisions and rate-limit calibration.
When fine-tuning saves money
Fine-tuning a smaller open model on your specific task can replace expensive API calls. The math has shifted dramatically as smaller models have improved.
| Task type | Approach | Cost vs frontier API |
|---|---|---|
| Generic Q&A, brainstorming | Use frontier API | Baseline |
| Classification (categorizing text) | Fine-tune 7B-13B model | 5-20× cheaper at scale |
| Structured data extraction | Fine-tune 7B model | 10-50× cheaper |
| Domain-specific writing (legal, medical) | Fine-tune 13B-70B model | 3-10× cheaper |
| General writing assistant | Use frontier API | Fine-tuning rarely beats |
| Code completion (single language) | Fine-tune 7B-13B model | 5-15× cheaper |
Fine-tuning cost itself is real — typically $500-5,000 for the training run plus ongoing inference infrastructure. Break-even point is usually 1-10 million tokens of inference per month, depending on task and model size. Below that, APIs win.
Building a cost dashboard that actually gets used
Cost dashboards exist in every AI-using organization; most go unused after the first week. The ones that get used share a few characteristics:
- Daily cost visible on the company Slack or homepage. Out of sight = out of mind. Make cost a default-visible number.
- Break down by feature, not by model. Engineers want to know what their code costs, not what model it uses.
- Track cost per active user. Total cost grows with scale but cost per user reveals efficiency trends.
- Compare to revenue / budget. $5,000/month feels different at $50K MRR vs $50K seed funding.
- Alert on changes, not absolute thresholds. 30% week-over-week increases matter more than crossing arbitrary budget lines.
Monthly bill audit checklist
Once a month, do a quick audit. Compare actual spend to projected spend, identify the largest cost line items, and check whether any usage pattern has changed unexpectedly.
Common mistakes
- Not setting hard rate limits in production. A bug that loops API calls can rack up thousands of dollars in hours. Set spend alerts and hard caps at the API key level.
- Treating per-request cost as the metric. "$0.004 per request" sounds fine until you have 10,000 requests/day. Budget by monthly total, not per-call.
- Using the same model for every task. Classification, summarization, and creative writing have very different model requirements. Routing saves money.
- Ignoring context caching offers. If you send the same long context repeatedly (RAG, document Q&A), prompt caching from your provider can cut input costs 50-90%.
- Forgetting to monitor. Set up daily/weekly cost dashboards. The team that finds out about a 10× cost spike at month-end is the team that learns the hard way to monitor in real-time.
Questions and answers
How accurate are the API providers' usage dashboards?
Generally very accurate — within 1-2% of actual billed amount. Discrepancies come from rounding and timezone-related cutoffs at month boundaries.
Do API providers offer volume discounts?
Enterprise contracts (typically $10K+/month commitment) sometimes include 15-30% discounts. Standard PAYG pricing is the same regardless of volume — there's no automatic tier discount in published rates.
What's the most underused cost-saving feature?
Context caching, as of 2025. Most teams either don't know about it or haven't implemented it. For RAG and document-heavy applications, it's typically 30-70% savings essentially for free.
Sources
- OpenAI, Anthropic, Google AI: published pricing pages (verify current rates)
- Together AI, Modal, Replicate: hosted inference pricing
- Lambda Labs, RunPod, vast.ai: GPU rental pricing
- Artificial Analysis: independent model comparison benchmarks
Related: AI Inference Cost · AI Tokens Per Word · RAG System Cost · Vector Database Cost