← LLMWatch
LLM Cost Optimization · September 2026

How to Reduce Your OpenAI API Costs: A Practical Guide

You've been getting billed for tokens you don't need. Here's how to cut your LLM API spend without touching your quality bar — and how to find which feature is actually responsible for the bill.

1. Know where your money is going (this is harder than it sounds)

Before you can optimize, you need attribution. OpenAI's billing dashboard shows total spend by day. It does not tell you whether it's your AI search box, your document summarizer, or your customer support bot that's causing the spike.

This is the most common situation: a team ships three LLM-powered features, the monthly bill jumps from $200 to $1,800, and nobody knows which feature to look at first.

Key insight: Most LLM cost problems are attribution problems first, optimization problems second. You can't optimize what you can't see.

The practical way to get attribution today is to instrument each feature with a cost-tracking wrapper around your OpenAI or Anthropic client. We'll look at how to do this below, and we'll also cover a free calculator to estimate costs before they happen.

2. Model selection: the single highest-leverage decision

The spread between the cheapest and most expensive models is roughly 30-50x. Getting model selection right often matters more than all other optimizations combined.

ModelInput (per 1M tokens)Output (per 1M tokens)Best for
GPT-4o-mini$0.15$0.60Classification, simple extraction, routing
Claude 3 Haiku$0.25$1.25Fast, simple tasks; high-volume pipelines
Claude 3.5 Haiku$0.80$4.00Balanced capability/cost; medium complexity
GPT-4o$2.50$10.00Complex reasoning, multi-step tasks
Claude 3.5 Sonnet$3.00$15.00Nuanced tasks, coding, long documents
Gemini 1.5 Flash$0.075$0.30Ultra-high volume, batch workloads

Practical rule: use the weakest model that passes your quality bar

For a feature doing sentiment classification on support tickets, GPT-4o-mini at $0.15/M input tokens is almost certainly sufficient. Using GPT-4o for this costs 16x more with no meaningful quality improvement.

Establish a small labeled eval set for each feature (even 50 examples), run both models, and pick the cheaper one that meets your threshold. Most teams skip this step and default to the most powerful model.

3. Token optimization: cut waste before it becomes spend

Trim system prompts aggressively

System prompts run on every request. A bloated 2,000-token system prompt costs $0.005 per request at GPT-4o rates. At 10,000 requests/day that's $50/day, $1,500/month — from the system prompt alone.

Audit your system prompts. Remove examples that could live in few-shot user messages instead. Remove repetitive instructions. Remove boilerplate. Aim for the minimum that preserves behavior.

Cache aggressively at the application layer

Many LLM calls are semantically identical. A RAG system answering "what is your return policy?" for the 500th time doesn't need to hit the model. Cache by embedding similarity (cosine threshold ~0.95) with a simple vector store.

Teams using semantic caching routinely report 30-60% reduction in LLM API calls for support and FAQ use cases.

Use structured output to reduce completion tokens

Verbose prose completions are expensive. If you're extracting structured data, use JSON mode or function calling and specify exactly the fields you need. A classification that returns {"category": "billing"} costs far less than one that returns three sentences explaining the classification.

Chunk documents at the retrieval layer, not the completion layer

For RAG workloads, retrieve only the relevant chunks (typically top-3 to top-5), not entire documents. An aggressive chunking strategy that keeps chunks under 512 tokens and retrieves only high-similarity results can reduce context window usage by 40-70%.

4. Use the OpenAI Batch API for non-realtime workloads

OpenAI's Batch API (and Anthropic's equivalent) processes requests asynchronously with a 24h SLA and costs 50% of the synchronous API. Any workload that can tolerate latency — document classification, bulk summarization, overnight processing jobs — should use the batch endpoint. This is a direct 2x cost reduction for applicable workloads.

5. Measure the impact of every change

Without per-feature attribution, you can't tell if an optimization worked. You'll make changes, see a slight decrease in the aggregate bill, and not know whether it was your optimization or just lower traffic.

The simplest instrumentation approach:

import openai

def tracked_completion(feature_name: str, **kwargs):
    response = openai.chat.completions.create(**kwargs)
    usage = response.usage
    cost = (usage.prompt_tokens / 1000) * INPUT_PRICE + \
           (usage.completion_tokens / 1000) * OUTPUT_PRICE
    log_cost(feature_name, cost, usage.prompt_tokens, usage.completion_tokens)
    return response

Call it as tracked_completion("search-feature", model="gpt-4o-mini", messages=[...]) and you immediately have per-feature cost breakdown.

Use the LLM Cost Calculator to estimate costs before writing a single line of code: lior-seats.github.io/llm-cost-calculator — enter your token estimates and request volume to see projected daily/monthly/annual spend across all major models.

6. Set spend alerts before you need them

Both OpenAI and Anthropic have billing alerts, but they're account-level. By the time your account-level alert fires, you already have a problem. Feature-level alerts — "alert me when the search feature exceeds $50/day" — are more actionable.

If you're tracking costs at the feature level (see the instrumentation snippet above), you can add a simple threshold check that fires an alert before the feature goes off the rails.

Summary: the optimization priority order

  1. Get attribution first — you can't optimize what you can't see
  2. Right-size your models — 16-30x cost difference between GPT-4o-mini and GPT-4o
  3. Use Batch API for non-realtime workloads (50% discount)
  4. Cache semantic duplicates at the application layer
  5. Trim system prompts — they run on every request
  6. Use structured output to reduce completion token bloat
  7. Set feature-level alerts before problems compound

Want per-feature LLM cost attribution automatically?

LLMWatch instruments your OpenAI and Anthropic calls to show real-time cost breakdown by feature, endpoint, and user — with threshold alerts before the bill arrives.

Join the LLMWatch waitlist →