Fine-tuning

Manage fine-tuning jobs to tailor a model to your specific training data. Related guide: Fine-tune modelssource

Create fine-tuning job

post https://api.openai.com/v1/fine_tuning/jobs

Creates a fine-tuning job which begins the process of creating a new model from a given dataset.source

Response includes details of the enqueued job including job status and the name of the fine-tuned models once complete.source

Learn more about fine-tuningsource

Request body

The name of the model to fine-tune. You can select one of the supported models.source

The ID of an uploaded file that contains training data.source

See upload file for how to upload a file.source

Your dataset must be formatted as a JSONL file. Additionally, you must upload your file with the purpose fine-tune.source

The contents of the file should differ depending on if the model uses the chat or completions format.source

See the fine-tuning guide for more details.source

The hyperparameters used for the fine-tuning job.source

A string of up to 64 characters that will be added to your fine-tuned model name.source

For example, a suffix of "custom-model-name" would produce a model name like ft:gpt-4o-mini:openai:custom-model-name:7p4lURel.source

The ID of an uploaded file that contains validation data.source

If you provide this file, the data is used to generate validation metrics periodically during fine-tuning. These metrics can be viewed in the fine-tuning results file. The same data should not be present in both train and validation files.source

Your dataset must be formatted as a JSONL file. You must upload your file with the purpose fine-tune.source

See the fine-tuning guide for more details.source

A list of integrations to enable for your fine-tuning job.source

The seed controls the reproducibility of the job. Passing in the same seed and job parameters should produce the same results, but may differ in rare cases. If a seed is not specified, one will be generated for you.source

Returns

Example request
1
2
3
4
5
6
7
curl https://api.openai.com/v1/fine_tuning/jobs \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -d '{
    "training_file": "file-BK7bzQj3FfZFXr7DbL6xJwfo",
    "model": "gpt-4o-mini"
  }'
Response
1
2
3
4
5
6
7
8
9
10
11
12
{
  "object": "fine_tuning.job",
  "id": "ftjob-abc123",
  "model": "gpt-4o-mini-2024-07-18",
  "created_at": 1721764800,
  "fine_tuned_model": null,
  "organization_id": "org-123",
  "result_files": [],
  "status": "queued",
  "validation_file": null,
  "training_file": "file-abc123",
}

List fine-tuning jobs

get https://api.openai.com/v1/fine_tuning/jobs

List your organization's fine-tuning jobssource

Query parameters

Identifier for the last job from the previous pagination request.source

Number of fine-tuning jobs to retrieve.source

Returns

A list of paginated fine-tuning job objects.source

Example request
1
2
curl https://api.openai.com/v1/fine_tuning/jobs?limit=2 \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
  "object": "list",
  "data": [
    {
      "object": "fine_tuning.job.event",
      "id": "ft-event-TjX0lMfOniCZX64t9PUQT5hn",
      "created_at": 1689813489,
      "level": "warn",
      "message": "Fine tuning process stopping due to job cancellation",
      "data": null,
      "type": "message"
    },
    { ... },
    { ... }
  ], "has_more": true
}

List fine-tuning events

get https://api.openai.com/v1/fine_tuning/jobs/{fine_tuning_job_id}/events

Get status updates for a fine-tuning job.source

Path parameters

The ID of the fine-tuning job to get events for.source

Query parameters

Identifier for the last event from the previous pagination request.source

Number of events to retrieve.source

Returns

A list of fine-tuning event objects.source

Example request
1
2
curl https://api.openai.com/v1/fine_tuning/jobs/ftjob-abc123/events \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
  "object": "list",
  "data": [
    {
      "object": "fine_tuning.job.event",
      "id": "ft-event-ddTJfwuMVpfLXseO0Am0Gqjm",
      "created_at": 1721764800,
      "level": "info",
      "message": "Fine tuning job successfully completed",
      "data": null,
      "type": "message"
    },
    {
      "object": "fine_tuning.job.event",
      "id": "ft-event-tyiGuB72evQncpH87xe505Sv",
      "created_at": 1721764800,
      "level": "info",
      "message": "New fine-tuned model created: ft:gpt-4o-mini:openai::7p4lURel",
      "data": null,
      "type": "message"
    }
  ],
  "has_more": true
}

List fine-tuning checkpoints

get https://api.openai.com/v1/fine_tuning/jobs/{fine_tuning_job_id}/checkpoints

List checkpoints for a fine-tuning job.source

Path parameters

The ID of the fine-tuning job to get checkpoints for.source

Query parameters

Identifier for the last checkpoint ID from the previous pagination request.source

Number of checkpoints to retrieve.source

Returns

A list of fine-tuning checkpoint objects for a fine-tuning job.source

Example request
1
2
curl https://api.openai.com/v1/fine_tuning/jobs/ftjob-abc123/checkpoints \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
{
  "object": "list"
  "data": [
    {
      "object": "fine_tuning.job.checkpoint",
      "id": "ftckpt_zc4Q7MP6XxulcVzj4MZdwsAB",
      "created_at": 1721764867,
      "fine_tuned_model_checkpoint": "ft:gpt-4o-mini-2024-07-18:my-org:custom-suffix:96olL566:ckpt-step-2000",
      "metrics": {
        "full_valid_loss": 0.134,
        "full_valid_mean_token_accuracy": 0.874
      },
      "fine_tuning_job_id": "ftjob-abc123",
      "step_number": 2000,
    },
    {
      "object": "fine_tuning.job.checkpoint",
      "id": "ftckpt_enQCFmOTGj3syEpYVhBRLTSy",
      "created_at": 1721764800,
      "fine_tuned_model_checkpoint": "ft:gpt-4o-mini-2024-07-18:my-org:custom-suffix:7q8mpxmy:ckpt-step-1000",
      "metrics": {
        "full_valid_loss": 0.167,
        "full_valid_mean_token_accuracy": 0.781
      },
      "fine_tuning_job_id": "ftjob-abc123",
      "step_number": 1000,
    },
  ],
  "first_id": "ftckpt_zc4Q7MP6XxulcVzj4MZdwsAB",
  "last_id": "ftckpt_enQCFmOTGj3syEpYVhBRLTSy",
  "has_more": true
}

Retrieve fine-tuning job

get https://api.openai.com/v1/fine_tuning/jobs/{fine_tuning_job_id}

Get info about a fine-tuning job.source

Learn more about fine-tuningsource

Path parameters

The ID of the fine-tuning job.source

Returns

The fine-tuning object with the given ID.source

Example request
1
2
curl https://api.openai.com/v1/fine_tuning/jobs/ft-AF1WoRqd3aJAHsqc9NY7iL8F \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
  "object": "fine_tuning.job",
  "id": "ftjob-abc123",
  "model": "davinci-002",
  "created_at": 1692661014,
  "finished_at": 1692661190,
  "fine_tuned_model": "ft:davinci-002:my-org:custom_suffix:7q8mpxmy",
  "organization_id": "org-123",
  "result_files": [
      "file-abc123"
  ],
  "status": "succeeded",
  "validation_file": null,
  "training_file": "file-abc123",
  "hyperparameters": {
      "n_epochs": 4,
      "batch_size": 1,
      "learning_rate_multiplier": 1.0
  },
  "trained_tokens": 5768,
  "integrations": [],
  "seed": 0,
  "estimated_finish": 0
}

Cancel fine-tuning

post https://api.openai.com/v1/fine_tuning/jobs/{fine_tuning_job_id}/cancel

Immediately cancel a fine-tune job.source

Path parameters

The ID of the fine-tuning job to cancel.source

Returns

The cancelled fine-tuning object.source

Example request
1
2
curl -X POST https://api.openai.com/v1/fine_tuning/jobs/ftjob-abc123/cancel \
  -H "Authorization: Bearer $OPENAI_API_KEY"
Response
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
  "object": "fine_tuning.job",
  "id": "ftjob-abc123",
  "model": "gpt-4o-mini-2024-07-18",
  "created_at": 1721764800,
  "fine_tuned_model": null,
  "organization_id": "org-123",
  "result_files": [],
  "hyperparameters": {
    "n_epochs":  "auto"
  },
  "status": "cancelled",
  "validation_file": "file-abc123",
  "training_file": "file-abc123"
}

Training format for chat models

The per-line training example of a fine-tuning input file for chat modelssource

A list of tools the model may generate JSON inputs for.source

Whether to enable parallel function calling during tool use.source

A list of functions the model may generate JSON inputs for.source

OBJECT Training format for chat models
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
{
  "messages": [
    { "role": "user", "content": "What is the weather in San Francisco?" },
    {
      "role": "assistant",
      "tool_calls": [
        {
          "id": "call_id",
          "type": "function",
          "function": {
            "name": "get_current_weather",
            "arguments": "{\"location\": \"San Francisco, USA\", \"format\": \"celsius\"}"
          }
        }
      ]
    }
  ],
  "parallel_tool_calls": false,
  "tools": [
    {
      "type": "function",
      "function": {
        "name": "get_current_weather",
        "description": "Get the current weather",
        "parameters": {
          "type": "object",
          "properties": {
            "location": {
                "type": "string",
                "description": "The city and country, eg. San Francisco, USA"
            },
            "format": { "type": "string", "enum": ["celsius", "fahrenheit"] }
          },
          "required": ["location", "format"]
        }
      }
    }
  ]
}

Training format for completions models

The per-line training example of a fine-tuning input file for completions modelssource

The input prompt for this training example.source

The desired completion for this training example.source

OBJECT Training format for completions models
1
2
3
4
{
  "prompt": "What is the answer to 2+2",
  "completion": "4"
}

The fine-tuning job object

The fine_tuning.job object represents a fine-tuning job that has been created through the API.source

The object identifier, which can be referenced in the API endpoints.source

The Unix timestamp (in seconds) for when the fine-tuning job was created.source

For fine-tuning jobs that have failed, this will contain more information on the cause of the failure.source

The name of the fine-tuned model that is being created. The value will be null if the fine-tuning job is still running.source

The Unix timestamp (in seconds) for when the fine-tuning job was finished. The value will be null if the fine-tuning job is still running.source

The hyperparameters used for the fine-tuning job. See the fine-tuning guide for more details.source

The base model that is being fine-tuned.source

The object type, which is always "fine_tuning.job".source

The organization that owns the fine-tuning job.source

The compiled results file ID(s) for the fine-tuning job. You can retrieve the results with the Files API.source

The current status of the fine-tuning job, which can be either validating_files, queued, running, succeeded, failed, or cancelled.source

The total number of billable tokens processed by this fine-tuning job. The value will be null if the fine-tuning job is still running.source

The file ID used for training. You can retrieve the training data with the Files API.source

The file ID used for validation. You can retrieve the validation results with the Files API.source

A list of integrations to enable for this fine-tuning job.source

The seed used for the fine-tuning job.source

The Unix timestamp (in seconds) for when the fine-tuning job is estimated to finish. The value will be null if the fine-tuning job is not running.source

OBJECT The fine-tuning job object
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
{
  "object": "fine_tuning.job",
  "id": "ftjob-abc123",
  "model": "davinci-002",
  "created_at": 1692661014,
  "finished_at": 1692661190,
  "fine_tuned_model": "ft:davinci-002:my-org:custom_suffix:7q8mpxmy",
  "organization_id": "org-123",
  "result_files": [
      "file-abc123"
  ],
  "status": "succeeded",
  "validation_file": null,
  "training_file": "file-abc123",
  "hyperparameters": {
      "n_epochs": 4,
      "batch_size": 1,
      "learning_rate_multiplier": 1.0
  },
  "trained_tokens": 5768,
  "integrations": [],
  "seed": 0,
  "estimated_finish": 0
}

The fine-tuning job event object

Fine-tuning job event objectsource

OBJECT The fine-tuning job event object
1
2
3
4
5
6
7
{
  "object": "fine_tuning.job.event",
  "id": "ftevent-abc123"
  "created_at": 1677610602,
  "level": "info",
  "message": "Created fine-tuning job"
}

The fine-tuning job checkpoint object

The fine_tuning.job.checkpoint object represents a model checkpoint for a fine-tuning job that is ready to use.source

The checkpoint identifier, which can be referenced in the API endpoints.source

The Unix timestamp (in seconds) for when the checkpoint was created.source

The name of the fine-tuned checkpoint model that is created.source

The step number that the checkpoint was created at.source

Metrics at the step number during the fine-tuning job.source

The name of the fine-tuning job that this checkpoint was created from.source

The object type, which is always "fine_tuning.job.checkpoint".source

OBJECT The fine-tuning job checkpoint object
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
{
  "object": "fine_tuning.job.checkpoint",
  "id": "ftckpt_qtZ5Gyk4BLq1SfLFWp3RtO3P",
  "created_at": 1712211699,
  "fine_tuned_model_checkpoint": "ft:gpt-4o-mini-2024-07-18:my-org:custom_suffix:9ABel2dg:ckpt-step-88",
  "fine_tuning_job_id": "ftjob-fpbNQ3H1GrMehXRf8cO97xTN",
  "metrics": {
    "step": 88,
    "train_loss": 0.478,
    "train_mean_token_accuracy": 0.924,
    "valid_loss": 10.112,
    "valid_mean_token_accuracy": 0.145,
    "full_valid_loss": 0.567,
    "full_valid_mean_token_accuracy": 0.944
  },
  "step_number": 88
}