Skip to main content

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

string
required
The ID of an uploaded file that contains training data. The file must be formatted as JSONL.
string
required
The model to fine-tune (e.g., gpt-4o-mini-2024-07-18, gpt-3.5-turbo-0125)
string
The ID of an uploaded file containing validation data (optional)
object
Training hyperparameters
string
A string to append to the fine-tuned model name (max 40 characters)

Response

string
The fine-tuning job identifier
string
The object type, always “fine_tuning.job”
string
The base model being fine-tuned
integer
Unix timestamp of when the job was created
integer
Unix timestamp of when the job finished (null if in progress)
string
The name of the fine-tuned model (null until training completes)
string
Current status: created, running, succeeded, failed, or cancelled
string
The ID of the training file
string
The ID of the validation file (if provided)
object
The hyperparameters used for training

Example

Training Data Format

Prepare your training data as JSONL:

Response Example

List Fine-tuning Jobs

Returns a paginated list of fine-tuning jobs.

Retrieve Fine-tuning Job

Get details about a specific job, including current status and progress.

Cancel Fine-tuning Job

Cancel a job that is in progress. The job status will change to cancelled.

Using the Fine-tuned Model

Once training completes, use your fine-tuned model:

Best Practices

  • 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
  • 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
  • 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
  • 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
Check provider documentation for specific model availability.

Upload File

Upload training data

Chat Completions

Use your fine-tuned model

Provider Guide

Provider-specific details