LLM API costs can scale faster than revenue if left unchecked. A production app making 10 million API calls per day at $0.01 per call spends $100,000/month. Most teams discover this problem after launch, not before. This guide covers 9 proven strategies to cut LLM API costs in production — from prompt engineering and caching to model routing, batching, and self-hosting — with real numbers on the savings each approach delivers.
Strategy 1: Switch to a cheaper model for simple tasks
The single biggest lever is model selection. GPT-4o costs $2.50/1M input tokens and $10/1M output tokens. GPT-4o-mini costs $0.15/$0.60 — a 16x reduction. For tasks that don't require frontier reasoning (classification, summarisation, extraction, simple Q&A), a smaller model performs identically at a fraction of the cost.
Run an A/B test: route 10% of traffic to the cheaper model and compare output quality on your specific task. Most teams find that 60–80% of their requests can be handled by a model 5–10x cheaper than their current choice. See live LLM pricing to compare current rates across all providers.
Build a routing layer that classifies request complexity and routes to the appropriate model tier. Simple requests (single-turn, short context, factual) go to a budget model. Complex requests (multi-turn, long context, reasoning) go to a frontier model. A well-tuned router can cut costs by 40–60% with no quality degradation on complex tasks.
Strategy 2: Implement semantic caching
Semantic caching stores LLM responses and returns cached results for semantically similar future queries — not just exact matches. If 1,000 users ask variations of "what is your return policy?", you pay for one LLM call and serve the rest from cache.
Tools like GPTCache, Redis with vector search, or a simple embedding similarity lookup implement this pattern. Embed each incoming query, search for similar cached queries above a similarity threshold (typically 0.92–0.95 cosine similarity), and return the cached response if found. Cache hit rates of 20–40% are common for customer-facing apps with repetitive query patterns.
At a 30% cache hit rate on 10M daily requests at $0.01/call, semantic caching saves $30,000/month. The cost of running the embedding model and vector search is typically 100–200x cheaper than the LLM call it replaces. Use a fast embedding model (text-embedding-3-small at $0.02/1M tokens) for cache lookups.
Strategy 3: Use the Batch API for async workloads
OpenAI, Anthropic, and Google all offer batch APIs that process requests asynchronously (within 24 hours) at a 50% discount. If your workload doesn't require real-time responses — document processing, content generation, data extraction, nightly analysis — the batch API cuts your bill in half immediately.
OpenAI Batch API: submit a JSONL file of requests, get results back within 24 hours at 50% off standard pricing. Anthropic Message Batches API: same model, same quality, 50% discount. Google Vertex AI batch prediction: similar pricing structure.
Identify which parts of your pipeline are async: nightly report generation, bulk document indexing, content moderation queues, email drafting. Move all of these to batch APIs. For a pipeline processing 1M documents/day at $0.01/call, batch API saves $1,500/day ($45,000/month). See the Batch Processing Cost Guide for architecture patterns.
Strategy 4: Reduce prompt size with compression
Input tokens are billed per token — shorter prompts cost less. Most production prompts have significant room for compression without quality loss. Common sources of bloat: verbose system prompts, redundant instructions, unnecessary examples, whitespace and formatting, and over-specified output schemas.
Audit your system prompt. A 2,000-token system prompt that can be compressed to 800 tokens saves 1,200 tokens per request. At 10M requests/day with GPT-4o ($2.50/1M input tokens), that's $30,000/month in savings from prompt compression alone.
For RAG pipelines, retrieval quality directly affects cost. A poorly tuned retriever returns 10 chunks when 3 would suffice — you're paying for 7 unnecessary chunks of context on every request. Tune your similarity threshold and top-k parameter. Reranking retrieved chunks and keeping only the top 3 can cut RAG context costs by 50–70%.
LLMLingua and similar prompt compression tools use a small model to compress long prompts by removing low-information tokens while preserving meaning. They report 3–20x compression ratios with under 5% quality loss on most tasks — though results vary significantly by prompt type.
Strategy 5: Enable prompt caching
Anthropic Claude and Google Gemini support prompt caching — if you send the same prefix (system prompt + static context) repeatedly, the provider caches the KV state and charges a reduced rate for cache hits. Anthropic charges 10% of the input token price for cache reads (90% discount). Google Gemini charges 25% for cache reads.
This is most valuable when you have a large, static system prompt or document context that's the same across many requests. A 10,000-token system prompt sent with every request costs $0.025 per call at GPT-4o rates. With Anthropic's prompt caching, that drops to $0.0025 per call after the first request — a 90% reduction on the static portion.
To use Anthropic prompt caching, add `"cache_control": {"type": "ephemeral"}` to the content blocks you want cached. The cache persists for 5 minutes (refreshed on each use). For high-traffic apps, this alone can cut costs by 30–50% if your system prompt is large.
Strategy 6: Switch providers for better rates
The same model often costs significantly different amounts across providers. Llama 3.1 70B ranges from $0.12/1M tokens (Groq) to $0.88/1M tokens (Together AI) to $2.49/hr self-hosted. For open-weight models, shopping providers can cut costs by 3–7x with zero code changes beyond the base URL.
Use a proxy like LiteLLM to abstract provider selection. LiteLLM supports 100+ providers with a unified OpenAI-compatible API. You can implement fallbacks (if Provider A is down, route to Provider B), load balancing across providers, and cost-based routing (always use the cheapest provider that meets your latency SLA).
Check live LLM pricing regularly — provider prices change frequently. Set up a monthly cost review: compare your current provider's rates against alternatives for your top 3 most-used models. A 30-minute review can identify 20–40% savings opportunities.
Strategy 7: Optimise output length
Output tokens are typically 3–4x more expensive than input tokens (GPT-4o: $2.50 input vs $10 output per 1M tokens). Reducing output length has an outsized impact on cost. Two techniques work well: explicit length instructions and structured output.
Add explicit length constraints to your prompt: "Respond in 2–3 sentences", "Return a JSON object with exactly these fields", "Summarise in under 100 words". Models generally follow these instructions. Reducing average output from 300 tokens to 150 tokens cuts output costs in half.
Use structured output (JSON mode or function calling) instead of free-form text when you only need specific fields. A model generating a JSON object with 5 fields uses far fewer tokens than one writing a paragraph that you then parse. OpenAI's structured outputs and Anthropic's tool use both support this pattern.
Strategy 8: Self-host at scale
Above a certain token volume, self-hosting open-weight models on GPU cloud infrastructure beats managed APIs on cost. The break-even point depends on the model tier: for GPT-4o-class tasks, self-hosting isn't yet viable (no open-weight equivalent). For GPT-4o-mini-class tasks, Llama 3.1 8B on a $0.40/hr RTX 4090 costs under $0.00006/1K tokens at full utilisation — 250x cheaper than GPT-4o-mini.
The break-even vs managed APIs for Llama 3.1 8B is approximately 5M tokens/day — above that, self-hosting is cheaper. For the 70B model (GPT-4-class quality), break-even is around 20M tokens/day on an H100. Use the LLM ROI Calculator to model your specific volume.
Self-hosting requires engineering investment: setting up vLLM, managing GPU instances, handling model updates, and monitoring. Budget 40–80 hours of initial setup and 5–10 hours/month of ongoing maintenance. Factor this into your cost comparison — at low volumes, the engineering cost exceeds the API savings.
Strategy 9: Implement request deduplication
In high-traffic apps, the same request is often made multiple times in quick succession — a user double-clicking a button, a retry on network error, or multiple users asking the same question simultaneously. Request deduplication prevents paying for the same LLM call twice.
Implement an in-flight request cache: when a request arrives, check if an identical request is already being processed. If so, wait for the in-flight result and return it to both callers. Use a hash of the request parameters (model, messages, temperature) as the cache key. This is different from semantic caching — it only deduplicates exact concurrent requests, not similar historical ones.
For idempotency keys, accept a client-provided `X-Idempotency-Key` header and cache responses by key for 60 seconds. If the client retries with the same key (network error, timeout), return the cached response without making another LLM call. This is especially important for expensive long-context requests where retries are costly.