Skip to content
Back to the blog
Cost optimization Martin Pohl

10 ways to cut AI API costs in 2026

A practical playbook for cutting LLM costs by 40–80% without giving up quality. Caching, model routing, batch APIs, prompt compression and other tactics, with the figures attached.

Sdílet:

Is the AI API bill growing faster than revenue? You are not alone. Most teams we have looked at spend 40–70% more than they need to. Here are 10 tactics that hold up in production.

1. Route models by difficulty

Do not send everything to GPT-5. Classification, short answers and routing can go to GPT-4o mini or Claude Haiku at a 10–20× lower price. Leave complex reasoning on the flagship. A short “router” prompt on a small model decides where the request goes.

2. Prompt caching

Anthropic, OpenAI and Gemini can cache repeated parts of a prompt (the system prompt, RAG context, few-shot examples). Cached tokens cost 10–25% of the normal price. For agents with a large system prompt this is often the biggest one-off saving.

3. Batch API instead of realtime

If you do not need an answer in seconds (log classification, embeddings, bulk generation), use the batch endpoint. That is a 50% discount against the ordinary API at both OpenAI and Anthropic.

4. Shorten system prompts

Every request pays for the whole system prompt again (unless you cache it). 2,000 wasted tokens × 100k requests = 200M extra tokens a month. Audit the prompts and delete dead instructions.

5. A max_tokens limit

The model likes to write a longer answer than you need. Cap max_tokens hard. With a JSON response format that cuts output tokens sharply.

6. Structured output instead of “explain why”

When you only need the result, have the model return JSON. Free-form “step by step thinking” sounds nice, and you pay for every token. On reasoning models (o1, GPT-5 thinking) it is often the largest line on the invoice.

7. Streaming and early termination

Stream the answer and stop generation once you have what you need (for example the first JSON block). That saves output tokens in the edge cases.

8. Cache results, not only the prompt

Identical input, identical output? Cache it. Redis, or even a simple Postgres table. On an FAQ bot or a classifier the cache hit ratio commonly gets above 30%.

9. Embeddings and retrieval instead of stuffing the context

Do not paste the whole docs into the context. Use RAG. Five relevant chunks (500 tokens) are cheaper than a 50k-token dump, and often more accurate.

10. Measure, do not guess

Without monitoring you will miss a runaway loop, an infinite agent or a bug that burns $200 a day. Connect OpenAI or Anthropic through Tokeny and watch daily spend.

How much does it save in total?

A realistic mix of these tactics gives a 40–80% lower invoice on most use cases. Start with routing and caching. Those are usually the fastest wins.

Related: Prompt optimization · Token window strategy · Estimate the real cost

Related guides and price pages

LLM Cost Calculator

Estimate across 11 models

GPT API cost

Per-token prices for OpenAI models

Claude API cost

Haiku, Sonnet, Opus pricing

How to calculate LLM cost

The formula, step by step

10 ways to save

Caching, routing, batch APIs

Prompt optimization

Cut tokens by 30–60%

Token window strategy

RAG, sliding window, pruning

Track real AI spend, not just estimates

Upload a CSV from Cursor, Grok Bot or OpenRouter and see daily spend in USD and CZK. The account is free and does not ask for a card.

Sdílet:

Written after hours. If this helped, support my work with a coffee ☕