LLM API costs grow super-linearly with product success. A prototype that costs $50/month can cost $5,000/month at modest scale if you haven't optimised. Here are seven techniques ranked by impact-to-effort ratio.
1. Use prompt caching (biggest single win)
Anthropic and OpenAI both support prompt caching — if the first N tokens of your prompt are identical across requests, they're cached and billed at ~10% of the normal input rate. For apps with long system prompts (instructions, examples, context), this alone can cut costs by 50–80%.
Tip
Anthropic: use cache_control: {type: "ephemeral"} on message blocks. OpenAI: prefix cache is automatic on inputs >1,024 tokens.
2. Use the Batch API for async workloads
If your workload doesn't need a real-time response — classification, extraction, nightly summaries — use the Batch API. All major providers offer 50% off standard pricing for batch jobs with up to 24-hour turnaround. See the ModelStop batch pricing page for a full comparison.
3. Route by task complexity (model cascading)
Not every request needs your most powerful model. Build a simple classifier that routes easy requests (FAQ lookup, intent detection, simple extraction) to a cheap model, and hard requests (nuanced reasoning, multi-step planning) to a frontier model. A 70/30 split at a 10:1 cost ratio saves 63% vs sending everything to the expensive model.
4. Compress your context window
Output tokens cost 3–5× more than input tokens on most providers, but input tokens at scale still add up. Techniques: truncate conversation history to the last N turns, summarise old context, use embeddings + retrieval instead of stuffing full documents, and strip whitespace from structured outputs.
5. Constrain your outputs
Unconstrained generation is wasteful. If you need a JSON object, say so explicitly and use structured output mode (supported by all major providers). For classification, use logprobs or constrain to a fixed token set. For summaries, set a max_tokens budget. Output tokens are your biggest lever.
6. Downgrade to a cheaper model and eval the diff
The quality gap between GPT-4o and GPT-4o mini is much smaller than the 17× price gap for most real-world tasks. Run an A/B eval on your production traffic before assuming you need the expensive model. For many tasks, the cheaper model performs within 5% on your actual quality metric.
7. Self-host for predictable high-volume workloads
At sufficient scale (millions of requests/day), self-hosting an open-weights model on dedicated GPU instances can be 10–50× cheaper than API pricing. The break-even point varies by model size and GPU cost — typically around $500–2,000/month in API spend. Llama 3.1 70B on 2× A100s via vLLM is a common production setup.
Tip
Use Together AI or Fireworks AI as a managed open-source inference layer before committing to self-hosting — lower ops overhead, still 50–80% cheaper than OpenAI/Anthropic.
