Claude API in production: cut your bill in half without losing quality

7 min read

Claude API costs spiral when you call Opus for everything. Prompt caching, batch processing, model routing: the guide to cutting costs.

Hand annotating a budget calculation notebook next to a calculator and keyboard on a desk

An agent that calls Claude Opus to summarize a support ticket often costs 8 to 10 times more than it should. The answer lies in three levers: route to the right model based on the task, enable prompt caching on repetitive prompts, and shift what isn't urgent to the Batch API. We detail each with code, and the pitfalls that blow up your bill despite good intentions.

1. Stop calling Opus for everything

It's the most common mistake we see with teams starting out with the Claude API: one model, used for everything, from simple text classification to complex code generation. Anthropic now offers a multi-tier lineup, Claude Opus, Claude Sonnet, and Claude Haiku, each in successive versions, and these models have neither the same price nor the same speed, according to a comparison published by Tech Insider in October 2026.

The reflex to adopt: route based on the actual complexity of the task.

function pickModel(task: TaskType) {
  if (task === "classification" || task === "extraction") {
    return "claude-haiku-latest"; // fast, cheap
  }
  if (task === "code_generation" || task === "complex_reasoning") {
    return "claude-opus-latest"; // maximum quality
  }
  return "claude-sonnet-latest"; // the reasonable default
}

Ticket classification, entity extraction, intent routing: Haiku is almost always enough. Keep Opus for multi-step reasoning or code generation where an error costs more than the price difference.

Pitfall: not testing the cheaper model before deploying it. A poorly prompted Haiku model gives degraded results, and the team concludes "Haiku isn't good enough" when the prompt was never adapted for a smaller model.

2. Enable prompt caching on long system prompts

If your agent sends the same voluminous context with each call, a 2,000-token system prompt, a knowledge base, conversation history, you're repaying that context with every request. Prompt caching changes the game: the repeated part of the prompt is cached on Anthropic's side, and subsequent calls charge it at a reduced rate.

const response = await anthropic.messages.create({
  model: "claude-sonnet-latest",
  system: [
    {
      type: "text",
      text: longSystemPrompt,
      cache_control: { type: "ephemeral" }
    }
  ],
  messages: [{ role: "user", content: userQuery }]
});

A tutorial published by Tech Insider in October 2026, devoted to setting up a pull request review bot, describes precisely this type of optimization:

Tech Insider, "Claude Sonnet 5.5 API Setup," October 2026 "a working Claude Sonnet 5.5 API integration, a cost-control setup using prompt caching and batch processing, and a small working project (a pull-request review bot)"

Concretely, according to this tutorial, the same project combines prompt caching and batch processing to keep the bill in check on repeated usage like automated code review. The logic applies to any agent reusing stable context: customer support, document summarization, internal assistant.

Pitfall: the cache has a short lifespan. If your calls are spaced several minutes apart without steady traffic, the cache expires before reuse and you gain nothing. It only works at volumes with sufficient call frequency.

An [AI agent](/expertises/agents-ia) that costs too much in prod? Let's talk about your architecture.

3. Shift what isn't urgent to the Batch API

Not everything needs a response in under two seconds. Nightly ticket classification, mass summary generation, product data enrichment: these are processes that can wait a few hours. Anthropic's Batch API handles these volumes at a reduced rate compared to synchronous calls.

const batch = await anthropic.messages.batches.create({
  requests: tickets.map((t) -> ({
    custom_id: t.id,
    params: {
      model: "claude-haiku-latest",
      max_tokens: 500,
      messages: [{ role: "user", content: t.content }]
    }
  }))
});

You launch the batch, retrieve the results a few hours later. Simple to implement. The real work is identifying what can be asynchronous in your product without degrading user experience, often more processes than you'd expect at first.

This combination of routing + cache + batch isn't just a matter of budgetary comfort. According to Anthropic's IPO filing analyzed by TechCrunch, cost pressure increases with scale:

TechCrunch, "Anthropic's IPO filing reveals its strategy," October 26, 2026 "More than half of customers spending at least $100,000 annually now use both the Claude platform and a first-party app like Claude Code or Cowork, up from about 30% at the end of last year."

In other words, the biggest customers already consume multiple Anthropic products at once, according to this TechCrunch analysis. As usage grows, the price gaps between models and between synchronous/batch modes weigh more on the overall bill.

4. Monitor consumption per endpoint, not just the monthly total

The limit of this approach: if you only measure consumption at the global bill level, you discover the problem a month too late. You need to instrument every endpoint calling Claude, with input/output token counts and the model used.

logUsage({
  endpoint: "support-ticket-classifier",
  model: response.model,
  inputTokens: response.usage.input_tokens,
  outputTokens: response.usage.output_tokens,
  cacheReadTokens: response.usage.cache_read_input_tokens
});

Without this granular tracking, you can't know which agent or feature is blowing up your budget. We've seen teams discover that a single endpoint, often a minor feature, lightly used but poorly optimized, represented over 40% of total spending. A simple dashboard with these metrics avoids end-of-month surprises.

For the reliability of structured outputs in production, note also that cloud integrations are evolving: Amazon added support for structured outputs on Claude models via Bedrock, which reduces the number of retries needed to get an exploitable format, and indirectly lowers costs tied to retries, according to AWS documentation.

We had touched on supervising these agents in our guide to AI agent training in 2026: cost mastery is part of the skills a team must acquire before going to production, just like security, a topic we dug into after the CyberXero incident.

Conclusion

Three levers are enough to regain control of a Claude API bill that's spiraling: route to the cheapest model that does the job, cache repetitive prompts, and process in batch everything that isn't urgent. None of the three requires rewriting your architecture, just stop using the API as if one model, one calling mode, could handle everything.

The real discipline is tracking per endpoint. Without it, you're fixing a problem you can't see anymore.

Need to audit the API consumption of your AI agents in production? The fstck team supports setting up a controlled AI automation architecture, from model selection to cost monitoring.

Frequently asked questions

How do I know if my prompt caching is actually working on the Claude API?

Check the cache_read_input_tokens field in the API response: if it's zero on calls that should reuse the cache, either the delay between calls exceeds the cache lifespan, or the system prompt isn't identical across calls.

Is the Anthropic Batch API suitable for a real-time chatbot?

No. The Batch API processes requests asynchronously over several hours; it's designed for volumes that don't require immediate response, mass classification, data enrichment, nightly summaries. For a chatbot, stick with the standard synchronous API.

What's the cost difference between Claude Haiku and Claude Opus for a simple task?

The price gap between the two extremes of the Claude lineup is significant, Haiku is positioned as the economical, fast option; Opus as the maximum-quality option. For a classification or extraction task, testing Haiku first with a well-calibrated prompt avoids paying the difference with no real benefit.

Should I combine prompt caching and Batch API on the same project?

Yes, they're complementary: caching reduces the cost of repeated context on synchronous calls, batch reduces the per-unit cost on deferrable processing. The same agent can use both depending on the type of request it handles.

Does model routing add maintenance complexity?

A bit, but a simple routing function based on task type is enough for most cases. The real complexity is measuring response quality from the cheaper model to ensure it holds up, not the routing code itself.

Équipe Fullstack
Follow us on LinkedIn →

Let's talk about your project

Got a project in the works, a bold idea?
Let's meet and talk about it.

Contact us
→