How to Reduce Your OpenAI API Costs
Learn how to reduce your OpenAI API costs by cutting prompt token bloat, not quality, with a measurable code example and practical fixes today.

If your OpenAI or Anthropic bill has grown faster than your actual usage, the problem almost never lives in how many requests you're sending — it lives in how many tokens each request burns. Learning how to reduce your OpenAI API costs starts with understanding that a single verbose prompt can cost 2-3x more than it needs to, every single time it runs, and that adds up fast once you're calling the API thousands of times a day.
This guide walks through why token count (not request count) drives your bill, how to measure where your tokens are actually going, and concrete ways to cut that number without making your prompts worse.
Why Your API Bill Grows Faster Than Your Usage
Most teams assume cost scales linearly with traffic: twice the users, twice the bill. In practice it scales with tokens per call, and that number quietly creeps upward as a codebase matures. System prompts accumulate extra instructions nobody removes. Few-shot examples get added "just in case" and never get pruned. Context windows get stuffed with entire documents instead of the relevant excerpt. None of these changes look like a cost problem in a code review — they just look like someone being thorough.
The result: a prompt that started at 200 tokens can end up at 600-800 tokens six months later, while the number of API calls stays the same. That's a 3-4x cost increase hiding in plain sight.
The Real Cost Driver: Prompt Verbosity, Not Model Choice
Switching to a cheaper model is the first thing most teams try, and it often backfires — a cheaper model that needs more retries or produces worse output ends up costing more in aggregate. The more reliable lever is trimming what you're actually sending, because both input and output tokens are billed, and a bloated prompt inflates both: input directly, and output indirectly, since verbose instructions tend to produce verbose responses.
Two tools from Cuelara, an AI prompt-optimization toolkit, are built specifically around this: a Token Optimizer that compresses a prompt based on its actual measured token count rather than a guess, and a Diff & Cost Estimate tool that shows you the exact cost difference between two prompt versions before you ship either one.
How to Measure Where Your Tokens Are Actually Going
Before optimizing anything, measure it. For OpenAI models, the tiktoken library gives you an exact count — not an estimate — of how many tokens a given string will cost:
import tiktoken
def count_tokens(text: str, model: str = "gpt-4o") -> int:
encoding = tiktoken.encoding_for_model(model)
return len(encoding.encode(text))
verbose_prompt = """
You are a highly skilled and experienced customer support assistant
who has been trained extensively on our product documentation and
company policies. Please carefully read the following customer
message and respond in a helpful, friendly, and professional manner,
making sure to address all of their concerns thoroughly and provide
clear next steps.
Customer message: My order hasn't arrived yet.
"""
compressed_prompt = """
Role: support assistant.
Task: reply helpfully to the customer message. Address all concerns, give clear next steps.
Customer message: My order hasn't arrived yet.
"""
print("Verbose:", count_tokens(verbose_prompt))
print("Compressed:", count_tokens(compressed_prompt))
Running this on the two versions above shows the verbose prompt costs roughly twice as many input tokens as the compressed one — for instructions that produce functionally identical output. At API scale, that's not a rounding error.
How to Cut Your API Costs Without Losing Quality
- Compress instructions, don't just shorten them. Cutting words randomly can strip out constraints the model actually needs. The goal is removing redundant phrasing while keeping every instruction that changes behavior, then re-measuring to confirm the compressed version still says everything the original did.
- Cache anything reused across calls. If a system prompt or a large reference document is identical across many requests, use your provider's prompt caching feature instead of resending it every time — this can cut repeated-context costs dramatically.
- Extract only the relevant context, not the whole document. Pasting an entire PDF into a prompt to answer one question wastes the vast majority of those tokens. Pulling just the relevant section first (a retrieval step) keeps the prompt focused and cheap.
- Compare before you ship a prompt change. A change that looks like an improvement in a quick test can quietly add tokens elsewhere. Running a side-by-side cost comparison before deploying catches this before it hits production traffic.
- Right-size the model per task, not per project. A classification or extraction task rarely needs your most expensive model — reserve that for tasks that genuinely require deeper reasoning.
Best Practices to Keep Costs Down Long-Term
- Re-measure token counts whenever a prompt is edited, not just when it's first written — costs drift upward gradually, not all at once.
- Treat your system prompt like production code: review it periodically for accumulated cruft, the same way you'd review a config file that's grown over time.
- Set a token budget per prompt type and flag anything that exceeds it in code review.
- Log actual token usage per request in production so cost regressions show up in monitoring, not just on the monthly invoice.
Frequently Asked Questions
Does prompt compression reduce output quality? Not if done correctly — the goal is removing redundant or repetitive phrasing while preserving every instruction and constraint that actually affects the model's behavior. A poorly compressed prompt that drops a real constraint will hurt quality; a well-compressed one won't, because nothing the model needed was removed.
Is switching to a cheaper model a good way to cut costs? Sometimes, but it's not the first thing to try. A cheaper model that produces less reliable output often needs more retries or post-processing, which can erase the savings. Compressing prompt verbosity usually has a more predictable payoff and doesn't risk output quality the way a model downgrade can.
How much can prompt compression actually save? It depends heavily on how verbose the original prompt is, but cutting a bloated system prompt or set of instructions by 40-50% in token count is common once accumulated redundancy is removed, without changing what the prompt asks for.
Does this apply to Claude and Gemini too, not just OpenAI? Yes — token-based billing and the same verbosity-creep problem apply across every major LLM provider. The techniques here (measuring actual token counts, compressing without dropping constraints, caching repeated context) aren't OpenAI-specific.
Key Takeaways
API costs almost always come down to tokens per call, not calls per month, and that number grows quietly as prompts accumulate redundant instructions over time. Measure your actual token counts instead of guessing, compress based on that measurement rather than an arbitrary rewrite, and re-check costs whenever a prompt changes — treating prompt bloat as a recurring maintenance task, not a one-time cleanup, is what keeps the bill from creeping back up.
Try It Yourself
If you'd rather not build a token-counting script for every prompt you write, try compressing one with Cuelara here — paste in a prompt and it shows the exact token reduction before you ship anything.


