To optimize LLM costs, measure where your tokens go, then pull the levers in order of payoff: prompt caching, output control, model routing, batching, and context trimming. Self-hosters add quantization. Most teams find that a handful of changes cover the bulk of the savings, and that the order matters more than the cleverness of any single trick.
This guide is for developers, founders and operations leads who already have an LLM feature in production, or are about to ship one, and want the bill to scale slower than usage. Token usage optimization is part of the story, but it is only one lever. 🎯
TL;DR
- Measure first. Log input tokens, output tokens, cache hits and cost per request, by feature, before you change anything.
- Output tokens usually cost 3x to 5x more than input tokens, so shaping the response often beats shortening the prompt.
- Cache stable prompt prefixes, batch anything that is not time-sensitive, and route simple requests to smaller models.
- Build an eval on a capable model first. Cheaper models without a quality baseline cost more than they save.
- Skip optimization for one-off queries. The effort pays off on high-volume, long-context and agentic workloads.
Table of Contents
- Why LLM bills grow faster than usage
- Step 1: Measure before you manage
- A worked example: where the money really goes
- The seven levers, in order of payoff
- When not to optimize
- A prioritization checklist
- Our perspective
- Compare tools before you commit
- FAQ
- Sources
Why LLM bills grow faster than usage
Per-token prices keep falling. The Stanford AI Index reports that the cost of querying a model at GPT-3.5 level fell from $20.00 to $0.07 per million tokens between November 2022 and October 2024, a drop of more than 280-fold. Yet many teams still watch their invoices climb.
The reason is structural. Products move from single prompts to multi-step agents, retrieval pipelines and long conversations. Each step resends context. A feature that once cost one call per user action now costs ten, each carrying thousands of tokens of instructions, tool definitions and history.
Cheap tokens reward waste. So the job is less about squeezing every token and more about designing the architecture around the model. Anthropic's cost cookbook frames it as an ongoing engineering discipline, not a one-time setup.

Step 1: Measure before you manage
You cannot optimize what you cannot see. Before touching a prompt, instrument every call with:
- Feature or route name
- Model and version
- Input tokens, cached input tokens and output tokens
- Latency
- Dollar cost, computed from the current price sheet
- A quality score from your eval, where you have one
Then sort by total spend, not by cost per call. A cheap call made 400,000 times a day beats an expensive call made twice. Most teams discover that one or two routes account for the majority of spend, and that is where you start.
Keep a baseline too. Anthropic's guidance on cost and intelligence is to build an evaluation and measure performance on a capable model first. Without that number, every later saving is a guess about quality.
A worked example: where the money really goes
Here is an illustrative workload. The prices are made up for round numbers, so swap in your provider's current rates.
- 10,000 requests per day
- 3,000 input tokens per request, of which 2,000 are a stable system prompt
- 500 output tokens per request
- Assumed rates: $1 per million input tokens, $4 per million output tokens
| Scenario | Daily input cost | Daily output cost | Total per day |
|---|---|---|---|
| Baseline | $30 | $20 | $50 |
| Stable prefix cached at a 90% discount | $12 | $20 | $32 |
| Whole workload batched at 50% off | $15 | $10 | $25 |
| Output capped to 300 tokens, with caching | $12 | $12 | $24 |
Two lessons. First, output is 14% of the tokens in this workload but 40% of the baseline bill. Second, the levers stack: caching plus output control halves the bill with no model change at all.
The seven levers, in order of payoff
1. Cache stable prompt prefixes
If your requests begin with the same system instructions, tool definitions or reference files, you are paying full price to reprocess them every time. Google Cloud's guidance says prompt caching can cut input costs by up to 90% and latency by up to 85%. Discounts vary by provider and model, so check the current sheet. OpenAI's original launch applied a 50% discount to cached input automatically on prompts over 1,024 tokens, and newer models have changed the terms since.
The common mistake is caching too much. Put the stable material first, and the dynamic, user-specific data after it. Anything that changes early in the prompt breaks the prefix and kills your hit rate. Agentic workloads benefit most, since system instructions, tool definitions and reference files repeat between calls while only the latest input changes.
Check your cache-hit metric weekly. A low hit rate usually means a timestamp, user name or random ID sits near the top of the prompt.

2. Shape the output
Output generation is the main driver of both latency and cost, and output tokens typically run 3x to 5x the price of input tokens. That is why experienced teams stop trimming prompts and start shaping responses:
- Force a strict JSON schema so the model returns fields, not prose.
- Set a sensible maximum output length.
- Use stop sequences where the answer has a clear end.
- Ask for labels or IDs instead of explanations when a machine, not a person, reads the result.
This is the cleanest token usage optimization there is, because it rarely touches quality for structured tasks.
3. Route requests to the right model
Not every request needs a flagship model. Classification, extraction and short rewrites run well on small, fast models. Hard reasoning and ambiguous requests deserve the big one. AWS reports that intelligent routing between a smaller and larger model can reduce costs by up to 30% without compromising accuracy. Treat that as a ceiling for a generic setup, since your own traffic mix decides the real number.
A practical routing path:
- Tag each request type by difficulty using your logs.
- Run the small model against your eval for the easy types.
- Ship only the types that clear your quality bar.
- Add a fallback: if the small model's output fails validation, retry on the larger one.
The fallback step protects you from the main risk. Moving to a cheaper model too early causes quality regressions that cost more in rework and lost user trust than the tokens saved, which is the point of building the eval first.
4. Batch what can wait
Data extraction, sentiment tagging, bulk document processing, nightly summaries and embeddings backfills do not need an instant answer. Batch APIs can run up to 50% below on-demand pricing. The trade is turnaround time, so use them for work with a deadline measured in hours, not seconds.
Audit your jobs. Teams often run offline work through the same real-time endpoint as their chat feature simply because it was the first integration they built.
5. Trim and retrieve context
Long context is convenient and expensive. Stuffing a whole document or chat history into every call multiplies input cost. Better options:
- Retrieve only the relevant chunks instead of whole files.
- Summarize older conversation turns once and carry the summary.
- Drop tool definitions a given route never uses.
- Remove boilerplate and repeated few-shot examples that the model no longer needs.
This lever pays most in long-running sessions and massive-context workloads, according to Snowflake's cost optimization guide. Combine it with caching: cache what is stable, retrieve what is relevant, and send nothing else.
6. Quantize if you self-host
If you run open-weight models on your own GPUs, memory and throughput set your cost per request. Quantization to FP8, INT8 or INT4, using tools such as LLM Compressor with vLLM, reduces memory use and raises throughput. That lets the same hardware serve more concurrent requests. Always rerun your eval on the quantized model, because the quality hit varies by model and task.
The infrastructure side matters too. Right-sizing GPU instances and using spot capacity for non-production work are common ways to lower GPU spend, though self-hosting only beats an API once your volume is high and steady.
7. Watch the price sheet
Providers cut prices often. Google announced it was reducing Gemini 1.5 Pro costs by 50% on both input and output tokens, effective October 7, 2024. A model you rejected last year on price may now fit. Re-run your cost model every quarter, and keep your code provider-agnostic enough to switch.
When not to optimize
Optimization has its own cost: engineering time, added complexity, new failure modes. Many teams waste money over-optimizing one-off queries where the effort outweighs the savings. The ROI is highest for long sessions, massive context and high-volume repetitive calls.
A simple rule: if a route costs less per month than an engineer's afternoon, leave it alone. Spend your time on the routes at the top of your spend report.
A prioritization checklist
| Order | Action | Effort | Best for |
|---|---|---|---|
| 1 | Add per-route token and cost logging | Low | Everyone |
| 2 | Build a small eval set | Medium | Anyone changing models |
| 3 | Move stable content to the prompt start and enable caching | Low | Agents, support bots, RAG |
| 4 | Cap and structure outputs | Low | Extraction, classification |
| 5 | Move offline jobs to batch | Low to medium | Back-office pipelines |
| 6 | Route easy requests to smaller models with fallback | Medium | High-volume mixed traffic |
| 7 | Trim context, quantize, review prices quarterly | Medium to high | Long sessions, self-hosters |
Our perspective
We test AI tools hands-on for a minimum of 14 days, tracking real-world performance, latency and cost. That habit shapes how we look at LLM spend. Launch-day price pages rarely match what a tool costs after two weeks of real use: retries, long contexts and agent loops quietly inflate the bill.
So we would tell any team the same thing we tell ourselves. Judge a model by cost per successful task, not cost per million tokens. A cheap model that needs two retries and a human fix can be the expensive option. A pricier model that gets it right the first time can be the efficient one.
We also see the cost question showing up in tool choice, not just API settings. Coding assistants, for example, differ a lot in how they consume context, and that shows in monthly spend. Our Claude Code vs Cursor comparison looks at that trade-off between a terminal agent and an AI IDE. And for model-level decisions, our ChatGPT vs DeepSeek R1 benchmark shows how a lower-priced reasoning model holds up against a market leader.
One more principle: we take no sponsored placements, so a recommendation to spend less is one we can actually make.
— AIMaestrohub
Compare tools before you commit
Picking the right tool is the first cost decision, before any prompt tuning. 🐨 AI Maestro Hub publishes hands-on reviews, verified pricing and head-to-head tables for 870+ AI tools. Browse our AI tool comparisons to see benchmarks and real costs side by side, or start from the AI Maestro Hub homepage to use the directory and the tool finder quiz.
FAQ
What are the main pillars of LLM cost optimization?
Four cover most cases: measure usage, reduce what you send (caching, trimmed context), reduce what you generate (output limits, structured responses), and match each task to the right model or pricing tier (routing, batch). Self-hosters add infrastructure efficiency, such as quantization.
Which LLM is most cost-effective?
There is no single answer, because cost per token is not cost per task. A small model is the cheapest for classification and extraction, while harder reasoning may need a flagship model to avoid retries. Run your own eval across two or three candidates and compare cost per successful result.
How much is 1 million tokens?
It depends on the model and on whether the tokens are input, cached input or output. Prices have fallen sharply, with GPT-3.5-level performance dropping from $20.00 to $0.07 per million tokens in under two years. Output typically costs several times more than input, so read the provider's current price sheet for both.
Can you really cut LLM costs by 90%?
Only in specific cases. The 90% figure applies to cached input tokens at some providers, not to the whole bill. Stacking caching, batching, output limits and routing can cut a bill sharply on repetitive, high-volume workloads, but your result depends on your traffic. Measure a baseline and report savings per route.
Does token usage optimization hurt quality?
It can, if you cut blindly. Shortening prompts or switching to smaller models without an eval risks regressions. Output shaping and caching usually leave quality untouched, so start there and test every other change against your baseline.
Sources
- Stanford AI Index Report 2025
- Your ultimate guide to the latest in generative AI on Vertex AI, Google Cloud Blog
- Reduce costs and latency with Amazon Bedrock Intelligent Prompt Routing and prompt caching, AWS News Blog
- Optimizing cost for using foundational models with Amazon Bedrock, AWS
- Get started with OpenAI GPT-5.6 on Amazon Bedrock, AWS
- Prompt Caching in the API, OpenAI
- Latency optimization, OpenAI API docs
- AI Cost Optimization, Snowflake
- Cost optimization cookbook, Anthropic
- Optimizing for cost and intelligence, Anthropic docs
- LLM Compressor, vLLM docs
- Optimize LLM Serving with NVIDIA Triton and TensorRT-LLM
