How to Fine-Tune OpenAI Models
OpenAI wound down fine-tuning support for newer models (GPT-5 series) in May 2026. Fine-tuning remains available for: GPT-4.1, GPT-4.1 Mini, GPT-4.1 Nano, GPT-4o, GPT-4o Mini, and o4-mini. If you are starting a new fine-tuning project, GPT-4.1 Nano offers the best cost-to-quality ratio for most tasks, while GPT-4.1 provides the highest quality ceiling.
Step 1: Prepare Your JSONL Dataset
OpenAI fine-tuning uses JSONL files where each line is a JSON object with a "messages" array. Each message has a "role" (system, user, or assistant) and "content" fields. The model learns to produce the assistant messages given the system and user context.
A basic training example:
{"messages": [{"role": "system", "content": "You are a concise financial analyst."}, {"role": "user", "content": "Summarize Q3 revenue."}, {"role": "assistant", "content": "Q3 revenue was $4.2B, up 12% year-over-year, driven by 18% growth in cloud services offset by 3% decline in hardware."}]}
For function-calling fine-tuning, include "tools" and "tool_calls" in your training examples. This teaches the model when to call specific functions and how to format the arguments. Each example should show a complete tool-calling cycle: user request, tool call, tool result, and final response.
OpenAI requires a minimum of 10 training examples, but recommends 50-100 for noticeable quality improvements. For significant behavioral changes, aim for 500-1,000 examples. Each example can be a single-turn or multi-turn conversation. Multi-turn examples are more expensive (more tokens) but teach the model conversation dynamics that single-turn examples miss.
Common formatting mistakes that cause validation errors: missing the "messages" key, using roles other than system/user/assistant/tool, including empty content strings, and having conversations where the assistant message is missing. Run OpenAI's validation script before uploading to catch these issues.
Step 2: Upload and Validate Data
Upload your JSONL file through the OpenAI API using the Files endpoint with purpose="fine-tune". The API returns a file ID that you will reference when creating the fine-tuning job. File uploads are limited to 1GB, which is more than enough for most datasets (a 5,000-example dataset is typically 5-50MB).
Alternatively, use the OpenAI dashboard (platform.openai.com) to upload files through the browser. The dashboard provides a visual preview of your data and highlights formatting issues before you start training.
OpenAI validates your file format during upload and will reject files with structural errors. It also estimates the training cost based on your token count and model selection. Review this estimate before proceeding, especially if your dataset is large. A 10,000-example dataset on GPT-4o at $25 per million training tokens can cost over $100 for a single training run.
Prepare a separate validation file (10-20% of your data, held out from training) and upload it the same way. This is optional but strongly recommended. OpenAI will evaluate the model against the validation set during training and report validation loss, which is the best indicator of whether your model is generalizing versus memorizing.
Step 3: Create and Monitor the Fine-Tuning Job
Create the fine-tuning job through the API or dashboard. Specify the base model (e.g., "gpt-4.1-nano-2025-04-14"), your training file ID, and optionally your validation file ID. You can also set hyperparameters: number of epochs (default is auto, which OpenAI determines based on dataset size), learning rate multiplier, and batch size.
For most projects, leave the hyperparameters on "auto." OpenAI's default settings are well-tuned for typical datasets. Only override if you have specific knowledge about what works for your data. If you do override: start with 3 epochs for datasets under 1,000 examples and 2 epochs for larger datasets. Learning rate multiplier of 1.0 (the default) works well in most cases.
Training time depends on dataset size and model. GPT-4.1 Nano fine-tunes on 1,000 examples in approximately 15-30 minutes. GPT-4.1 takes longer, typically 1-3 hours for the same dataset. You can monitor progress through the dashboard, which shows training and validation loss curves in real-time, or poll the API for status updates.
Watch the training loss curve. It should decrease steadily. If it flattens immediately, your data may be too similar to the base model's training data (meaning fine-tuning isn't learning much new). If it oscillates, the learning rate is too high. If validation loss increases while training loss decreases, you are overfitting and should reduce epochs.
Step 4: Evaluate and Deploy
When training completes, OpenAI provides a custom model ID (like "ft:gpt-4.1-nano-2025-04-14:org-name:custom-suffix:abc123"). Use this model ID in your API calls exactly where you would use a base model ID. There is no separate deployment step, the fine-tuned model is immediately available for inference.
Run your fine-tuned model against a held-out test set that was not in either the training or validation files. Compare outputs side-by-side with the base model. Key metrics to check: does the model follow your formatting consistently? Does it use domain terminology correctly? Does it handle edge cases better? Has general capability regressed?
For production deployment, the fine-tuned model is accessed through the same API with the custom model ID. Inference pricing for fine-tuned models is higher than the base model: typically 2-3x the base model's per-token price. For GPT-4.1 Nano, base input pricing is $0.10 per million tokens, and fine-tuned is approximately $0.20-0.30. This premium is offset by shorter prompts (you no longer need lengthy system instructions) and potentially lower quality-adjusted cost (the fine-tuned model may work where you previously needed a more expensive base model).
Monitor your fine-tuned model's performance over time. Unlike self-hosted models, OpenAI manages the infrastructure, so you don't need to worry about serving, but you should track output quality. Set up automated evaluation on a sample of production traffic and alert when quality metrics drop. When they do, collect the new failure cases, add them to your training data, and create a new fine-tuned version.
OpenAI Fine-Tuning Pricing (July 2026)
GPT-4.1 Nano: Training at $0.20/1M tokens. The cheapest option and sufficient for most straightforward tasks like classification, formatting, and simple domain adaptation. A 5,000-example dataset costs under $1 to train.
GPT-4.1 Mini: Training at approximately $0.80/1M tokens. Better reasoning than Nano, suitable for more complex tasks. Good middle ground between cost and quality.
GPT-4o: Training at $25/1M tokens. The most expensive option but highest quality for complex, nuanced tasks. A 5,000-example dataset costs approximately $62. Only choose this if Nano or Mini cannot meet your quality bar.
o4-mini: Training pricing varies. Designed for reasoning-heavy tasks where the model needs to think through problems step by step. Best for mathematical, logical, and code analysis tasks where chain-of-thought reasoning is essential.
When to Choose OpenAI vs Open Source
Choose OpenAI fine-tuning when: you want zero infrastructure management, your team has no ML engineering expertise, you need the fastest possible time to production (hours, not days), your dataset is small (under 5,000 examples), or you are already committed to the OpenAI ecosystem. The convenience premium is worth it when engineering time is more expensive than API costs.
Choose open-source fine-tuning when: you need full control over model weights, you want to self-host for data privacy or regulatory compliance, your inference volume makes per-token API pricing expensive, you want to switch providers without vendor lock-in, or you need to fine-tune models larger than what OpenAI offers for fine-tuning. Open-source fine-tuning costs less in compute but requires more engineering effort.
OpenAI fine-tuning is the fastest path from data to production model, with zero infrastructure required. Start with GPT-4.1 Nano for the best cost-to-quality ratio. Format your data as JSONL chat conversations, upload, train, and your custom model endpoint is ready for API calls within hours.