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 TierTypical Input / 1MTypical Output / 1MBest Production Use Case
Economy / Flash$0.10 – $0.30$0.40 – $0.80Classification, extraction, high-volume chat, routing
Mid-Tier Balanced$1.00 – $1.50$4.00 – $6.00General SaaS copilots, summarization, RAG workflows
Frontier Flagship$2.50 – $5.00$10.00 – $18.00Complex code generation, multi-step agents, synthesis
Heavy Reasoning$8.00 – $15.00$25.00 – $60.00Deep 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.

Frequently Asked Questions

How many words equal 1,000 tokens in most LLMs?
In English prose, 1,000 tokens equals roughly 750 words (about 4 characters per token). Code, JSON payloads, and non-Latin languages such as Arabic or Japanese typically use more tokens per word.
Why do output tokens cost much more than input tokens?
Input tokens are processed in parallel during the prefill phase, whereas output tokens must be generated sequentially one token at a time while reading the full KV cache from GPU memory, making generation far more compute- and memory-bandwidth intensive.
What is a healthy AI gross margin for a SaaS business?
Top-performing AI SaaS companies target 70%–85% gross margins after LLM API and hosting costs. If AI API spend exceeds 25%–30% of user revenue, consider tiered usage limits, model routing, or higher pricing.
How much does prompt caching actually save?
Major providers discount cached input tokens by 50% to 90% (this calculator models a realistic 75% discount on cached inputs). Apps with large system prompts, long RAG documents, or multi-turn agent loops benefit the most.
Should I price my AI app flat-rate or usage-based?
Hybrid pricing usually performs best: include a generous credit allowance inside a predictable monthly subscription so buyers feel safe, while protecting your margin with overage tiers or top-up packs for heavy power users.