How to beginner · 3 min read

How many examples needed for fine-tuning

Quick answer
For effective fine-tuning with the OpenAI API, you typically need at least 100 high-quality examples, though 500+ examples yield better results. The exact number depends on task complexity and data quality, but fewer than 100 examples often lead to suboptimal fine-tuning.

PREREQUISITES

  • Python 3.8+
  • OpenAI API key (free tier works)
  • pip install openai>=1.0

Setup

Install the openai Python package and set your API key as an environment variable.

  • Run pip install openai
  • Set OPENAI_API_KEY in your environment
bash
pip install openai
output
Collecting openai
  Downloading openai-1.x.x-py3-none-any.whl (xx kB)
Installing collected packages: openai
Successfully installed openai-1.x.x

Step by step

This example demonstrates uploading a training file with 100+ examples and creating a fine-tuning job using the OpenAI SDK v1+ pattern.

python
import os
from openai import OpenAI

client = OpenAI(api_key=os.environ["OPENAI_API_KEY"])

# Upload training data file (JSONL format with messages)
training_file = client.files.create(
    file=open("training_data.jsonl", "rb"),
    purpose="fine-tune"
)

# Create fine-tuning job with a base model
job = client.fine_tuning.jobs.create(
    training_file=training_file.id,
    model="gpt-4o-mini-2024-07-18"
)

print(f"Fine-tuning job created with ID: {job.id}")

# Poll job status (simplified example)
import time
while True:
    status = client.fine_tuning.jobs.retrieve(job.id)
    print(f"Status: {status.status}")
    if status.status in ["succeeded", "failed"]:
        break
    time.sleep(10)

if status.status == "succeeded":
    print(f"Fine-tuned model: {status.fine_tuned_model}")
output
Fine-tuning job created with ID: ftjob-abc123
Status: running
Status: running
Status: succeeded
Fine-tuned model: gpt-4o-mini-ft-2026-04-01

Common variations

You can fine-tune different base models like gpt-4o or gpt-4o-mini. For smaller datasets, consider prompt engineering or few-shot learning instead of fine-tuning. Async fine-tuning monitoring can be implemented with event loops or callbacks.

python
import asyncio

async def monitor_fine_tune(job_id):
    while True:
        status = client.fine_tuning.jobs.retrieve(job_id)
        print(f"Async status: {status.status}")
        if status.status in ["succeeded", "failed"]:
            break
        await asyncio.sleep(10)

asyncio.run(monitor_fine_tune(job.id))
output
Async status: running
Async status: running
Async status: succeeded

Troubleshooting

  • If your fine-tuning job fails, check your training data format: it must be JSONL with messages arrays including system, user, and assistant roles.
  • Ensure you have at least 100 examples; fewer may cause poor model performance.
  • Monitor API usage limits and file upload size constraints.

Key Takeaways

  • Use at least 100 examples for fine-tuning to achieve meaningful improvements.
  • Higher quality and more examples (500+) improve fine-tuning results significantly.
  • For small datasets, prefer prompt engineering or few-shot learning over fine-tuning.
  • Always validate your training data format as JSONL with proper message roles.
  • Monitor fine-tuning job status via the OpenAI SDK to handle success or failure.
Verified 2026-04 · gpt-4o-mini-2024-07-18, gpt-4o
Verify ↗