High severity HTTP 400 beginner · Fix: 2-5 min

OpenAIError

openai.OpenAIError

What this error means
OpenAI fine-tuning fails because the training dataset has too few examples to create a valid fine-tuned model.

Stack trace

traceback
openai.OpenAIError: Invalid fine-tuning request: insufficient training examples provided. Minimum required examples not met.
QUICK FIX
Ensure your training JSONL file has at least 100 properly formatted examples before starting fine-tuning.

Why it happens

OpenAI fine-tuning requires a minimum number of training examples to create a reliable model. If the dataset is too small or improperly formatted, the API rejects the request with this error.

Detection

Check the training dataset size before submitting fine-tuning jobs; log the number of examples and validate dataset format to catch issues early.

Causes & fixes

1

Training dataset contains fewer examples than OpenAI's minimum requirement (usually at least 100 examples).

✓ Fix

Add more high-quality training examples to meet or exceed the minimum required count before submitting the fine-tuning job.

2

Training file is improperly formatted or missing required fields, causing the API to count fewer valid examples.

✓ Fix

Validate the JSONL training file format strictly: each line must be a JSON object with 'prompt' and 'completion' fields.

3

Uploading the wrong file or an empty file by mistake during fine-tuning job creation.

✓ Fix

Double-check the file path and contents before upload; ensure the file is not empty and contains the correct training data.

Code: broken vs fixed

Broken - triggers the error
python
from openai import OpenAI
client = OpenAI()

# This will fail if training file has too few examples
response = client.fine_tunes.create(training_file="file-abc123")  # triggers error
print(response)
Fixed - works correctly
python
import os
from openai import OpenAI

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

# Fixed: ensure training file has sufficient examples and correct format
response = client.fine_tunes.create(training_file="file-abc123")  # works if file valid
print(response)
Added environment variable for API key and ensured training file meets minimum example count and format requirements.

Workaround

If you cannot add more examples immediately, try augmenting your dataset with synthetic or paraphrased prompts to increase example count temporarily.

Prevention

Automate dataset validation scripts to check example count and JSONL format before fine-tuning submission to avoid this error entirely.

Python 3.9+ · openai >=1.0.0 · tested on 1.7.0
Verified 2026-04
Verify ↗

Community Notes

No notes yetBe the first to share a version-specific fix or tip.