Skip to content
MyStackCost
Leer en español

How to reduce LLM API costs: 8 techniques with real numbers

Pick the right model, cap output tokens, use caching and batch jobs: practical ways to cut your LLM API bill, each with a worked example.

Published: Updated: 6 min read

LLM API bills tend to grow quietly. During development, with a handful of test calls, the cost looks negligible. Then the feature ships, thousands of people start using it, and every extra token gets multiplied by hundreds of thousands of requests. The good news is that most of the savings don’t require switching providers. They come from using the one you already have more carefully.

This guide covers eight techniques, roughly in order of how much they usually save, each with a worked example. To try them with your own numbers, use our LLM API cost calculator, which compares models from OpenAI, Anthropic and Google using prices that are checked every day.

How the cost is calculated

LLM APIs charge per million tokens, with one price for input tokens (everything you send: instructions, context and the question) and a higher one for output tokens (the model’s answer). For a single request:

Cost = input tokens ÷ 1,000,000 × input price + output tokens ÷ 1,000,000 × output price

We’ll use one example throughout: an app that handles 100,000 requests a month, each with 1,500 input tokens and 500 output tokens. That adds up to 150 million input tokens and 50 million output tokens a month, so in the examples below we simply multiply millions of tokens by the price per million.

1. Match the model to the task

This is the decision with the biggest impact. At October 2026 prices:

  • Claude Sonnet 5.5 ($2 input and $10 output per million tokens): 150 × $2 + 50 × $10 = $800 a month.
  • Claude Haiku 5.5 ($0.10 and $0.50 per million tokens): 150 × $0.10 + 50 × $0.50 = $40 a month.

The same traffic costs 20 times less on the smaller model. Not every task can make that trade, but classifying messages, pulling fields out of a form or answering common support questions rarely needs the most capable model. Start with the cheapest model that meets your quality bar, and move up only where it falls short.

2. Route requests between models

You don’t have to pick a single model. A router sends each request to the model that fits: simple ones to the cheap model, hard ones to the capable model. If 80% of requests go to Haiku and 20% to Sonnet:

0.8 × $40 + 0.2 × $800 = $32 + $160 = $192 a month

That’s 76% less than sending everything to Sonnet. The router can be a simple rule, such as the length or type of the request, or a small model that classifies each request before it’s answered.

3. Keep output tokens in check

Output tokens cost five times as much as input tokens on most of the models in our calculator, so they deserve the most attention. Ask for concise answers, set a maximum number of output tokens on every call, and stop the model from restating the question or opening with filler. Asking for structured output, such as a short JSON object instead of prose, often helps too.

In the Sonnet example, cutting output from 500 to 300 tokens per request lowers the output cost from $500 to $300. The bill drops from $800 to $600 a month, 25% less.

4. Trim the context you send

Each request usually carries a system prompt, the conversation so far and some reference material. Much of it is repeated or simply not needed. A few ways to cut it down:

  • Summarize long conversations instead of resending the full history every turn.
  • Retrieve only the relevant passages of a document, not the whole document.
  • Audit the system prompt: rules pile up over time, and many stop being useful.

If input in the Sonnet example drops from 1,500 to 1,000 tokens, input costs go from $300 to $200: $100 less every month.

5. Use prompt caching

When many requests start the same way, with the same system prompt or the same base document, several providers let you cache that prefix and charge less each time it’s reused. Discounts, minimum lengths and how long the cache lasts vary by provider and model, so check your provider’s documentation. For apps with long, repeated instructions, it’s one of the easiest savings to capture.

6. Batch anything that isn’t urgent

If you don’t need the answer right away, as with overnight document summaries, classifying an email archive or generating product descriptions, batch APIs usually offer a significant discount, often around 50%, in exchange for returning results within hours instead of seconds. Confirm your provider’s current batch discount before you build a plan around it.

7. Stay below long-context pricing

Some models charge a higher rate once a single request passes a certain size, and that rate usually applies to the whole request. In our calculator, for example, Claude Haiku 5.5 gets more expensive above 100,000 input tokens and Gemini 3.1 Pro above 200,000. If you work with large documents, splitting them or sending only the relevant sections can keep you in the cheaper tier.

8. Cache answers that repeat

In a customer support chatbot, many people ask the same questions. Storing answers to common questions in your own app means you don’t pay the model to write the same reply hundreds of times. If just one in five requests is served from that cache, you save 20% of the bill.

The techniques at a glance

Technique Savings in the example Effort
Smaller model for everything From $800 to $40 Low, if quality holds
80/20 router From $800 to $192 Medium
Shorter answers From $800 to $600 Low
Less context From $800 to $700 Medium
Prompt caching Depends on the provider Low
Batch processing Often around 50% Low, if it can wait
Avoiding long-context pricing Depends on request size Medium
Answer caching Depends on how often questions repeat Medium

Mistakes that quietly inflate the bill

  • Unlimited automatic retries. If a call fails and your code keeps retrying, you may pay for every attempt the provider gets far enough to process. Cap retries and log how often they happen.
  • Conversation history that never stops growing. In a long chat, every new message resends the conversation so far, so the cost per message rises with each turn. Set a maximum number of messages or summarize the older ones.
  • Tests running on the most expensive model. Automated tests and development environments don’t need your production model. Use a cheap model or mocked responses.
  • Features nobody uses. An automatic summary of every document consumes tokens every day, even if nobody reads it. Check which features actually deliver value before you spend time optimizing them.

AI agents make the growing-history problem much worse. An agent that solves a task in ten steps re-sends the instructions, the request and every earlier tool result on each step, so the input tokens grow with the square of the steps, and a failed task that starts over pays for the whole run again. Our AI agent cost calculator adds up the cost step by step and shows how it changes with 1, 5, 10 or 20 steps.

Measure before you optimize

None of this works if you don’t know where the money goes. Before changing anything:

  • Log input and output tokens for each type of request.
  • Find which features of your app account for most of the spend.
  • Set spending alerts and per-user limits so a bug or a heavy user can’t surprise you.
  • Test quality on the cheaper model before ruling it out.

If you use AI for customer support, our AI chatbot ROI calculator also shows how much you save compared with agent time, which is usually far larger than the API bill itself.

Conclusion

Most AI spending is controlled by design decisions: picking the right model for each task, asking for concise answers and not sending more context than the model needs. Combined, these techniques can bring the bill down to a fraction of what the first version of a feature costs, without users noticing any difference. Prices change often, so rerun the numbers from time to time with current data.

Published:

Why AI agents cost more than you expect

An AI agent can burn dozens of times more tokens than a chatbot. Why accumulated context drives the bill up, with worked examples and ways to bring it down.