← Blog

Reduce Claude API Token Costs in Production

2026-11-10 · 5 min read · SubToAPI Team

Token costs on the Claude API scale directly with how much text you send and receive, which means the fastest way to cut your bill is to reduce the volume of tokens moving through every request without degrading output quality. In production this comes down to five concrete levers: trimming system prompts and context windows, using prompt caching for repeated content, routing requests to the right model size, capping output length, and monitoring usage per endpoint so you know where the money actually goes.

Most teams overspend not because Claude is expensive per token, but because their application sends far more context than the task needs, repeats the same boilerplate on every call, or defaults every request to the largest model regardless of complexity. Fixing those three issues typically cuts costs by 30-60% with no change to the user-facing product.

Audit What You're Actually Sending

Before optimizing anything, instrument your requests. Log token counts per call, broken down by system prompt, conversation history, and user input. Anthropic's API returns usage.input_tokens and usage.output_tokens on every response — store these alongside a route or feature identifier.

curl https://api.anthropic.com/v1/messages \
  -H "x-api-key: $ANTHROPIC_API_KEY" \
  -H "anthropic-version: 2023-06-01" \
  -H "content-type: application/json" \
  -d '{
    "model": "claude-3-5-sonnet-20241022",
    "max_tokens": 512,
    "messages": [{"role": "user", "content": "Summarize this ticket"}]
  }'

If you're running Claude behind SubToAPI, usage metadata is already attached to every response and visible per application key in the dashboard, so you don't need to build this logging layer yourself — see /docs/messages for the response shape.

Trim System Prompts and Context

System prompts tend to accumulate instructions over time — formatting rules, edge cases, examples — and nobody goes back to prune them. A 2,000-token system prompt sent on every one of 100,000 daily requests is 200 million tokens a month before a single user message is processed.

Concrete fixes:

A simple truncation pattern for conversation history:

function trimHistory(messages, maxTurns = 6) {
  if (messages.length <= maxTurns) return messages;
  return messages.slice(-maxTurns);
}

Use Prompt Caching for Repeated Content

If your system prompt, tool definitions, or reference documents are identical across many requests, prompt caching lets Claude skip reprocessing that content and charges a fraction of the normal input rate on cache hits. This is the single highest-leverage optimization for apps with large, static system prompts — customer support bots with long policy documents, coding assistants with repo context, or any app that reuses the same few-shot examples on every call.

The pattern: put static content first and mark it as cacheable, then append the variable user turn after it. Cache hits only help if the cached block is reused within the cache's TTL, so this works best for high-traffic endpoints, not one-off requests.

Route by Task Complexity

Not every request needs your largest model. Classification, extraction, short rewrites, and simple Q&A often perform just as well on a smaller, cheaper model, while multi-step reasoning or code generation benefits from the larger one. A basic router:

function pickModel(task) {
  const simpleTasks = ["classify", "extract", "format"];
  return simpleTasks.includes(task)
    ? "claude-3-5-haiku-20241022"
    : "claude-3-5-sonnet-20241022";
}

Run an evaluation set through both models for your actual tasks before committing — the cost savings only matter if output quality holds up. Keep a small holdout set of real production inputs and compare outputs manually or with an automated scorer whenever you adjust routing rules.

Cap Output Tokens and Stop Sequences

Output tokens generally cost more than input tokens, and uncapped generations are a common source of waste — a model that should return a one-line answer sometimes writes three paragraphs if max_tokens is left high and no stop sequence is set.

Centralize and Monitor Usage

Cost overruns are easiest to catch when usage is visible per feature, per team, and per API key — not just as one aggregate monthly number. If you're building this internally, you need to tag every request with a source identifier and persist token counts per tag.

SubToAPI handles this by giving each application its own sub_live_... key with usage metadata, streaming, and tool use available out of the box, so you can see exactly which part of your product is driving token spend without instrumenting it yourself. Plans start at Solo for single-developer projects and scale to Team and Scale tiers with per-seat usage visibility — see /pricing for details, or /docs/quickstart to get a key running in a few minutes.

Putting It Together

A realistic optimization order for an existing production app:

  1. Instrument usage logging by route/feature.
  2. Trim system prompts and truncate conversation history.
  3. Apply prompt caching to static, repeated content.
  4. Route simple tasks to a smaller model after validating quality.
  5. Cap max_tokens and add stop sequences.
  6. Review per-key usage weekly and re-audit after any prompt changes.

None of these require rewriting your application logic — they're changes to what you send and how you measure it.

Questions

Does switching models always save money without hurting quality? Not always. Smaller models are cheaper per token but can need more retries or longer prompts to get the same accuracy, which erases the savings. Test on real production inputs before switching.

Is prompt caching worth it for low-traffic endpoints? Usually not. Caching pays off when the same static content is reused across many requests within the cache window. For infrequent or highly variable prompts, the overhead isn't worth it.

How do I know which part of my app is driving token costs? Tag requests by feature or route and log input/output token counts per tag. If you use SubToAPI, each application key already reports usage metadata in the dashboard, so you get this breakdown without extra instrumentation — see /docs/messages.

Turn your Claude access into an HTTPS API

SubToAPI gives you application API keys, streaming, tool use and usage insights on top of your existing Claude access — set up in minutes.

Start free  Read the quickstart →