Create fine-tuning job

POST /fine_tuning/jobs

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

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

Learn more about fine-tuning

application/json

Body Required

  • model string Required

    Any of:

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

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

    Values are babbage-002, davinci-002, or gpt-3.5-turbo.

  • training_file string Required

    The ID of an uploaded file that contains training data.

    See upload file for how to upload a file.

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

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

    See the fine-tuning guide for more details.

  • The hyperparameters used for the fine-tuning job.

    Hide hyperparameters attributes Show hyperparameters attributes object
    • batch_size string | integer

      One of:

      Number of examples in each batch. A larger batch size means that model parameters are updated less frequently, but with lower variance.

      Value is auto. Default value is auto.

      Number of examples in each batch. A larger batch size means that model parameters are updated less frequently, but with lower variance.

      Minimum value is 1, maximum value is 256. Default value is auto.

    • learning_rate_multiplier string | number

      One of:

      Scaling factor for the learning rate. A smaller learning rate may be useful to avoid overfitting.

      Value is auto. Default value is auto.

      Scaling factor for the learning rate. A smaller learning rate may be useful to avoid overfitting.

      Minimum value is 0. Default value is auto.

    • n_epochs string | integer

      One of:

      The number of epochs to train the model for. An epoch refers to one full cycle through the training dataset.

      Value is auto. Default value is auto.

      The number of epochs to train the model for. An epoch refers to one full cycle through the training dataset.

      Minimum value is 1, maximum value is 50. Default value is auto.

  • suffix string | null

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

    For example, a suffix of "custom-model-name" would produce a model name like ft:gpt-3.5-turbo:openai:custom-model-name:7p4lURel.

    Minimum length is 1, maximum length is 40.

  • validation_file string | null

    The ID of an uploaded file that contains validation data.

    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.

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

    See the fine-tuning guide for more details.

  • integrations array[object] | null

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

    Hide integrations attributes Show integrations attributes object
    • type string Required

      The type of integration to enable. Currently, only "wandb" (Weights and Biases) is supported.

      Value is wandb.

    • wandb object Required

      The settings for your integration with Weights and Biases. This payload specifies the project that metrics will be sent to. Optionally, you can set an explicit display name for your run, add tags to your run, and set a default entity (team, username, etc) to be associated with your run.

      Hide wandb attributes Show wandb attributes object
      • project string Required

        The name of the project that the new run will be created under.

      • name string | null

        A display name to set for the run. If not set, we will use the Job ID as the name.

      • entity string | null

        The entity to use for the run. This allows you to set the team or username of the WandB user that you would like associated with the run. If not set, the default entity for the registered WandB API key is used.

      • tags array[string]

        A list of tags to be attached to the newly created run. These tags are passed through directly to WandB. Some default tags are generated by OpenAI: "openai/finetune", "openai/{base-model}", "openai/{ftjob-abcdef}".

  • seed integer | null

    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.

    Minimum value is 0, maximum value is 2147483647.

Responses

  • 200 application/json

    OK

    Hide response attributes Show response attributes object
    • id string Required

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

    • created_at integer Required

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

    • error object | null Required

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

      Hide error attributes Show error attributes object | null
      • code string Required

        A machine-readable error code.

      • message string Required

        A human-readable error message.

      • param string | null Required

        The parameter that was invalid, usually training_file or validation_file. This field will be null if the failure was not parameter-specific.

    • fine_tuned_model string | null Required

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

    • finished_at integer | null Required

      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.

    • hyperparameters object Required

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

      Hide hyperparameters attribute Show hyperparameters attribute object
      • n_epochs string | integer Required

        One of:

        The number of epochs to train the model for. An epoch refers to one full cycle through the training dataset. "auto" decides the optimal number of epochs based on the size of the dataset. If setting the number manually, we support any number between 1 and 50 epochs.

        Value is auto. Default value is auto.

        The number of epochs to train the model for. An epoch refers to one full cycle through the training dataset. "auto" decides the optimal number of epochs based on the size of the dataset. If setting the number manually, we support any number between 1 and 50 epochs.

        Minimum value is 1, maximum value is 50. Default value is auto.

    • model string Required

      The base model that is being fine-tuned.

    • object string Required

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

      Value is fine_tuning.job.

    • organization_id string Required

      The organization that owns the fine-tuning job.

    • result_files array[string] Required

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

    • status string Required

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

      Values are validating_files, queued, running, succeeded, failed, or cancelled.

    • trained_tokens integer | null Required

      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.

    • training_file string Required

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

    • validation_file string | null Required

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

    • integrations array[object] | null

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

      Not more than 5 elements.

      Hide integrations attributes Show integrations attributes object
      • type string Required

        The type of the integration being enabled for the fine-tuning job

        Value is wandb.

      • wandb object Required

        The settings for your integration with Weights and Biases. This payload specifies the project that metrics will be sent to. Optionally, you can set an explicit display name for your run, add tags to your run, and set a default entity (team, username, etc) to be associated with your run.

        Hide wandb attributes Show wandb attributes object
        • project string Required

          The name of the project that the new run will be created under.

        • name string | null

          A display name to set for the run. If not set, we will use the Job ID as the name.

        • entity string | null

          The entity to use for the run. This allows you to set the team or username of the WandB user that you would like associated with the run. If not set, the default entity for the registered WandB API key is used.

        • tags array[string]

          A list of tags to be attached to the newly created run. These tags are passed through directly to WandB. Some default tags are generated by OpenAI: "openai/finetune", "openai/{base-model}", "openai/{ftjob-abcdef}".

    • seed integer Required

      The seed used for the fine-tuning job.

    • estimated_finish integer | null

      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.

POST /fine_tuning/jobs
curl \
 -X POST https://api.openai.com/v1/fine_tuning/jobs \
 -H "Authorization: Bearer $ACCESS_TOKEN" \
 -H "Content-Type: application/json" \
 -d '{"model":"gpt-3.5-turbo","training_file":"file-abc123","hyperparameters":{"batch_size":"auto","learning_rate_multiplier":"auto","n_epochs":"auto"},"suffix":"string","validation_file":"file-abc123","integrations":[{"type":"wandb","wandb":{"project":"my-wandb-project","name":"string","entity":"string","tags":["custom-tag"]}}],"seed":42}'
Request example
{
  "model": "gpt-3.5-turbo",
  "training_file": "file-abc123",
  "hyperparameters": {
    "batch_size": "auto",
    "learning_rate_multiplier": "auto",
    "n_epochs": "auto"
  },
  "suffix": "string",
  "validation_file": "file-abc123",
  "integrations": [
    {
      "type": "wandb",
      "wandb": {
        "project": "my-wandb-project",
        "name": "string",
        "entity": "string",
        "tags": [
          "custom-tag"
        ]
      }
    }
  ],
  "seed": 42
}
Response examples (200)
{
  "id": "string",
  "created_at": 42,
  "error": {
    "code": "string",
    "message": "string",
    "param": "string"
  },
  "fine_tuned_model": "string",
  "finished_at": 42,
  "hyperparameters": {
    "n_epochs": "auto"
  },
  "model": "string",
  "object": "fine_tuning.job",
  "organization_id": "string",
  "result_files": [
    "file-abc123"
  ],
  "status": "validating_files",
  "trained_tokens": 42,
  "training_file": "string",
  "validation_file": "string",
  "integrations": [
    {
      "type": "wandb",
      "wandb": {
        "project": "my-wandb-project",
        "name": "string",
        "entity": "string",
        "tags": [
          "custom-tag"
        ]
      }
    }
  ],
  "seed": 42,
  "estimated_finish": 42
}