---
title: "How do I cut the cost of LLM API calls?"
description: "Measure usage on every response, cap output, cache the stable prefix, pick the cheapest model that passes your eval, lower effort and batch non-urgent work."
url: https://www.danny.engineering/answer/ai/how-do-i-cut-the-cost-of-llm-api-calls
author: Danny
published: 2026-12-03T00:00:00.000Z
updated: 2026-12-03T15:35:00.000Z
tags: ["AI"]
---

# How do I cut the cost of LLM API calls?

## The short answer


Start by logging `response.usage` on every call so you know where the money goes. Then work through the levers in order of effort: ask for shorter output and cap it (output tokens cost about five times input), cache the stable part of your prompt, route each task to the smallest model that passes your eval, lower `effort` for simple work, and send anything that can wait through the Message Batches API at half price. Most teams find the first three cut the bill by more than half.


```typescript
const response = await client.messages.create({ model, max_tokens, system, messages });

const { input_tokens, output_tokens, cache_read_input_tokens, cache_creation_input_tokens } = response.usage;
logger.info({ route: 'summarise', model, input_tokens, output_tokens, cache_read_input_tokens, cache_creation_input_tokens });
```


## How it works


You pay per token, and not all tokens cost the same. There are four buckets on a Claude bill, and the same shape applies to most providers:

- **Input tokens**: everything you send, including the system prompt, the conversation history, tool definitions and tool results. On `claude-sonnet-5-5` this is $2 per million.
- **Output tokens**: everything the model writes, including its thinking. About five times the input price, so $10 per million on Sonnet.
- **Cache reads**: input tokens served from the prompt cache cost roughly a tenth of normal input.
- **Batch requests**: anything sent through the Message Batches API is billed at 50% of the normal rate, in exchange for results within 24 hours.

So output is expensive: a 2,000-token essay costs as much as 10,000 tokens of reading. And the biggest input cost in a chat app is usually repetition: you resend the same system prompt and growing history on every turn, and without caching you pay full price each time.


The model you pick multiplies everything. The current line-up is `claude-haiku-5-5` at $0.10 input and $0.50 output per million, `claude-sonnet-5-5` at $2 and $10, and `claude-opus-5-5` at $4 and $20. Haiku is forty times cheaper than Opus on output, and not every route needs the same model.


## How to do it


### Measure first


Log usage per route and per model, then look at a week of data. You want two numbers: which routes spend the most, and the input to output ratio on each. A route that spends 90% on input wants caching and trimming; one that spends 60% on output wants brevity and a smaller model. Without this you will optimise the wrong thing. To size a prompt before sending it, `client.messages.countTokens({ model, system, messages })` tells you.


### Cap and shorten output


Set `max_tokens` to what the task needs and ask for brevity in the prompt: "Answer in two sentences", "Return only the JSON", "No preamble". Structured outputs help too, because a JSON schema removes the prose around the data. Watch for `stop_reason === 'max_tokens'` in your logs; if it fires often your cap is too low and you are paying for truncated answers you then retry.


### Cache the stable prefix


Prompt caching lets the API reuse the part of a prompt it has already processed. Mark the end of your stable content with `cache_control` and reads of that prefix drop to about a tenth of the price.


```typescript
const response = await client.messages.create({
  model: 'claude-sonnet-5-5',
  max_tokens: 1024,
  system: [
    { type: 'text', text: INSTRUCTIONS_AND_STYLE_GUIDE, cache_control: { type: 'ephemeral' } },
  ],
  messages: [{ role: 'user', content: `Today is ${today}. ${userQuestion}` }],
});
```


The rule to remember is that caching is a prefix match. The API compares your request byte for byte from the start, and the first difference breaks the cache for everything after it. So anything that changes per request (a timestamp, a user ID, the question) must come after the cached block, never inside it. Tool definitions come before the system prompt in the prefix, so keep their order stable too. Check `usage.cache_read_input_tokens`; if it stays at zero on repeated calls, something early in the prompt is changing.


### Route to the smallest model that passes your eval


Write a small eval set for each route (twenty to fifty real inputs with expected outputs), run it against each model, and use the cheapest one that passes your bar. In practice that often means `claude-haiku-5-5` for classification, extraction and routing, `claude-sonnet-5-5` for most generation and chat, and `claude-opus-5-5` where quality visibly matters, such as complex reasoning or code that ships. Make the model a parameter per route so you can change it without a deploy.


### Lower effort for simple tasks


Thinking is on by default on current models, and it is billed as output. For straightforward tasks, turn it down:


```typescript
output_config: { effort: 'low' }
```


Classification, short rewrites and formatting rarely need deep thinking. Keep `high` or above for hard problems and agentic work, and measure the difference on your eval.


### Batch anything that can wait


Nightly tagging, backfills and evaluation runs do not need an answer in two seconds. Send them as a batch and pay half.


```typescript
const batch = await client.messages.batches.create({
  requests: docs.map((doc) => ({
    custom_id: doc.id,
    params: {
      model: 'claude-haiku-5-5',
      max_tokens: 256,
      messages: [{ role: 'user', content: `Tag this article with up to three topics:\n\n${doc.text}` }],
    },
  })),
});
```


Results arrive in any order, so match them up by `custom_id`.


### Trim what you send


Conversation history grows every turn, and you pay for all of it every time. Keep the last few turns and summarise older ones. Trim tool results to the fields the model needs; a 50 KB JSON response is thousands of tokens on every following call. And once a document is in the cached prefix, refer to it rather than pasting it again.


## Common pitfalls

- **Optimising before measuring.** Teams often shrink a prompt that costs pennies while a chatty agent loop burns the budget. Log usage first.
- **Breaking the cache without noticing.** A `new Date()` in the system prompt, a randomly ordered tool list or a per-user greeting before the cached block means you pay full price every time. Verify with `cache_read_input_tokens`.
- **Switching to a cheaper model without an eval.** If quality drops, the retries, escalations and unhappy users cost more than the tokens saved. Downgrade only when the eval still passes.
- **Judging cost per request instead of per task.** A cheaper model that needs three attempts, or an agent that makes twice as many tool calls, is not cheaper.
- **Ignoring thinking tokens.** They are output tokens. A high effort setting on a simple route can double the bill with no visible benefit.

## Related reading

- [Pricing](https://platform.claude.com/docs/en/about-claude/pricing)
- [Prompt caching](https://platform.claude.com/docs/en/build-with-claude/prompt-caching)
- [Effort](https://platform.claude.com/docs/en/build-with-claude/effort)
- [Batch processing](https://platform.claude.com/docs/en/build-with-claude/batch-processing)
