The Claude API Cost Optimization Guide
cut our claude api costs by 60% last quarter without noticeably degrading output quality – and yeah, i’m sharing the whole playbook, not just the vague high-level stuff. this is everything we actually implemented, with the numbers.
## prompt compression is where most teams leave money on the table
the single biggest win for us was auditing our system prompts. we had accumulated this bloated instruction set over months – every time something broke, someone added a paragraph. ended up with 800+ token system prompts that were mostly redundant or contradictory.
after a proper rewrite focused on density:
– trimmed the system prompt from 847 tokens to 203 tokens by removing restated instructions and replacing verbose explanations with direct directives
– rewrote few-shot examples to be shorter while keeping the pattern clear – our examples went from avg 120 tokens each to 45
– removed filler phrases like “please remember to always ensure that you” – just say what you want
– cut politeness scaffolding entirely (“thank you, here is your response”) – models don’t need it and you’re paying for those tokens on output too
that compression alone knocked about 30% off our bill before we touched anything else.
## caching and batching are not optional if you have any repeated context
if you’re making api calls where the same context appears repeatedly – like a shared knowledge base, a consistent persona block, or a product catalog – and you’re not using prompt caching, you’re just burning money. for us, we have a ~2k token reference document that goes into probably 70% of our calls. caching that context reduced our effective input token cost on those calls dramatically because you’re only charged the cache write once, then cache read pricing on subsequent hits.
batching helped on a different axis. we had a bunch of async jobs that were firing individual requests as events came in. restructuring to group them into batch jobs where latency tolerance allowed it got us better throughput management and took advantage of lower batch pricing tiers.
## output length control actually matters
people focus a lot on input tokens but output tokens cost the same or more depending on the model tier. we were getting responses way longer than we needed for structured tasks. fixes we made:
1. added explicit length constraints in the prompt (“respond in 3 sentences or fewer”, “return only the json object with no explanation”)
2. stopped asking open-ended questions when we needed specific formats – vague prompts get verbose answers
3. for classification and extraction tasks, we switched to prompts that force short outputs rather than ones that invite the model to “explain its reasoning” unless we actually needed the reasoning
4. used the max_tokens parameter as a hard ceiling on tasks where we knew the expected output size
that last point is underused. if you’re doing a binary classification call, set max_tokens to something like 10. it won’t hurt quality and it prevents runaway outputs if the model misunderstands the task.
## model routing based on task complexity
not every call needs the most capable model. we built a simple routing layer that sends requests to different model tiers based on task type:
– simple extraction, formatting, classification – cheaper/faster model
– multi-step reasoning, nuanced writing, complex analysis – full capability model
– anything that needs to be fast and the output is low-stakes – cheapest viable option
the routing logic took maybe two days to build and the savings were immediate. something like 55% of our volume turned out to be tasks where the cheaper model performed identically on our eval metrics.
combine all of this and the math gets good fast. prompt compression + caching + output control + routing is genuinely how you get to 60% reduction without the outputs getting worse – in some cases our quality metrics actually improved because tighter prompts get more consistent responses.
curious what optimization people have found that i didn’t cover here – specifically whether anyone’s done anything interesting with structured outputs to reduce token overhead on json heavy workflows?
5 Replies
Join the discussion.
Log In to Replyjust tried this and yeah it works. debugging with AI is where I see the biggest time savings
the 60% reduction claim is interesting but really depends on your token patterns. caching system prompts alone got us maybe 20-25%. the bigger wins came from batching short requests instead of firing them one at a time.
does any of this apply if youre on the claude.ai pro plan vs direct API? or is this purely for API users paying per token?
can confirm this works. claude code is my go-to for complex refactoring tasks now
refactoring is fine but watch your context window on large codebases. feeding the whole file costs way more than scoping it to just the relevant function. learned that the hard way.