How the AI API Token Cost Works
AI-native SaaS companies face variable Cost of Goods Sold (COGS) that traditional software never had. While classic SaaS easily achieves 80%–85% gross margins, an unoptimized LLM wrapper using a flagship model on heavy chat histories can burn 40%–70% of subscription revenue on token fees alone. Modeling token volume, output ratios, and prompt caching upfront prevents pricing a product into negative unit economics.
Exact Mathematical Formula
Monthly Requests = DAU × Requests_Per_Day × 30
Input Tokens (M) = (Monthly Requests × Input_Tokens) / 1,000,000
Output Tokens (M) = (Monthly Requests × Output_Tokens) / 1,000,000
Effective Input Factor = (1 - Cache_Rate) + (Cache_Rate × 0.25)
Monthly API Cost = (Input_M × Effective_Factor × Input_Rate) + (Output_M × Output_Rate)
AI Gross Margin (%) = ((Price_Per_User - Cost_Per_User) / Price_Per_User) × 100
Step-by-Step Worked Example
Suppose a B2B SaaS app has 500 daily active users averaging 10 requests per day (150,000 monthly requests). Each request sends 2,000 input tokens (300M input tokens/month) and generates 500 output tokens (75M output tokens/month). At $1.25/1M input and $5.00/1M output with a 50% prompt cache hit rate, effective input drops by 37.5% to $234.38, plus $375.00 in output = $609.38/month ($1.22 per active user). On a $29/month plan, AI gross margin is a healthy 95.8%.
Industry Benchmarks & Reference Ranges
| Model Tier | Typical Input / 1M | Typical Output / 1M | Best Production Use Case |
|---|---|---|---|
| Economy / Flash | $0.10 – $0.30 | $0.40 – $0.80 | Classification, extraction, high-volume chat, routing |
| Mid-Tier Balanced | $1.00 – $1.50 | $4.00 – $6.00 | General SaaS copilots, summarization, RAG workflows |
| Frontier Flagship | $2.50 – $5.00 | $10.00 – $18.00 | Complex code generation, multi-step agents, synthesis |
| Heavy Reasoning | $8.00 – $15.00 | $25.00 – $60.00 | Deep research, audits, financial or legal verification |
Practical Ways to Improve This Metric
- Route 70%–85% of simple tasks (intent classification, formatting, short replies) to Flash/Economy models and escalate only complex queries to frontier models.
- Keep static system prompts and shared documents at the exact beginning of every prompt to maximize provider prompt caching (often 50%–90% cheaper on cached prefixes).
- Cap max_output_tokens and prefer concise JSON schemas—output tokens usually cost 3× to 5× more than input tokens.
- Summarize rolling chat history after 6–10 turns instead of re-sending the entire transcript on every message.
- Measure cost at the 95th percentile power user, not just the median user—power users often generate 10× average token costs on unlimited plans.