Fine-tune OpenAI's GPT-4o mini LLM AI model

Andreas Nigg
Andreas Nigg · Co-Founder, Pondhouse Data
Published Updated 8 min read
Fine-tune OpenAI's GPT-4o mini LLM AI model
On this page

To fine-tune GPT-4o mini, you upload a JSONL file of example conversations to the OpenAI fine-tuning dashboard, choose gpt-4o-mini as the base model and start a training job. When it finishes, you call the new model through the normal OpenAI API. When we published this guide, fine-tuning GPT-4o mini was even free, until 2024-09-23.

GPT-4o mini is cheap and handles text tasks well, which makes it a good base for customized models. Fine-tuning lets you adapt it to your own use case, for example more consistent customer service answers or a specific output format.

This guide covers the training data format, how much data you need, each setting in the fine-tuning dashboard, how to use the finished model and when RAG is the better choice. For fine-tuning open models like Llama 3 on your own hardware, see our guide on how to finetune LLMs.

Update (November 2026): OpenAI is phasing out self-serve fine-tuning: organizations that have not fine-tuned before can no longer create jobs, and from January 6, 2027 existing customers can't create new ones either. Fine-tuned models keep working until their base model is retired, and gpt-4o-mini-2024-07-18 shuts down on January 14, 2027. The free period and the prices below are from July 2024; current rates are on OpenAI's pricing page.

Why GPT-4o mini?

GPT-4o mini is a compact language model, built as an alternative to larger, more resource-intensive models. It aims for a balance between performance and cost, for developers and businesses with limited budgets or compute.

Cost is the main argument. At July 2024 prices, GPT-4o mini was 66x (!!!) cheaper than GPT-4 Turbo and 33x cheaper than GPT-4o for input tokens. How much you actually save depends on your use case and implementation.

Performance holds up surprisingly well. Various benchmarks show GPT-4o mini on par with the original GPT-4 model, which is just incredible for a model this small. Still, evaluate its language and function calling capabilities against your own project requirements.

Finally, GPT-4o mini can be fine-tuned like many other language models. A fine-tuned GPT-4o mini can potentially outperform much larger and more expensive models on specific use cases.

How much does fine-tuning GPT-4o mini cost?

Fine-tuning GPT-4o mini was free (up to 2 million training tokens per day) until 2024-09-23. After that date, it cost 3$ per 1 million training tokens.

Using a fine-tuned GPT-4o mini model was also cheap (July 2024 prices):

  • 0.3$ per 1 million tokens for input tokens
  • 1.2$ per 1 million tokens for output tokens

Fine-tuning an LLM had never been this cheap. If cost is your main concern, our post on strategies to reduce LLM costs covers other options as well.

How to fine-tune GPT-4o mini

Enough theory, let's start with the actual fine-tuning process.

Format of dataset for fine-tuning GPT-4o mini

A high-quality training set in the right format matters more than anything else for a successful fine-tuning run. The quality and relevance of your training data largely determine how well the fine-tuned model performs. For the OpenAI API, the data must be in JSONL (JSON Lines) format.

JSONL is a text format where each line is a separate, valid JSON object. This makes it efficient to process large datasets line by line.

The content itself is simple. Text completion models (like davinci-002) need prompt/completion pairs. Chat models (like gpt-4o-mini) need arrays of messages with the roles "user" and "assistant", as known from the OpenAI API request payload.

Example of JSONL format for text completion models:

1{"prompt": "Summarize the main points of the article:", "completion": "The article discusses..."}
2{"prompt": "Translate the following sentence to French:", "completion": "La traduction est..."}
3{"prompt": "What are the key features of Python?", "completion": "Python's key features include..."}

This guide uses a chat model, so we need the chat format. For demonstration purposes, we use a small dataset of customer service inquiries and matching responses.

Sample data for this guide, in the format for fine-tuning OpenAI chat models:

1{
2 "messages": [{"role": "system", "content": "You are a customer service representative for an online bookstore."},
3 {"role": "user", "content": "How long does shipping usually take?"},
4 {"role": "assistant", "content": "Shipping times typically range from 3-5 business days for standard delivery. Express shipping options are available for faster delivery."}]
5}
6{
7 "messages": [{"role": "system", "content": "You are a customer service representative for an online bookstore."},
8 {"role": "user", "content": "Can I return a book if I don't like it?"},
9 {"role": "assistant", "content": "Yes, we offer a 30-day return policy for books in new condition. Please keep the original receipt for your return."}]
10}

This is a minimal dataset for demonstration. In practice, you'd want a larger, more diverse set of examples to fine-tune your model effectively.

NOTE: These examples are formatted to be easier to read. In the actual dataset, each JSON dictionary must be on a single line, like so:

1{ "messages": [{"role": "system", "content": "You are a customer service representative for an online bookstore."}, {"role": "user", "content": "Can I return a book if I don't like it?"}, {"role": "assistant", "content": "Yes, we offer a 30-day return policy for books in new condition. Please keep the original receipt for your return."}] }

NOTE 2: You'll need at least 10 examples for fine-tuning.

How much data is needed for LLM fine-tuning?

How much data you need for LLM fine-tuning depends on several factors:

  • Complexity of the task: more complex tasks generally need more data.

  • Desired performance level: higher expectations often require more training data.

  • Base model size and capabilities: larger models may need more data to fine-tune effectively.

  • Domain specificity: highly specialized tasks might need more domain-specific examples.

As a general guideline:

  • Minimum: OpenAI requires at least 10 examples and recommends starting with 50 well-crafted ones, but this is often not enough for complex tasks.

  • Typical range: many successful fine-tuning projects use between 500 and 10,000 examples.

  • Upper end: some large-scale projects use 100,000 or more examples, especially for diverse or complex tasks.

Quality often beats quantity. A small dataset of high-quality, diverse examples can outperform a larger dataset of low-quality or repetitive ones. Keep evaluating the model as you grow the dataset, because returns diminish beyond a certain point.

Note: This point is immensely important. In the good old machine learning days, you needed millions of rows of data. LLMs are different: even small amounts of data influence the output of a model. So make sure you have no (as in zero) wrong data, and a good but not enormous amount of high-quality rows.

For the best results, start with a moderately sized, high-quality dataset and grow it while you monitor the performance. That way you find the sweet spot between data quantity and model performance for your use case.

Step-by-step guide to fine-tuning GPT-4o mini

  1. Navigate to the OpenAI fine-tuning dashboard.

    The OpenAI fine-tuning dashboard in the OpenAI platform

  2. Click "Create". In the overlay, set the following:

    • Base model: select gpt-4o-mini.
    • Training data: upload your jsonl file, as described in the section above.
    • Validation data: select "None". If you have a separate validation dataset, upload it here. It uses the same format as the training dataset and is used to evaluate the model's performance during and after training.
    • Suffix: this suffix is added to the model name after fine-tuning, so you can identify the fine-tuned model later.
    • Seed: set it to a specific number if you want reproducible results. The same seed and job parameters should produce the same results across fine-tuning runs.
    • Batch size: set it to auto for your first run. You can try different batch sizes later. Batch size mainly affects training speed and much less the model performance. Since training runs on OpenAI's infrastructure, leaving it at auto is a good choice.
    • Learning rate multiplier: set it to auto for your first run. This hyperparameter controls how much the model's weights change during training. A smaller value prevents over-fitting and can stabilize training, but values that are too small slow training down. There are good ways to determine the learning rate automatically, so auto is a good choice here as well.

    Fine-tuning settings with base model, training data, suffix, seed and hyperparameters

  3. Click "Create". You'll see the running job with a summary of its current stages.

    Fine-tuning job details for gpt-4o-mini with status and job messages

  4. When the job is finished, you'll find a chart of the training loss. You want the training loss to go down and settle at a low number at the end. If it doesn't decrease, you need more or different training data, or you might have to adjust the learning rate.

    Training loss chart dropping from about 2.5 to 0.0004

Using a fine-tuned OpenAI model

When the job is complete, the model name appears at the very top of the job page. It looks similar to ft:gpt-4o-mini-2024-07-18:pondhouse-data-og:customer-service:9oofdDLO.

Head over to the OpenAI Chat Playground, and select your fine-tuned model from the drop-down in the top-left. Use the chat interface to test your model.

OpenAI Chat Playground answering a question with the fine-tuned model

One interesting fact about the screenshot above: I asked a question similar to one in my training samples, and I got exactly the answer from the training data. This shows, first, that the training worked and, second, that the model fits training data very quickly. If I had just one wrong training sample, the model would take it for a fact. So make sure you have no wrong data!

To use the model in your own application, call it with the normal OpenAI SDK:

1from openai import OpenAI
2client = OpenAI()
3
4completion = client.chat.completions.create(
5 model="ft:gpt-4o-mini-2024-07-18:pondhouse-data-og:customer-service:9oofdDLO",
6 messages=[
7 {"role": "system", "content": "You are a customer service representative for an online bookstore. Provide helpful and friendly assistance to customers with their inquiries."},
8 {"role": "user", "content": "I received a damaged book. What should I do?"}
9 ]
10)
11
12print(completion.choices[0].message.content)

When should I use fine-tuning vs embeddings / retrieval augmented generation?

Embeddings with retrieval augmented generation (RAG) work best when you have a large quantity of documents and context you want the model to understand.

As a rule, don't use fine-tuning to add new knowledge to a model. Use RAG for that.

If you want to change the behaviour, output format or general attitude of the model, fine-tuning is the better approach. Before you start a training run, it can be worth trying automated prompt optimization with DSPy, which works from the same kind of example data but leaves the model as it is.

Retrieval and fine-tuning are not alternatives to each other. They can in fact complement each other.

Conclusion

Fine-tuning GPT-4o mini is a practical way to adapt an OpenAI model to a specific use case. The process has four parts: prepare a JSONL dataset, create a job in the fine-tuning dashboard, check the training loss and call the model by its ft: name.

Points to remember:

  1. Data quality matters most. Make sure your training examples are accurate and relevant to your use case.

  2. Start with a moderate amount of high-quality data rather than aiming for large quantities.

  3. The fine-tuning process itself is straightforward on OpenAI's platform.

  4. GPT-4o mini is a cost-effective alternative to larger models for many applications.

Fine-tuning is not a magic solution. Results depend on your use case and the quality of your training data, so test the fine-tuned model thoroughly (for example by comparing model versions with Prompt Flow evaluations) and keep refining the dataset. Because fine-tuning is so cheap now, those experiments cost very little.

Further reading

Interested in building high-quality AI agent systems?

We prepared a comprehensive guide based on cutting-edge research for how to build robust, reliable AI agent systems that actually work in production. This guide covers:

  • Understanding the 14 systematic failure modes in multi-agent systems
  • Evidence-based best practices for agent design
  • Structured communication protocols and verification mechanisms
Andreas Nigg

About the author

Andreas Nigg

Co-Founder, Pondhouse Data

Andreas has spent more than eight years building data applications. At Pondhouse Data he designs and ships AI systems and integrates them into complex, real-world environments.