Most companies building with LLMs are spending far more than they need to. We routinely see organizations burning through $10,000 to $100,000+ per month on API calls, with no visibility into where that money is going or whether the most expensive model is even necessary for every request.
The root cause is straightforward: teams default to the most powerful model for every task. They send every classification, every extraction, every summarization request to GPT-4o or Claude Opus because it works, and because the per-request cost feels negligible. But at scale, those fractions of a cent compound into five- and six-figure monthly invoices.
The good news: LLM cost optimization is largely an engineering problem, and the techniques are well-understood. You do not need to sacrifice output quality to cut costs dramatically. What you need is a systematic approach to understanding your workload, matching models to tasks, and eliminating waste.
This guide covers the nine highest-impact techniques we use with clients, ranked from easiest to implement to most complex. Most teams can cut their LLM spending by 40-60% in the first week by applying the first four sections alone.
Before optimizing anything, you need to know where your money is going. LLM costs break down into several distinct components, and the distribution varies dramatically by application.
Before optimizing, measure. Track cost per request, cost per user, and cost per feature. You cannot optimize what you do not measure. Even a simple per-endpoint cost log will reveal where 80% of your spend is concentrated.
Several tools make LLM cost tracking straightforward:
usage field from API responses to your database. Multiply token counts by published pricing. This takes an afternoon to build and gives you everything you need.Once you have a week of data, you will almost certainly find that a small number of endpoints or features account for the majority of your spend. That is where to focus first.
The cheapest token is the one you never send. Prompt optimization is the fastest, lowest-risk way to reduce LLM costs, and most teams have significant room for improvement.
System prompts tend to accumulate instructions over time. We regularly see system prompts of 2,000-5,000 tokens that could be compressed to 300-500 tokens with no loss of quality. Every token in your system prompt is sent with every single request.
The math: a 2,000-token system prompt at GPT-4o input pricing ($2.50 per 1M tokens) costs $5 per million requests. Compress it to 500 tokens and you save $3.75 per million requests. At 100K requests per day, that is $1,125/month saved from a single change.
Few-shot examples are excellent during development but expensive in production. Each example adds hundreds of tokens per request. Modern models (GPT-4o, Claude 3.5 Sonnet and above) handle most tasks well with clear zero-shot instructions. Test your prompts without examples -- you may find that quality is comparable, especially for well-defined tasks like classification and extraction.
Requesting JSON output (using provider JSON mode or structured outputs) reduces token waste from natural language responses. Instead of "The sentiment of this review is positive because the customer expressed satisfaction with the delivery speed and product quality," you get {"sentiment": "positive", "confidence": 0.94}. Fewer output tokens, easier to parse, cheaper to generate.
For RAG applications, the context you inject often contains redundant information. Techniques that help:
Both Anthropic and OpenAI now offer prompt caching that reduces input token costs by 50-90% for repeated prompt prefixes. If your system prompt or few-shot examples are identical across requests, the provider caches the processed tokens and charges a fraction of the normal input price. This is essentially free money -- you enable it with a minor API change and immediately save on every request that shares a common prefix.
Quick win: Audit your top 5 highest-cost endpoints. For each one, check the system prompt length, whether few-shot examples are necessary, and whether the output format is as concise as possible. Most teams find 30-50% token savings from this exercise alone.
This is the single highest-impact optimization for most teams. The price difference between frontier and mid-tier models is 10-30x, and for the majority of tasks, the cheaper model performs just as well.
| Model Tier | Examples | Best For | Relative Cost |
|---|---|---|---|
| Frontier | GPT-4o, Claude Opus, Gemini Ultra | Complex reasoning, nuanced code generation, multi-step planning, ambiguous tasks | 1x (baseline) |
| Mid-tier | GPT-4o-mini, Claude Sonnet, Gemini Flash | Summarization, translation, moderate reasoning, structured extraction | 0.03-0.1x |
| Small / Fast | Claude Haiku, Gemini Flash 8B | Classification, routing, simple Q&A, intent detection, filtering | 0.01-0.03x |
| Self-hosted | Llama 3.1 70B/8B, Mistral, Qwen | High-volume tasks, privacy requirements, predictable workloads | Fixed cost (volume-dependent) |
| Specialized | text-embedding-3-small, Cohere Embed | Embedding generation, search, semantic similarity | 0.001-0.01x |
The most effective cost optimization strategy is the model cascade: route each request to the cheapest model capable of handling it, and escalate only when needed.
Here is how it works in practice:
80% of LLM tasks do not need the most powerful model. Classification, extraction, formatting, simple Q&A, intent detection, and summarization can all be handled by models that cost 10-30x less than frontier models. Route simple tasks to smaller, cheaper models and reserve your budget for the tasks that actually require complex reasoning.
A well-implemented model cascade typically reduces costs by 40-60% with no measurable quality degradation on the tasks that were routed to cheaper models. The key is evaluating quality per task type, not globally. Your classification accuracy with Haiku might be 98% vs. 99% with Opus -- a difference that is rarely worth a 30x cost premium.
If the same question (or a sufficiently similar question) has been asked before, there is no reason to pay for a new LLM call. Caching is the second-highest-impact optimization after model routing, and it compounds over time as your cache warms up.
Cache hit rates vary by application type:
A 30% cache hit rate translates directly to a 30% cost reduction on the cached endpoints. Combined with model routing, you can achieve 50-70% total savings from these two techniques alone.
Not every LLM request needs a real-time response. For asynchronous workloads, batch processing can cut costs by 50% with no architectural complexity.
OpenAI's Batch API accepts a file of requests and processes them within a 24-hour window at 50% of the standard price. Same models, same quality, half the cost. The trade-off is latency: results come back hours later instead of seconds. For many workloads, this is perfectly acceptable.
For workloads that do not fit neatly into the Batch API, implement a queue-based architecture. Requests that do not need immediate responses go into a processing queue (SQS, Redis Queue, Celery). A worker processes them at a controlled rate, which also helps manage rate limits and smooth out traffic spikes. This does not directly reduce per-token costs, but it prevents expensive retry logic, reduces rate-limit errors, and lets you apply other optimizations (like batching multiple small requests into one larger call) more easily.
Self-hosting an LLM replaces variable per-token costs with fixed infrastructure costs. Whether this saves money depends entirely on your volume, your workload characteristics, and your team's operational capability.
| Deployment Model | Cost Structure | Best For | Break-Even Volume |
|---|---|---|---|
| API (OpenAI, Anthropic) | Pay per token, zero infrastructure | Variable workloads, prototyping, low-to-moderate volume | N/A (baseline) |
| Self-hosted GPU (dedicated) | Fixed monthly cost ($2-8K/GPU) | Predictable high-volume, privacy requirements, single-model deployments | ~10M tokens/month per model |
| Serverless GPU (Modal, RunPod, Replicate) | Pay per second of GPU time | Bursty workloads, variable demand, multiple model types | ~5M tokens/month (lower overhead) |
Self-hosting makes financial sense at 10M+ tokens/month for a single model. Below that volume, API costs are usually lower than GPU rental. Factor in operational overhead: model updates, scaling, monitoring, security patching, and the engineering time required to maintain the infrastructure. If your team does not have MLOps experience, the hidden costs of self-hosting can exceed the savings.
The most cost-effective architecture for many teams is hybrid: self-host a smaller model (Llama 3.1 8B or 70B) for high-volume, simpler tasks, and use API calls to frontier models (GPT-4o, Claude Opus) for complex tasks. This gives you the cost benefits of self-hosting where volume justifies it, without sacrificing quality on the tasks that need frontier capability.
Cost optimization is not a one-time project. Without ongoing monitoring, costs creep back up as new features ship, prompts evolve, and usage grows. Worse, runaway agents, prompt injection attacks, and infinite loops can cause sudden cost spikes that blow through budgets in hours.
Sudden cost spikes almost always indicate a problem:
Set up anomaly detection on your hourly and daily cost metrics. If spend exceeds 2x the trailing 7-day average for more than 30 minutes, alert your on-call team. This is no different from monitoring any other infrastructure cost -- treat your LLM spend with the same rigor you apply to cloud compute.
These are anonymized examples from client engagements and industry case studies. The techniques are the same ones described in this guide, applied in combination.
| Metric | Before | After |
|---|---|---|
| Monthly LLM spend | $45,000 | $12,000 |
| Cost reduction | 73% | |
Techniques applied: Model cascade (routed 70% of support queries to GPT-4o-mini), semantic caching (35% hit rate on common questions), prompt compression (reduced system prompt from 3,200 to 600 tokens), and conversation truncation (limited context window to last 5 turns + summary).
Key insight: The vast majority of customer support queries are simple, repetitive questions. Only escalation-worthy conversations -- billing disputes, technical debugging, complaints requiring empathy -- needed the frontier model. Customer satisfaction scores were unchanged after the switch.
| Metric | Before | After |
|---|---|---|
| Monthly LLM spend | $8,000 | $2,000 |
| Cost reduction | 75% | |
Techniques applied: Batch API for all document processing (50% cost reduction), self-hosted embedding model replacing OpenAI embeddings (90% reduction in embedding costs), and structured output format reducing output tokens by 40%.
Key insight: Document processing is an ideal batch workload. No user is waiting for real-time results -- documents are uploaded during the day and results are ready by morning. Switching to the Batch API was a single-day code change that halved the API bill immediately.
| Metric | Before | After |
|---|---|---|
| Monthly LLM spend | $15,000 | $4,000 |
| Cost reduction | 73% | |
Techniques applied: Model cascade with confidence-based escalation (GPT-4o-mini handled 85% of requests), response caching with 1-hour TTL (28% cache hit rate), and prompt optimization (removed redundant product catalog context, replaced with targeted retrieval).
Key insight: Product recommendations for returning customers are highly cacheable -- the same user browsing similar products generates nearly identical recommendation requests within a short time window. The 1-hour TTL was aggressive enough to stay fresh while catching the majority of repeat queries.
The pattern across all three cases is the same: measure your workload, route to cheaper models where quality is sufficient, cache what repeats, and batch what is not time-sensitive. No exotic techniques required -- just systematic application of these fundamentals.
We have helped companies reduce LLM spending from five figures to four. Book a call to discuss your optimization strategy.
Book a Free Call