Fine-tuning API
Fine-tune models on your own data to improve performance for your specific use case. The gateway supports fine-tuning endpoints for compatible providers.Endpoints
Create Fine-tuning Job
POST /v1/fine_tuning/jobs Create a fine-tuning job to train a model on your data.List Fine-tuning Jobs
GET /v1/fine_tuning/jobs List all fine-tuning jobs for your organization.Retrieve Fine-tuning Job
GET /v1/fine_tuning/jobs/:jobId Get details about a specific fine-tuning job.Cancel Fine-tuning Job
POST /v1/fine_tuning/jobs/:jobId/cancel Cancel a fine-tuning job that is in progress.Authentication
Requires provider authentication headers:Create Fine-tuning Job
Request Parameters
The ID of an uploaded file that contains training data. The file must be formatted as JSONL.
The model to fine-tune (e.g.,
gpt-4o-mini-2024-07-18, gpt-3.5-turbo-0125)The ID of an uploaded file containing validation data (optional)
Training hyperparameters
A string to append to the fine-tuned model name (max 40 characters)
Response
The fine-tuning job identifier
The object type, always “fine_tuning.job”
The base model being fine-tuned
Unix timestamp of when the job was created
Unix timestamp of when the job finished (null if in progress)
The name of the fine-tuned model (null until training completes)
Current status:
created, running, succeeded, failed, or cancelledThe ID of the training file
The ID of the validation file (if provided)
The hyperparameters used for training
Example
Training Data Format
Prepare your training data as JSONL:Response Example
List Fine-tuning Jobs
Retrieve Fine-tuning Job
Cancel Fine-tuning Job
cancelled.
Using the Fine-tuned Model
Once training completes, use your fine-tuned model:Best Practices
Training Data Quality
Training Data Quality
- Provide at least 50-100 high-quality examples
- Ensure examples are diverse and representative
- Follow the same format across all examples
- Include a system message if needed for your use case
Hyperparameter Tuning
Hyperparameter Tuning
- Start with default (auto) hyperparameters
- Monitor validation loss to detect overfitting
- Adjust n_epochs if the model isn’t learning enough or is overfitting
- Use validation data to evaluate performance
Cost Management
Cost Management
- Training costs are based on the number of tokens in your training data
- Start with a small dataset to validate your approach
- Fine-tuning is typically 10-20x the cost of inference
- Consider if prompt engineering can achieve similar results first
Model Versioning
Model Versioning
- Use the suffix parameter to create meaningful model names
- Keep track of which training data was used for each model
- Test new models thoroughly before replacing production models
Provider Support
Fine-tuning support varies by provider. Currently supported:
- OpenAI: GPT-4, GPT-3.5 Turbo
- Azure OpenAI: Same models as OpenAI
Related Resources
Upload File
Upload training data
Chat Completions
Use your fine-tuned model
Provider Guide
Provider-specific details