How LLM Pricing Works — A Complete Guide
LLM APIs charge per million tokens — separately for input and output. This guide covers every pricing dimension: input/output split, cache pricing, batch discounts, context window costs, and why your bill keeps growing.
The basic formula
Cost = (input_tokens / 1,000,000) × price_per_M_input + (output_tokens / 1,000,000) × price_per_M_output. Every other pricing feature is a modifier on top of this.
Why output costs 3–5× more than input
Input tokens go through the model's forward pass once. Output tokens are generated one at a time — each requires a full forward pass through the model. This is fundamentally more compute. At scale, minimizing output token length has outsized cost impact.
Prompt caching: the biggest cost lever
Anthropic (Claude), OpenAI (GPT), and Google (Gemini) all offer prompt caching — storing a reusable prefix so you don't re-process it on every call. Cached reads cost 5–10× less than standard input. If you have a long system prompt used across many calls, caching should be your first optimization.
Batch API: 50% off for async workloads
All major providers offer batch APIs (results in <24h, not real-time): OpenAI Batch API, Anthropic Message Batches, Gemini Batch. These cut costs by ~50% with no quality trade-off. Any pipeline that doesn't need real-time results should use batch.
Context window pricing surprises
You only pay for tokens actually used, not the context window size. But in practice, long contexts cost more because: (1) every turn in a conversation re-sends the full history, (2) long system prompts compound, (3) RAG adds retrieved chunks. A 20-turn conversation with a 2K system prompt uses ~50K+ tokens just for repeated context.
Related calculators
Related guides
Frequently Asked Questions
Why is my LLM bill higher than expected?
Common causes: (1) System prompt re-sent on every call — enable caching. (2) Full conversation history — use sliding window or summarization. (3) Long retrieved chunks in RAG — reduce chunk count. (4) Using a flagship model where a mid-tier model would do. Run your workload through the Agent Cost Calculator to find where the money goes.
Is there a free tier for LLM APIs?
Most providers offer free credits on signup ($5–$20). Ongoing free usage is limited: Anthropic and OpenAI have no ongoing free tier for production use. Google Gemini has a free tier with rate limits. For production workloads, budget for paid usage from the start.
Guide updated 2026-08-20. Pricing data verified weekly. See methodology · sources.