Your OpenAI bill is probably higher than it needs to be. Not because you're scaling fast — because the tokens themselves are wasteful. The average production prompt wastes 40–70% of its token budget on redundant instructions, repeated context, and identical requests that hit the API over and over.
This guide walks through three techniques that compound together to cut costs by 60% or more without changing your output quality.
Rewrites bloated prompts to their minimum effective form before they hit the API.
The fastest win is cleaning up your system prompts. Most accumulate instructions over time without ever being audited. Here's a before and after from a real customer support bot:
You are a helpful customer support assistant. Please make sure to always be polite and professional in your responses. It is very important that you respond to customer questions in a helpful manner. Make sure to note that you should always try to resolve the customer's issue. Please be concise but also make sure to be thorough. Always maintain a professional tone and make sure to be empathetic to the customer's situation.
You are a polite, professional customer support assistant. Resolve issues concisely and empathetically.
Same behavior. 80% fewer tokens on every single call. At 10,000 calls per day, that's 710,000 tokens saved daily — before we even get to caching.
Returns cached responses for identical and semantically similar prompts.
After compressing your prompts, caching is the next biggest lever. There are two layers:
Hash the prompt. If it matches a cached hash, return the cached response. Simple, fast, catches 10–15% of typical API calls.
Generate an embedding for the prompt. Compare it against cached embeddings using cosine similarity. If similarity ≥ 85%, return the cached response. Catches an additional 20–35% of calls that exact match misses.
// Tokoscope handles both layers automatically
const client = wrap(new OpenAI(), { apiKey: 'ts_live_...' })
// First call — cache miss, stores response + embedding
await client.chat.completions.create({
model: 'gpt-4o-mini',
messages: [{ role: 'user', content: 'What is the capital of France?' }]
})
// Second call — semantic hit (89.3% match)
await client.chat.completions.create({
model: 'gpt-4o-mini',
messages: [{ role: 'user', content: 'Name the French capital city.' }]
})
// ⚡ Tokoscope cache hit [semantic (89.3% match)] — saved 21 tokens
Identifies which features or endpoints are burning the most — so you know where to focus optimization effort.
The third technique isn't a direct optimization — it's the intelligence layer that tells you where to focus. Most teams applying blanket optimizations miss the 20% of endpoints that account for 80% of costs.
By tracking token usage per endpoint or feature, you can see exactly which part of your product is burning the most and prioritize accordingly.
"We thought our search feature was the bottleneck. Cost attribution showed it was actually our onboarding flow — which we'd never thought to optimize."
| Technique | Applies to | Typical saving | Cumulative |
|---|---|---|---|
| Prompt compression | All calls | ~30% | 30% saved |
| Exact match caching | Repeated prompts | ~10–15% | 40–45% saved |
| Semantic caching | Similar prompts | ~20–25% | 60–70% saved |
| Total | — | — | 60–70% saved |
These techniques compound because they operate at different layers. Compression reduces the size of every call. Caching eliminates calls entirely. Attribution tells you where to apply the other two first.
The manual approach takes days. Set up a Redis cache, build a prompt auditor, wire up analytics, keep pricing tables up to date across providers.
Or drop in two lines and let Tokoscope handle all three automatically:
import { wrap } from 'tokoscope'
const client = wrap(new OpenAI(), {
apiKey: 'ts_live_...' // from app.tokoscope.com/settings
})
// That's it. Compression, caching, and attribution
// are all running automatically on every call.
Free tier monitors up to 500K tokens per month. No credit card required.
Get started free →