Early-bird price on the GenAI & Agentic AI Engineer Bootcamp batch. Grab a seat →

An LLM bill is input tokens times the input price plus output tokens times the output price, summed over every request. You reduce it with five mechanisms: cache the repeated start of the prompt, move work that can wait to a batch API, route simple requests to a cheaper model, send less context, and cap output length. Each one gives something up, so measure cost per request before and after, and re-run your evaluations.

This article is part of the LLMOps guide.

Key takeaways

  • Measure before optimising. Record input, output and cached token counts for every call.
  • Prompt caching pays off only when the same prefix is reused within the cache lifetime. A cache write can cost more than ordinary input.
  • Anthropic, OpenAI and Google each document a batch interface at half the standard price, with results inside about 24 hours.
  • Routing and context trimming save money by accepting some risk to quality. Evaluations tell you how much.
  • The discounts and limits below were read in the providers' documentation in November 2026. Confirm them before relying on them.

Where does the money go?

Read the usage fields on a week of real traffic before changing anything. On Anthropic's Messages API the response usage object reports input_tokens, output_tokens, cache_read_input_tokens and cache_creation_input_tokens. Put them on your traces, as described in LLM observability and tracing, and break cost down by feature.

Two patterns are common: a long system prompt sent unchanged on every call, and a conversation history sent again on every turn. Both are repeated prefixes, which is what caching addresses.

One warning about comparisons: token counts depend on the model. Anthropic states that Claude 4.7 and later models use a newer tokenizer producing roughly 30 per cent more tokens for the same text. Compare models by cost per request, not price per token. Anthropic's token counting endpoint is free and returns an estimate.

How does prompt caching work, and what does it trade away?

The provider stores the processed form of the beginning of your prompt. A later request that starts with exactly the same content reuses it and is billed less for those tokens. Only a prefix can match, so the order of the prompt matters: stable content first, changing content last.

On Anthropic's API you opt in with cache_control:

import anthropic

client = anthropic.Anthropic()

response = client.messages.create(
    model="claude-sonnet-5-5",
    max_tokens=1024,
    system=[
        {
            "type": "text",
            "text": LONG_STATIC_INSTRUCTIONS,  # policies, examples, reference text
            "cache_control": {"type": "ephemeral"},
        }
    ],
    messages=[{"role": "user", "content": user_question}],
)
print(response.usage.cache_creation_input_tokens, response.usage.cache_read_input_tokens)

The cached prefix covers tools, then system, then messages, up to the marked block. The default lifetime is 5 minutes, refreshed each time the entry is used, and "ttl": "1h" selects a one-hour lifetime. You can set up to four breakpoints. Prompts below a minimum length (512 to 4,096 tokens depending on the model) are processed without caching and without an error.

A bar chart of Anthropic prompt caching multipliers against the base input price: cache read 0.1, normal input 1, five-minute cache write 1.25, one-hour cache write 2.

The billing explains the trade-off. As of November 2026, Anthropic prices a 5-minute cache write at 1.25 times the base input price, a 1-hour write at 2 times, and a cache read at 0.1 times (lower on some models). Take a 10,000-token prefix:

  • Sent twice without caching: 20,000 token-units.
  • With caching: 12,500 for the write plus 1,000 for the read, 13,500 in total.
  • Sent once and never reused inside 5 minutes: 12,500 instead of 10,000. You paid more.

So caching helps traffic that repeats a prefix quickly, and costs money on rare, one-off prompts.

Other providers work differently:

ProviderHow caching is enabledPoints to note
Anthropiccache_control on the request or on content blocksWrites cost more than normal input; cache reads do not count towards the input-tokens-per-minute rate limit
OpenAIAutomatic on supported models; newer models also accept explicit breakpointsOn GPT-5.6 and later the minimum is 1,024 tokens and cache writes are billed above normal input
Google GeminiImplicit caching on by default for Gemini 2.5 and newerMinimum prompt size of 2,048 or 4,096 tokens depending on the model; savings apply only on a hit
Amazon BedrockImplicit or explicit, depending on the model; cachePoint in the Converse APIA hit is never guaranteed; caching is not supported with the batch inference API

What breaks caching is usually small: a timestamp near the top of the system prompt, a reordered tool list or an edited earlier message changes the prefix and causes a miss. Bedrock's documentation adds that a request sent before an identical one has started its response writes a new entry instead of reading one, so a burst of parallel first requests pays for several writes.

When is a batch API the right tool?

A batch API accepts many requests at once and returns the results later, at a discount. It fits work nobody is waiting for: evaluations, backfills, nightly summaries.

ProviderDocumented discountTurnaroundLimits per batch
Anthropic Message Batches API50 per centMost batches finish in under 1 hour; expiry at 24 hours100,000 requests or 256 MB
OpenAI Batch API50 per cent24-hour completion window50,000 requests, 200 MB input file
Google Gemini Batch API50 per centTarget of 24 hours2 GB input file

The trade is latency and a different programming model. You submit, poll, and match results to requests by an identifier (custom_id on Anthropic and OpenAI), because both state that results can come back in any order. Feature support can be narrower too: Amazon Bedrock's batch inference, for instance, does not support tool calling in jobs that use the Converse format.

Does routing requests to a smaller model save money?

Routing means choosing a model per request. The simplest router is a rule you write: classification and extraction go to the small model, harder reasoning to the large one. A learned router predicts which model is good enough for each prompt.

Amazon Bedrock offers the second kind as intelligent prompt routing. It routes between two models in the same family by predicting the response quality of each, with a fallback model and a "response quality difference" threshold that you configure. Its documentation lists the limits plainly: routing is optimised only for English prompts and cannot adjust to application-specific performance data.

What routing trades away:

  • Some hard requests will reach the small model and get a worse answer.
  • You now maintain evaluation results for two models, and the prompt has to work on both.
  • Debugging needs the model name on every trace.

Write the rule-based router first. Its mistakes are easy to see.

How do you trim context without hurting answers?

Every token you send is billed on every call, so the cheapest token is the one you do not send. Common cuts:

  • Retrieve fewer, better passages. See hybrid search and reranking.
  • Summarise or drop old conversation turns once a conversation is long.
  • Remove tool definitions the request cannot need.
  • Delete instructions and examples from the system prompt that no evaluation case depends on.

Two cautions. Cutting the wrong context lowers quality, and only an evaluation run will show it. Trimming also fights with caching: rewriting earlier turns changes the prefix, which is why OpenAI's caching guide advises appending new messages instead of rewriting earlier ones.

Do output limits help?

Yes, within reason. Output tokens are billed separately from input tokens, so check the output rate on your model's pricing page. There are two controls. The first is the prompt: ask for the format and length you need. The second is the hard cap, max_tokens on Anthropic's API, which stops generation.

The cap protects the budget but can cut an answer off mid-sentence or leave JSON unclosed, so set it above what a correct answer needs and alert on responses that hit it.

What should you do first?

  1. Add token counts and cost per request to your traces.
  2. Put stable content first in the prompt, then enable caching.
  3. Move offline work to a batch API.
  4. Trim context, checking each cut against your evaluation set.
  5. Add routing last. It adds the most moving parts.

After each step, run the checks described in LLM evaluation in CI. A saving that lowers answer quality is a regression.

Common questions

Can I combine caching with batch processing?

On Anthropic's API, yes. The documentation says the discounts stack, with cache hits in batches on a best-effort basis, and suggests the one-hour cache lifetime for batches. On Amazon Bedrock, prompt caching is not supported with the batch inference API.

Why did my cost rise after a small prompt edit?

Check the cache read ratio first. An edit near the top of the prompt invalidates the cached prefix for every request, so each one pays the write rate again until the new prefix is warm.

Free download: LLM cost and latency worksheet

Estimate monthly LLM spend and cost per successful task. Includes a worked example and CSV for comparing model, volume, quality, and latency scenarios. See what’s inside.

LLMOps: how to run LLM applications in production

What changes when you operate an LLM application: prompt and model versions, evaluations, tracing, cost per request and provider limits, with a minimum setup checklist.

Prompt versioning: treating prompts like code

How to keep prompts in the repository, review them like code, tie each version to a model and its evaluation results, label traces, and roll back safely.