Build with AI

How do you use GPT-4o mini to cut API costs?

· By Robert Scales · 4 min read

Short answer

Send most of your requests to GPT-4o mini, which costs $0.15 per million input tokens and $0.60 per million output tokens, and keep the larger GPT-4o only for the requests that truly need it. A simple router that picks the model per task, plus a test set to check quality, can cut a typical bill by well over half.

A week after its release, GPT-4o mini is the cheapest capable model on OpenAI's price list. That changes how you should design an application. Instead of choosing one model for everything, you can treat models like staff with different hourly rates: the small one handles the routine work, and the expensive one is called in only when a request is hard. The savings come from that split, not from any single trick.

The API bills by the token, a small piece of text; OpenAI's pricing page puts 1,000 tokens at roughly 750 English words. You pay separately for input tokens (what you send, including instructions and any documents) and output tokens (what the model writes back), and output costs more.

The prices that matter

These are the per-million-token prices on OpenAI's pricing page this week.

ModelInputOutput
gpt-4o$5.00$15.00
gpt-4o-mini$0.15$0.60
GPT-3.5 Turbo (current version)$0.50$1.50

Both GPT-4o models accept up to 128,000 tokens of context, and OpenAI says GPT-4o mini can write up to 16,000 tokens in one reply. OpenAI says it costs over 60% less than GPT-3.5 Turbo while scoring higher on its benchmarks, such as 82% on MMLU, a broad test of general knowledge. If you still run GPT-3.5 Turbo, switching is usually the easiest saving you will ever make.

A worked cost comparison

Imagine an app that sorts incoming customer emails. The figures below are illustrative: 100,000 requests a month, each with about 1,000 input tokens (instructions plus the email) and 200 output tokens (a category and a one-line summary). That adds up to 100 million input tokens and 20 million output tokens a month.

SetupInput costOutput costMonthly total
All gpt-4o100 × $5.00 = $50020 × $15.00 = $300$800
All gpt-3.5-turbo100 × $0.50 = $5020 × $1.50 = $30$80
All gpt-4o-mini100 × $0.15 = $1520 × $0.60 = $12$27
Router: 80% mini, 20% gpt-4o$12 + $100$9.60 + $60$181.60

If the router tries the small model first, the escalated 20% also pay for that first attempt, about $5.40 more. Even so, the mixed setup costs less than a quarter of the all-GPT-4o version. Two more levers stack on top. The Batch API, for work that can wait up to 24 hours, such as overnight reports, is billed at half price. And shorter prompts cost less on every single call, so trimming a long system message pays off quickly at this volume.

A simple router in Python

A router is a few lines of code that decide which model gets each request. This one uses the openai Python library (version 1.x). It starts with the small model and escalates only when the small model says it is unsure.

from openai import OpenAI
client = OpenAI()  # reads OPENAI_API_KEY from the environment

SYSTEM = ("Classify the email as billing, technical, sales or other, "
          "then give a one-line summary. If you cannot decide, reply only: UNSURE")

def ask(model, text):
    r = client.chat.completions.create(
        model=model,
        messages=[{"role": "system", "content": SYSTEM},
                  {"role": "user", "content": text}],
        max_tokens=150,
        temperature=0,
    )
    return r.choices[0].message.content.strip(), r.usage

def route(text, hard=False):
    if hard or len(text) > 20000:          # long or flagged requests go straight up
        return ask("gpt-4o", text)
    answer, usage = ask("gpt-4o-mini", text)
    if answer.startswith("UNSURE"):        # escalate only the doubtful cases
        return ask("gpt-4o", text)
    return answer, usage

max_tokens caps the reply length, so a confused request can't run up output costs. The usage object returned with each call reports the tokens billed, which you can log to see where your money really goes. The escalation rule is deliberately crude; you can replace it with any test you trust, such as "the answer is not one of the four allowed categories."

Try it: Collect 30 real requests from your own app. Run them through both models, put the answers side by side in a spreadsheet, and mark each mini answer as good enough or not. The share you mark good is a fair first estimate of how much traffic you can route to the small model.

Check quality before you switch

A cheaper model is only a saving if the answers stay acceptable. Keep that test set of real requests, rerun it whenever you change prompts or models, and look at the failures, not just the score. Set a monthly budget in your OpenAI billing settings as a safety net; the pricing page notes there may be a short delay before the limit takes effect.

Which tasks can a small model handle?

Small models do best on high-volume, well-defined jobs where the answer is short and the instructions are clear. Sorting messages into categories, pulling fields such as dates and totals out of text, rewriting a paragraph in a set tone, short translations and first-draft replies all fit. OpenAI reports that early partners found GPT-4o mini much better than GPT-3.5 Turbo at extracting structured data from receipt files and at drafting email replies from a thread's history.

Keep the larger model for work where a mistake is costly or the reasoning is long: multi-step analysis, careful review of contracts or code, and questions that need weighing many pieces of evidence. Even then, a common pattern is to let the small model do the first pass, such as summarizing or filtering, and give only the condensed result to GPT-4o.

The honest answer for your own app comes from testing, not from benchmarks. A model that scores well on general tests may still stumble on your particular wording, and one that seems weaker on paper may handle your narrow task perfectly. Your test set decides.

Sources

  1. Pricing (OpenAI API, July 2024) — OpenAI
  2. GPT-4o mini: advancing cost-efficient intelligence — OpenAI, July 18, 2024
  3. OpenAI unveils GPT-4o mini, a smaller and cheaper AI model — TechCrunch (Maxwell Zeff), July 18, 2024

Get the free Guide to Artificial Intelligence

Sign up for the weekly newsletter and receive the free guide: what changed in AI this week, one lesson, one prompt to try. Unsubscribe in one click.

How we handle your address

Back to top

Display

Your choices are saved in this browser only. No data is sent.

Text size
100%
Colours
Reading
More settings
Accessibility statement