How to reduce OpenAI API costs

Reduce OpenAI API costs by measuring spend per completed task, trimming unnecessary input and output, and testing lower-cost models on repeated work. Review caching for shared instructions and batch pricing for jobs that can wait. Set retry limits and track quality alongside the bill so failed requests and rework stay visible.

Example

A code review job costs 24 cents for 30 requests across 10 accepted reviews. Its cost is 2.4 cents per accepted review. If a shorter prompt costs 18 cents across the same tasks but only 6 reviews pass, the cost rises to 3 cents per accepted review.

What to do

  1. Group a sample of real workloads by task and record model, input, cached input and output usage where available. Include retries and compare provider billing totals for the same time window.
  2. Shorten one task’s prompt. Keep the changed lines and directly relevant files, cap the response size, and measure how many tasks still pass your review checks.
  3. Test a lower-cost model on repetitive, easily checked work. Keep separate criteria for higher-risk fixes and consider a stronger model for tasks that fail those checks.
  4. Measure cached input usage for requests with shared instructions. Consider the provider’s Batch API for tests or classifications you can receive later. Check endpoint support and data handling before moving any work.
  5. Use per-task retry limits and spend alerts. Reconcile gateway usage with the upstream provider statement, and track IDE seat fees separately if you also pay for a coding product.

How to verify

Compare the same tasks and acceptance rules before and after one change. Report total cost, accepted tasks, cost per accepted task and p95 completion time. Recheck the provider’s current rates before forecasting monthly savings.

Limits

A smaller model or shorter output can increase rework. Apply gateway controls only to eligible routed traffic and confirm any separate endpoints, including batch work, with the client and provider.

Frequently asked questions

Can caching reduce the model bill?
Eligible repeated input can be billed differently. Check cached tokens in usage records and use the provider’s current rates for the model you tested.
What work is suitable for batch processing?
Try an evaluation run or offline classification where a delayed result is acceptable. Keep interactive feedback on a path with a suitable response time.
Do these changes lower my ChatGPT or IDE subscription fee?
They address metered API requests. Track any subscription fee as a separate line when calculating total coding spend.

Spendplane for this workflow

Estimate usage before committing to a model mix

Start free

Related reading