How LLM API Pricing Works
LLM APIs charge per token — the fundamental unit of text that language models process. A token is approximately 4 characters or ¾ of a word in English. Prices are quoted per 1 million tokens (1M tokens) in USD, split into input tokens (your prompt) and output tokens (the model's response).
For example, GPT-4o charges $2.50 per 1M input tokens and $10.00 per 1M output tokens (as of July 2026). A typical chat message of 500 input tokens and 200 output tokens costs: (500/1,000,000 × $2.50) + (200/1,000,000 × $10.00) = $0.00125 + $0.002 = $0.00325 per message. See the live LLM pricing table for current rates across all providers.
Input vs Output Token Pricing
Output tokens are almost always more expensive than input tokens — typically 3–5× more. This is because generating tokens requires sequential computation (each token depends on all previous tokens), while processing input tokens can be parallelized. For cost optimization, minimize output length where possible — use structured outputs, set max_tokens limits, and instruct the model to be concise.
The input/output ratio of your application significantly affects total cost. A RAG (retrieval-augmented generation) system with large context windows will have a high input:output ratio and benefit from providers with low input pricing. A creative writing tool with short prompts and long outputs benefits from low output pricing. Compare OpenAI vs Anthropic token pricing to see how the two leading providers stack up.
Prompt Caching: The Biggest Cost Reducer
Prompt caching is the most impactful cost optimization available in 2026. OpenAI, Anthropic, and Google all offer cached input pricing at 50–75% off standard input rates for repeated prompt prefixes. If your application uses a consistent system prompt (e.g., a 2,000-token system prompt sent with every request), caching reduces those tokens to $0.625/1M instead of $2.50/1M on GPT-4o — a 75% reduction.
To maximize cache hits: (1) place static content (system prompts, few-shot examples, retrieved documents) at the beginning of your prompt; (2) keep the cached prefix identical across requests; (3) use the same model version — caches are model-version specific.
Batch API Discounts
OpenAI's Batch API offers 50% off standard pricing for asynchronous requests with a 24-hour completion window. Anthropic's Message Batches API offers similar discounts. For workloads that don't require real-time responses — data processing, content generation, evaluation pipelines — batch APIs can halve your LLM costs.
Google's Vertex AI offers batch prediction at 50% off for Gemini models. Together AI and Fireworks AI offer batch endpoints for open-weight models at competitive rates. Use the LLM provider comparison tool to find the cheapest provider for your specific model and volume.
Cost Estimation Formula
To estimate monthly LLM API costs: (1) measure your average input tokens per request; (2) measure your average output tokens per request; (3) estimate monthly request volume; (4) apply the formula: Monthly cost = (avg_input_tokens × monthly_requests / 1,000,000 × input_price) + (avg_output_tokens × monthly_requests / 1,000,000 × output_price).
Example: 10,000 daily requests, 1,000 input tokens, 500 output tokens, GPT-4o pricing: (1,000 × 300,000 / 1M × $2.50) + (500 × 300,000 / 1M × $10.00) = $750 + $1,500 = $2,250/month. With prompt caching on a 500-token system prompt: save ~$375/month, reducing total to ~$1,875/month. Track LLM price history and trends to see how costs have fallen over time.