Claude API Reduce Token Usage: 10 Proven Techniques
Reducing token usage on the Claude API comes down to three levers: send less input, generate less output, and reuse what you've already sent instead of resending it. Every token — in the system prompt, conversation history, tool definitions, and the response itself — counts toward your bill and toward your latency, so the techniques below attack all three levers directly.
This guide covers concrete, implementable techniques rather than vague advice like "be concise." Each one has a measurable effect on token count and is something you can ship today.
1. Use Prompt Caching for Repeated Context
If your system prompt, tool definitions, or a large reference document (like a style guide or codebase excerpt) stays the same across requests, cache it. Claude's prompt caching lets you mark a block of the prompt as reusable, so subsequent requests only pay a fraction of the token cost for that block instead of the full input price.
{
"system": [
{
"type": "text",
"text": "You are a customer support agent for Acme Corp...",
"cache_control": { "type": "ephemeral" }
}
]
}
This is the single highest-leverage change for applications with long, static system prompts — RAG pipelines with large retrieved contexts, coding agents with repo context, or chatbots with detailed persona instructions.
2. Trim Conversation History Aggressively
Sending the full chat history on every turn is the most common source of token waste. Instead:
- Summarize older turns into a short recap once the conversation passes a threshold (e.g., 10 turns).
- Drop tool-call results that are no longer relevant to the current question.
- Cap history to the last N turns plus a running summary, rather than keeping everything verbatim.
A simple sliding-window implementation:
function trimHistory(messages, maxTurns = 8) {
if (messages.length <= maxTurns * 2) return messages;
const recent = messages.slice(-maxTurns * 2);
const summary = { role: "user", content: "[Earlier conversation summarized: ...]" };
return [summary, ...recent];
}
3. Set max_tokens Deliberately, Not as a Safety Net
Many developers set max_tokens to a large number "just in case" and let the model decide when to stop. But a high ceiling doesn't reduce cost by itself — cost is driven by actual output length. The real win is prompting for brevity and setting max_tokens to match the expected answer size, which also catches runaway generations early.
{
"model": "claude-sonnet-4-5",
"max_tokens": 300,
"messages": [{ "role": "user", "content": "Summarize this ticket in 2 sentences." }]
}
Pair this with explicit formatting instructions ("respond in under 50 words", "output JSON only, no explanation") to cut filler text the model would otherwise generate.
4. Strip Unused Tool Definitions
Tool schemas are sent as input tokens on every request, even if the model never calls them. If your agent has 15 tools defined but only 3 are relevant to the current task, filter the tool list dynamically based on context or user intent instead of always sending the full set.
const relevantTools = allTools.filter(t => intentMatchesTool(userQuery, t));
This matters more than it looks — verbose JSON schemas with long descriptions and nested properties can easily add hundreds of tokens per tool.
5. Compress Retrieved Context Before Sending It
In RAG-style setups, don't paste raw retrieved chunks into the prompt. Pre-process them:
- Deduplicate overlapping chunks.
- Truncate to the most relevant sentences using a lightweight extraction step before the Claude call.
- Convert tables or HTML to plain text — markup tokens add up fast.
6. Use Structured Output Instead of Prose
Asking for JSON or a fixed schema instead of free-form prose reduces output tokens because the model doesn't need to write transitions, hedges, or explanations. It also makes parsing deterministic.
{
"messages": [{
"role": "user",
"content": "Extract name, email, and company from this text. Return JSON only: {\"name\":\"\",\"email\":\"\",\"company\":\"\"}"
}]
}
7. Batch Independent Requests Instead of Chaining Context
If you're processing a list of independent items (e.g., classifying 50 support tickets), don't put them all in one giant prompt with shared context repeated per item. Separate independent tasks into separate calls so each one only carries the context it actually needs — combined with prompt caching for the shared system prompt, this is usually cheaper than one mega-prompt.
8. Choose the Right Model for the Task
Not every call needs your most capable model. Classification, extraction, and short-answer tasks often work fine on a smaller/faster model tier, which typically also means lower per-token cost. Reserve the larger model for genuinely complex reasoning or long-form generation.
9. Monitor Usage to Find the Real Waste
You can't optimize what you don't measure. Track token usage per endpoint, per user, and per feature so you know where the spend is actually concentrated — it's often a single chatty endpoint rather than the whole app.
If you're running Claude behind an internal API layer, SubToAPI surfaces usage metadata per request — input tokens, output tokens, and model used — in the dashboard, which makes it easy to spot which calls are expensive before you start optimizing blindly. It sits on top of your existing Claude access and gives you application API keys, streaming, and tool use through a standard HTTPS endpoint, with usage visible per key and per team seat. See the quickstart or pricing for details.
10. Avoid Redundant System Prompt Repetition
If you're calling Claude from multiple services (a web app, a background worker, a Slack bot), make sure they're not each maintaining their own slightly different, duplicated system prompt. Centralize it, cache it, and reuse it — this also makes future prompt edits consistent across your stack.
Putting It Together
A typical high-traffic app can cut 30–50% of its input token cost just by combining prompt caching, trimmed history, and filtered tool lists — with no change to response quality. Output token savings from max_tokens discipline and structured formatting are usually smaller in percentage terms but compound over thousands of daily requests.
Questions
Does prompt caching reduce output tokens too? No — caching only reduces the cost of repeated input tokens (system prompts, tool definitions, long context blocks). Output tokens are always billed at full rate regardless of caching.
Is a smaller max_tokens value enough to reduce cost on its own? Not by itself. max_tokens caps the ceiling, but actual cost depends on how many tokens the model generates. Combine it with explicit brevity instructions and structured output formats for real savings.
Will reducing tokens hurt response quality? Not if done correctly. Trimming irrelevant history, filtering unused tools, and requesting structured output usually improves quality by removing noise — the risk is only if you cut context the model actually needs for the current task.