Fine-tuning lets you specialize an OpenAI model for a particular task by continuing its training on your own curated dataset. Rather than relying solely on prompts to steer model behavior, fine-tuning bakes your requirements directly into the model weights — enabling more consistent outputs, shorter prompts, and better performance on domain-specific tasks. This guide covers when to fine-tune, how to prepare your data, and how to run and monitor a fine-tuning job from start to finish.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/openai/openai-cookbook/llms.txt
Use this file to discover all available pages before exploring further.
When to fine-tune
Before investing in fine-tuning, it is worth evaluating whether prompt engineering alone can meet your needs. Fine-tuning is most valuable in the following scenarios:Consistent style or format
When your application requires responses to follow a specific tone, structure, or schema — and prompting alone produces inconsistent results.
Shorter prompts
When you want to reduce token usage and latency by embedding complex instructions into the model itself rather than repeating them in every request.
Domain specialization
When the model needs to perform reliably in a specialized domain — such as legal, medical, or financial text — using terminology and conventions specific to that field.
Improved instruction following
When the base model struggles to follow complex multi-step instructions, fine-tuning on high-quality examples can improve reliability substantially.
Fine-tuning is not a substitute for retrieval. If your use case requires the model to access up-to-date or proprietary knowledge, consider retrieval-augmented generation (RAG) alongside or instead of fine-tuning.
Fine-tuning methods
OpenAI’s platform supports several fine-tuning methods. The two most commonly used for chat models are supervised fine-tuning (SFT) and direct preference optimization (DPO).Supervised fine-tuning (SFT)
Supervised fine-tuning (SFT)
SFT is the standard approach. You provide input-output pairs — a conversation that ends with an ideal assistant response — and the model is trained to reproduce those outputs. This technique works well for:
- Teaching a specific response format (JSON, Markdown, structured reports)
- Adjusting tone or persona
- Distilling a larger model’s expertise into a smaller, faster model
- Correcting instruction-following failures
Direct preference optimization (DPO)
Direct preference optimization (DPO)
DPO uses pairwise comparisons — a preferred response and a rejected response for the same prompt — to teach the model which outputs are better. It is a lightweight alternative to reinforcement learning from human feedback (RLHF) that does not require a separate reward model.DPO is best suited for:
- Aligning outputs with human preferences (tone, politeness, helpfulness)
- Refining an already-capable model using human-rated feedback
- Achieving nuanced behavioral alignment that is difficult to express as exact output labels
Preparing your training data
Fine-tuning for chat models uses the JSONL format. Each line is a separate JSON object representing one training example. A training example is a full conversation including a system message, one or more user turns, and the desired assistant response.- Include at least one
usermessage and oneassistantmessage - End with an
assistantturn (the target output the model learns to produce) - Use the
system,user, andassistantrole values
Validating your data
Before uploading, check your dataset for format errors, token length distribution, and per-message role consistency. The Chat fine-tuning data preparation cookbook provides a validation script that checks error counts, estimates training cost, and surfaces common issues.Running a fine-tuning job
Upload your training file
Upload your JSONL file to the Files API with
purpose="fine-tune". The returned file ID is used when creating the job.Monitor your job
Jobs can take anywhere from a few minutes to several hours depending on dataset size. Poll the job status or list events to track progress:The job transitions through
validating_files → queued → running → succeeded (or failed).Hyperparameters
OpenAI exposes a small set of hyperparameters that you can tune to influence training. In most cases the defaults work well, but adjusting them can help if your loss curve shows over- or underfitting.| Hyperparameter | Default | Notes |
|---|---|---|
n_epochs | Auto | Number of passes over the training data. A value of 3–5 is a common starting point. |
batch_size | Auto | Controls how many examples are processed per gradient update. Larger batches stabilize training but require more memory. |
learning_rate_multiplier | Auto | Scales the learning rate. If the model overfits, try reducing this. |
Adding a validation file
To catch overfitting, provide a separate held-out validation set. The API computes validation loss at the end of each epoch and surfaces it in the training events.Using DPO
For DPO, each training example must contain aprompt and both a chosen and rejected completion. The format differs slightly from SFT:
"dpo" as the method when creating the job:
beta parameter controls how strongly the model is pulled toward the preferred response. Higher values enforce preferences more aggressively; lower values allow more deviation from the base model.
Next steps
Evaluation
Measure your fine-tuned model’s quality using LLM-as-a-judge, rule-based evals, and the Evals API.
Reinforcement fine-tuning
For tasks with verifiable outputs, RFT uses reward signals to push reasoning capabilities beyond what labeled data alone can achieve.