AI spend and model operations
Reduce LLM API Costs: Techniques That Protect Quality
How to reduce LLM API costs with model routing, prompt caching, batch APIs, context trimming, output limits, and per-workflow unit cost tracking.
Why is my LLM API bill so high?
Most LLM bills grow for a few plain reasons. Every request goes to the same large model regardless of difficulty. Prompts carry long instructions, documents, or conversation history that are re-sent on every call. Outputs run longer than anyone needs. Retries and agent loops multiply calls without anyone noticing. And jobs that could wait hours run at real-time prices.
None of these show up clearly on a provider invoice, which reports spend by model and by day. To cut cost without hurting quality, you need to see spend by workflow and by task, then decide which technique fits each one.
Start with attribution
Tag every request with the workflow, task type, and environment that produced it. Log input tokens, cached tokens, output tokens, model, latency, and retries. Without that, cost work is guesswork.
Which LLM cost optimization techniques work best?
The right technique depends on the workload. This table maps common techniques to where they help and what to watch.
- Technique
- Model routing and cascades
- What it does
- Sends easy requests to a smaller model and escalates hard ones to a larger model.
- Best for
- Mixed workloads with many simple requests.
- What to watch
- Routing errors on hard cases. Measure quality per route.
- Technique
- Prompt caching
- What it does
- Reuses processing for a repeated prompt prefix, billed at a reduced input rate.
- Best for
- Long, stable system prompts, tool definitions, or shared documents.
- What to watch
- Cache only helps when the prefix is identical and reused within the cache lifetime.
- Technique
- Batch APIs
- What it does
- Submits requests asynchronously for later processing at a discounted rate.
- Best for
- Evaluations, backfills, classification, and nightly jobs.
- What to watch
- Results are not immediate. Not suitable for user-facing requests.
- Technique
- Context trimming
- What it does
- Removes irrelevant history, documents, and instructions from each request.
- Best for
- Chat history, retrieval pipelines, and agent loops.
- What to watch
- Cutting context the model actually needs lowers quality.
- Technique
- Output length limits
- What it does
- Caps maximum output and asks for concise, structured responses.
- Best for
- Extraction, classification, and short drafting tasks.
- What to watch
- Truncated answers. Set limits from observed needs.
- Technique
- Smaller or open models
- What it does
- Uses a cheaper hosted model or a self-hosted open model for suitable tasks.
- Best for
- High-volume, well-defined tasks.
- What to watch
- Hosting, operations, and quality differences on edge cases.
- Technique
- Semantic caching
- What it does
- Returns a stored answer when a new request closely matches a past one.
- Best for
- Repeated FAQ-style questions with stable answers.
- What to watch
- Stale or wrong matches. Needs a similarity threshold and expiry.
- Technique
- Retry and loop control
- What it does
- Limits retries, agent steps, and tool calls per task.
- Best for
- Agents and pipelines with automatic retries.
- What to watch
- Silent loops that multiply cost. Set hard step budgets.
How much do prompt caching and batch APIs save?
Major providers publish discounts for caching and batching. The figures below are taken from each provider's documentation page at the time of writing. Rates differ by model and change over time, so check the linked pages before you model savings.
OpenAI prompt caching
- OpenAI's prompt caching guide says reused input tokens are billed at a reduced cached-input rate, "discounted up to 95%," and that caching is on by default for supported models. The guide also documents a cache-write charge on newer models.
- Requests share a long, identical prefix such as instructions or tool definitions.
OpenAI Batch API
- OpenAI's Batch API guide lists a "50% cost discount compared to synchronous APIs," with a 24-hour completion window.
- Work can wait up to a day, such as evaluations or bulk classification.
Anthropic prompt caching
- Anthropic's documentation says cache reads cost 10 percent of the base input token price, with per-model exceptions, and 5-minute cache writes cost 25 percent more than base input tokens.
- Long system prompts or documents are reused across many requests within minutes.
Anthropic Message Batches API
- Anthropic's batch processing documentation says all batch usage is charged at 50 percent of standard API prices, and that caching and batch discounts can stack.
- Large volumes of requests do not need an immediate response.
Google Gemini Batch API
- Google's Gemini batch documentation says batch usage is priced at 50% of the standard interactive API cost for the equivalent model, with a 24-hour target turnaround.
- Bulk jobs on Gemini models can run asynchronously.
Google Gemini context caching
- Google's context caching documentation says implicit caching is enabled by default on Gemini 2.5 and newer models and that cost savings are passed on when requests hit the cache. Explicit caching is also available on supported models.
- Requests repeat the same large context, such as a long document or video.
How do you lower an OpenAI or other LLM API bill step by step?
Work in this order. Each step is cheaper and safer than the next, and each one makes the next easier to judge.
- 01
Attribute spend to workflows
Tag requests by workflow and task, and calculate cost per completed task, not just total spend per model. - 02
Fix waste first
Remove duplicate calls, cap retries, set agent step budgets, and stop sending unused history or documents. - 03
Cap output length
Set maximum output tokens from real needs and ask for structured, concise responses where possible. - 04
Restructure prompts for caching
Put stable instructions, tools, and shared documents at the start of the prompt and variable content at the end, so prefixes match. - 05
Move non-urgent work to batch
Identify evaluations, backfills, and scheduled jobs that can tolerate delayed results and submit them through batch endpoints. - 06
Build an evaluation set
Collect representative inputs with known good outputs for each workflow before changing models. - 07
Test smaller models and routes
Run candidate models or a routing cascade against the evaluation set and compare quality, latency, and cost per task. - 08
Roll out gradually and monitor
Shift a share of traffic, watch quality and unit cost, and keep a quick path back to the previous route.
When should you switch to a cheaper model?
Switching models is the change most likely to save money and most likely to hurt quality. Use these gates.
- 01
Do you have an evaluation set that reflects real traffic, including hard cases?
- If yes
- Run the candidate model against it before any production change.
- If no
- Build one first. Without it, you cannot tell savings from quality loss.
- 02
Does the cheaper model meet the acceptance bar on every task type that matters?
- If yes
- Route those task types to it and keep the larger model for the rest.
- If no
- Consider a cascade that escalates uncertain cases, or keep the current model for that task.
- 03
Is cost per completed task lower after counting retries and escalations?
- If yes
- Proceed with a gradual rollout and monitoring.
- If no
- The switch is not saving money. Revisit prompt and context changes instead.
- 04
Can you roll back quickly if quality drops in production?
- If yes
- Ship the change behind a routing flag.
- If no
- Add a rollback path before switching.
What should you monitor after cutting LLM costs?
Savings erode quietly when prompts drift, traffic changes, or providers update models. Track these per workflow.
- ✓
Cost per completed task
The main unit metric. Total spend can rise with volume while unit cost falls. - ✓
Cache hit rate
Falling hit rates usually mean someone changed the prompt prefix or added variable content early in the prompt. - ✓
Quality on the evaluation set
Rerun it on a schedule and after every model, prompt, or provider change. - ✓
Escalation and retry rates
Rising escalations in a cascade can cancel out the savings of the smaller model. - ✓
Output token distribution
Watch for outputs growing over time as prompts are edited. - ✓
Provider pricing changes
Review provider pricing pages regularly. Rates and discounts change, and older models are retired.
What should you avoid when reducing LLM spend?
Avoid switching models based on public benchmarks alone. Benchmarks measure general tasks, not your workflow, and a model that scores well overall can still fail your specific exceptions.
Avoid treating total spend as the target. A workflow that handles twice the volume at a lower cost per task is a success, even if the bill went up. Set targets on unit cost and quality together.
Avoid one-time cleanups. Cost work holds only when attribution, evaluation, and monitoring keep running. Assign an owner for model spend the same way you would for cloud spend.
Questions this article answers
What is the fastest way to reduce LLM API costs?
Remove waste first: cap retries and agent steps, stop re-sending unused history, and limit output length. These changes rarely hurt quality. Then restructure prompts so stable content comes first and can be cached, and move non-urgent jobs to a batch API.
Does prompt caching reduce quality?
No. Prompt caching reuses processing for an identical prompt prefix, so the model sees the same input. It changes cost and latency, not the answer. Savings depend on how much of each prompt is identical and how often it is reused within the cache lifetime.
Is the batch API worth using?
Yes, for work that can wait. OpenAI, Anthropic, and Google each document a 50 percent batch discount on their batch pages. Evaluations, backfills, bulk classification, and nightly reports are common fits. User-facing requests usually are not, because results arrive later.
Should I switch to an open-source model to save money?
Sometimes. Open models can lower per-request cost for high-volume, well-defined tasks, but you take on hosting, scaling, security, and updates. Compare full cost per task, including operations, and test quality on your own evaluation set before switching.
How do I measure LLM cost per workflow?
Tag each request with its workflow and task, log tokens, cached tokens, model, and retries, and divide total spend for that workflow by the number of tasks completed. Track it over time alongside quality so you can see whether changes help.
What is model routing?
Model routing sends each request to the model best suited to it, usually a cheaper model for simple tasks and a stronger one for hard tasks. A cascade tries the cheaper model first and escalates when confidence is low or checks fail.
Next step
Review one LLM bill
Bring task-level usage if available. The review can find attribution gaps, caching and batch candidates, and models worth testing.