This document describes how to tune a Gemini model by using supervised
fine-tuning.

## Before you begin

Before you begin, you must prepare a supervised fine-tuning dataset. Depending
on your use case, there are different requirements for preparing a dataset:

- [Text tuning](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/tuning/text.md.txt)
- [Image tuning](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/tuning/image.md.txt)
- [Document tuning](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/tuning/document.md.txt)
- [Audio tuning](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/tuning/audio.md.txt)
- [Video tuning](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/tuning/video.md.txt)
- [Tune function calling](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/tuning/function-calling.md.txt)

> [!NOTE]
> To see an example of using the Google Gen AI SDK for Python to tune the text generation foundation model,
> run the "Supervised fine-tuning with Gemini for article summarization" notebook in one of the following
> environments:
>
> [![](https://docs.cloud.google.com/static/vertex-ai/images/colab-logo-32px.png)Open in Colab](https://colab.research.google.com/github/GoogleCloudPlatform/generative-ai/blob/main/gemini/tuning/sft_gemini_summarization.ipynb)
>
>
> \|
>
> [![](https://docs.cloud.google.com/static/vertex-ai/images/colab-enterprise-logo-32px.png)Open in Colab Enterprise](https://console.cloud.google.com/agent-platform/colab/import/https%3A%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fgenerative-ai%2Fmain%2Fgemini%2Ftuning%2Fsft_gemini_summarization.ipynb)
>
>
> \|
>
> [![](https://docs.cloud.google.com/static/vertex-ai/images/vertex-ai-workbench-logo-32px.png)Open
> in Agent Platform Workbench](https://console.cloud.google.com/agent-platform/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/generative-ai/main/gemini/tuning/sft_gemini_summarization.ipynb)
>
>
> \|
>
> [![](https://docs.cloud.google.com/static/vertex-ai/images/github-logo-32px.png)View on GitHub](https://github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/tuning/sft_gemini_summarization.ipynb)

> [!NOTE]
> To see an example of Supervised Fine-Tuning with integrated Gen AI evaluation service,
> run the "Supervised Fine-Tuning with integrated Gen AI Evaluation" notebook in one of the following
> environments:
>
> [![](https://docs.cloud.google.com/static/vertex-ai/images/colab-logo-32px.png)Open in Colab](https://colab.research.google.com/github/GoogleCloudPlatform/generative-ai/blob/main/gemini/tuning/sft_gemini_automatic_evaluation.ipynb)
>
>
> \|
>
> [![](https://docs.cloud.google.com/static/vertex-ai/images/colab-enterprise-logo-32px.png)Open in Colab Enterprise](https://console.cloud.google.com/agent-platform/colab/import/https%3A%2F%2Fraw.githubusercontent.com%2FGoogleCloudPlatform%2Fgenerative-ai%2Fmain%2Fgemini%2Ftuning%2Fsft_gemini_automatic_evaluation.ipynb)
>
>
> \|
>
> [![](https://docs.cloud.google.com/static/vertex-ai/images/vertex-ai-workbench-logo-32px.png)Open
> in Agent Platform Workbench](https://console.cloud.google.com/agent-platform/workbench/deploy-notebook?download_url=https://raw.githubusercontent.com/GoogleCloudPlatform/generative-ai/main/gemini/tuning/sft_gemini_automatic_evaluation.ipynb)
>
>
> \|
>
> [![](https://docs.cloud.google.com/static/vertex-ai/images/github-logo-32px.png)View on GitHub](https://github.com/GoogleCloudPlatform/generative-ai/blob/main/gemini/tuning/sft_gemini_automatic_evaluation.ipynb)

## Supported models

The following Gemini models support supervised tuning:

#### Click to expand supported models

- [Gemini 3.5 Flash-Lite](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/gemini/3-5-flash-lite.md.txt)
- [Gemini 3.5 Flash](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/gemini/3-5-flash.md.txt)
- [Gemini 3.1 Flash-Lite](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/gemini/3-1-flash-lite.md.txt)
- [Gemini 2.5 Pro](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/gemini/2-5-pro.md.txt)
- [Gemini 2.5 Flash-Lite](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/gemini/2-5-flash-lite.md.txt)
- [Gemini 2.5 Flash](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/gemini/2-5-flash.md.txt)

## Create a tuning job

You can create a supervised fine-tuning job by using the Google Cloud console, the
Google Gen AI SDK, the REST API, or
Colab Enterprise.

Optional: (Preview) For Gemini 2.5 and earlier models, include the
`evaluationConfig` to automatically [run an
evaluation](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/run-evaluation) using the Gen AI evaluation service
after the tuning job completes. This evaluation configuration is available in
the `us-central1` region.

### Console

> [!NOTE]
> **Note:** Creating a supervised fine-tuning job using the console is only available for Gemini 2.5 and earlier models.

To tune a text model with supervised fine-tuning by using the
Google Cloud console, perform the following steps:

1. In the Gemini Enterprise Agent Platform section of the Google Cloud console, go to the **Agent Studio** page.

   [Go to
   **Agent Studio**](https://console.cloud.google.com/agent-platform/generative/language/tuning)
2. Click **Create tuned model**.
3. Under **Model details** , configure the following:
   1. In the **Tuned model name** field, enter a name for your new tuned model, up to 128 characters.
   2. In the **Base model** field, select the foundation model to tune.
   3. In the **Region** drop-down field, select the region where the pipeline tuning job runs and where the tuned model is deployed.
4. Under **Tuning setting** , configure the following:
   1. In the **Number of epochs** field, enter the number of steps to run for model tuning.
   2. In the **Adapter Size** field, enter the adapter size to use for model tuning.
   3. In the **Learning rate multiplier** field, enter the step size at each iteration. The default value is 1. .
5. Optional: To disable intermediate checkpoints and use only the latest checkpoint, click the **Export last checkpoint only** toggle.
6. Click **Continue** .

   The **Tuning dataset** page opens.
7. To upload a dataset file, select one of the following:
   1. If you haven't uploaded a dataset yet, select the radio button for **Upload file to Cloud Storage** .
      1. In the **Select JSONL file** field, click **Browse** and select your dataset file.
      2. In the **Dataset location** field, click **Browse** and select the Cloud Storage bucket where you want to store your dataset file.
   2. If your dataset file is already in a Cloud Storage bucket, select the radio button for **Existing file on Cloud Storage** .
      1. In **Cloud Storage file path** field, click **Browse** and select the Cloud Storage bucket where your dataset file is located.
8. (Optional) To get validation metrics during training, click the **Enable model validation** toggle.
   1. In the **Validation dataset** file, enter the Cloud Storage path of your validation dataset.
9. Click **Start Tuning** .

   Your new model appears under the **Tuned Models** section
   on the **Tune and Distill page** . When the model is finished tuning, the
   **Status** says **Succeeded**.

### Python

Install the Google Gen AI SDK:

```
pip install --upgrade google-genai
```

To learn more, see the [SDK reference documentation](https://googleapis.github.io/python-genai/).

Set environment variables to use the Google Gen AI SDK with
Gemini Enterprise Agent Platform:

```
# Replace PROJECT_ID with your project ID, and set GOOGLE_CLOUD_LOCATION to
# the region where the tuning job runs.
export GOOGLE_CLOUD_PROJECT=PROJECT_ID
export GOOGLE_CLOUD_LOCATION=us # Use us-central1 for Gemini 2.5 and earlier models
export GOOGLE_GENAI_USE_ENTERPRISE=True
```

Create the tuning job:

    import time

    from google import genai
    from google.genai.types import (
        CreateTuningJobConfig,
        EvaluationConfig,
        GcsDestination,
        HttpOptions,
        Metric,
        OutputConfig,
        TuningDataset,
    )

    # TODO(developer): Update and un-comment below line
    # output_gcs_uri = "gs://your-bucket/your-prefix"

    client = genai.Client(http_options=HttpOptions(api_version="v1beta1"))

    training_dataset = TuningDataset(
        gcs_uri="gs://cloud-samples-data/ai-platform/generative_ai/gemini/text/sft_train_data.jsonl",
    )
    validation_dataset = TuningDataset(
        gcs_uri="gs://cloud-samples-data/ai-platform/generative_ai/gemini/text/sft_validation_data.jsonl",
    )

    evaluation_config = EvaluationConfig(
        metrics=[
            Metric(
                name="FLUENCY",
                prompt_template="""Evaluate this {prediction}"""
            )
        ],
        output_config=OutputConfig(
            gcs_destination=GcsDestination(
                output_uri_prefix=output_gcs_uri,
            )
        ),
    )

    tuning_job = client.tunings.tune(
        base_model="gemini-3.5-flash",
        training_dataset=training_dataset,
        config=CreateTuningJobConfig(
            tuned_model_display_name="Example tuning job",
            validation_dataset=validation_dataset,
            evaluation_config=evaluation_config,
        ),
    )

    running_states = set([
        "JOB_STATE_PENDING",
        "JOB_STATE_RUNNING",
    ])

    while tuning_job.state in running_states:
        print(tuning_job.state)
        tuning_job = client.tunings.get(name=tuning_job.name)
        time.sleep(60)

    print(tuning_job.tuned_model.model)
    print(tuning_job.tuned_model.endpoint)
    print(tuning_job.experiment)
    # Example response:
    # projects/123456789012/locations/us-central1/models/1234567890@1
    # projects/123456789012/locations/us-central1/endpoints/123456789012345
    # projects/123456789012/locations/us-central1/metadataStores/default/contexts/tuning-experiment-2025010112345678

    if tuning_job.tuned_model.checkpoints:
        for i, checkpoint in enumerate(tuning_job.tuned_model.checkpoints):
            print(f"Checkpoint {i + 1}: ", checkpoint)
        # Example response:
        # Checkpoint 1:  checkpoint_id='1' epoch=1 step=10 endpoint='projects/123456789012/locations/us-central1/endpoints/123456789000000'
        # Checkpoint 2:  checkpoint_id='2' epoch=2 step=20 endpoint='projects/123456789012/locations/us-central1/endpoints/123456789012345'

### REST

To create a model tuning job, send a POST request by using the [`tuningJobs.create`](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/rest/v1/projects.locations.tuningJobs/create.md.txt)
method. Some of the parameters are not supported by all of the models. Ensure
that you include only the applicable parameters for the model that you're
tuning.


Before using any of the request data,
make the following replacements:

- <var class="edit" scope="PROJECT_ID" translate="no">PROJECT_ID</var>: Your [project ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifiers).
- <var class="edit" scope="TUNING_JOB_REGION" translate="no">TUNING_JOB_REGION</var>: The [region](https://docs.cloud.google.com/gemini-enterprise-agent-platform/resources/locations.md.txt) where the tuning job runs. This is also the default region for where the tuned model is uploaded. For Gemini 3 and later models, use the `us` or `eu` multi-region endpoint.
- <var class="edit" scope="BASE_MODEL" translate="no">BASE_MODEL</var>: Name of the foundation model to tune.
- <var class="edit" scope="TRAINING_DATASET_URI" translate="no">TRAINING_DATASET_URI</var>: Cloud Storage URI of your training dataset. The dataset must be formatted as a JSONL file. For best results, provide at least 100 to 500 examples. For more information, see [About supervised tuning datasets](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/tuning/supervised-tuning/prepare-data.md.txt).
- <var class="edit" scope="VALIDATION_DATASET_URI" translate="no">VALIDATION_DATASET_URI</var> Optional: The Cloud Storage URI of your validation dataset file.
- <var class="edit" scope="EPOCH_COUNT" translate="no">EPOCH_COUNT</var> Optional: The number of complete passes the model makes over the entire training dataset during training. Leave it unset to use the [pre-populated recommended value](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/models/tuning.md.txt#supervisedtuningspec).
- <var class="edit" scope="ADAPTER_SIZE" translate="no">ADAPTER_SIZE</var> Optional: The [Adapter size](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/models/tuning.md.txt#adaptersize) to use for the tuning job. The adapter size influences the number of trainable parameters for the tuning job. A larger adapter size implies that the model can learn more complex tasks, but it requires a larger training dataset and longer training times.
- <var class="edit" scope="LEARNING_RATE_MULTIPLIER" translate="no">LEARNING_RATE_MULTIPLIER</var> Optional: A multiplier to apply to the recommended learning rate. Leave it unset to use the [recommended value](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/models/tuning.md.txt#supervisedtuningspec).
- <var class="edit" scope="EXPORT_LAST_CHECKPOINT_ONLY" translate="no">EXPORT_LAST_CHECKPOINT_ONLY</var> Optional: Set to `true` to use only the latest checkpoint.
- <var class="edit" scope="TUNED_MODEL_DISPLAYNAME" translate="no">TUNED_MODEL_DISPLAYNAME</var> Optional: A display name for the tuned model. If not set, a random name is generated.
- <var class="edit" scope="KMS_KEY_NAME" translate="no">KMS_KEY_NAME</var> Optional: The Cloud Key Management Service resource identifier of the customer-managed encryption key used to protect a resource. The key has the format: `projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key`. The key needs to be in the same region as where the compute resource is created. For more information, see [Customer-managed encryption keys (CMEK)](https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/general/cmek.md.txt).
- <var class="edit" scope="SERVICE_ACCOUNT" translate="no">SERVICE_ACCOUNT</var> Optional: The service account that the tuningJob workload runs as. If not specified, the Agent Platform Secure Fine-Tuning Service Agent in the project is used. See [Tuning Service Agent](https://cloud.google.com/iam/docs/service-agents#vertex-ai-secure-fine-tuning-service-account). If you plan to use a customer-managed Service Account, you must grant the `roles/aiplatform.tuningServiceAgent` role to the service account. Also grant the [Tuning Service Agent](https://cloud.google.com/iam/docs/service-agents#vertex-ai-secure-fine-tuning-service-account) `roles/iam.serviceAccountTokenCreator` role to the customer-managed Service Account.


HTTP method and URL:

```
POST https://aiplatform.TUNING_JOB_REGION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs
```


Request JSON body:

```
{
  "baseModel": "BASE_MODEL",
  "supervisedTuningSpec" : {
      "trainingDatasetUri": "TRAINING_DATASET_URI",
      "validationDatasetUri": "VALIDATION_DATASET_URI",
      "hyperParameters": {
          "epochCount": EPOCH_COUNT,
          "adapterSize": "ADAPTER_SIZE",
          "learningRateMultiplier": LEARNING_RATE_MULTIPLIER
      },
      "exportLastCheckpointOnly": EXPORT_LAST_CHECKPOINT_ONLY
  },
  "tunedModelDisplayName": "TUNED_MODEL_DISPLAYNAME",
  "encryptionSpec": {
    "kmsKeyName": "KMS_KEY_NAME"
  },
  "serviceAccount": "SERVICE_ACCOUNT"
}
```

To send your request, choose one of these options:

#### curl

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://aiplatform.TUNING_JOB_REGION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs"
```

#### PowerShell

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://aiplatform.TUNING_JOB_REGION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following.

#### Response

```
{
  "name": "projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs/TUNING_JOB_ID",
  "createTime": "CREATE_TIME",
  "updateTime": "UPDATE_TIME",
  "state": "STATE",
  "supervisedTuningSpec": {
        "trainingDatasetUri": "TRAINING_DATASET_URI",
        "validationDatasetUri": "VALIDATION_DATASET_URI",
        "hyperParameters": {
            "epochCount": EPOCH_COUNT,
            "adapterSize": "ADAPTER_SIZE",
            "learningRateMultiplier": LEARNING_RATE_MULTIPLIER
        }
    },
  "tunedModelDisplayName": "TUNED_MODEL_DISPLAYNAME",
  "encryptionSpec": {
    "kmsKeyName": "KMS_KEY_NAME"
  },
  "serviceAccount": "SERVICE_ACCOUNT"
}
```

#### Example curl command

```
PROJECT_ID=PROJECT_ID
LOCATION=us
curl \
-X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
"https://aiplatform.${LOCATION}.rep.googleapis.com/v1/projects/${PROJECT_ID}/locations/${LOCATION}/tuningJobs" \
-d \
$'{
   "baseModel": "gemini-3.5-flash",
   "supervisedTuningSpec" : {
      "trainingDatasetUri": "TRAINING_DATASET_URI",
      "validationDatasetUri": "VALIDATION_DATASET_URI"
   },
   "tunedModelDisplayName": "tuned_gemini"
}'
```

### REST

To create a model tuning job, send a POST request by using the [`tuningJobs.create`](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/rest/v1/projects.locations.tuningJobs/create.md.txt)
method. Some of the parameters are not supported by all of the models. Ensure
that you include only the applicable parameters for the model that you're
tuning.


Before using any of the request data,
make the following replacements:

- <var class="edit" scope="PROJECT_ID" translate="no">PROJECT_ID</var>: Your [project ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifiers).
- <var class="edit" scope="TUNING_JOB_REGION" translate="no">TUNING_JOB_REGION</var>: The [region](https://docs.cloud.google.com/gemini-enterprise-agent-platform/resources/locations.md.txt) where the tuning job runs. This is also the default region for where the tuned model is uploaded. Multi-region endpoints aren't supported for Gemini 2.5 and earlier models. Use a regional endpoint, such as `us-central1`.
- <var class="edit" scope="BASE_MODEL" translate="no">BASE_MODEL</var>: Name of the foundation model to tune.
- <var class="edit" scope="TRAINING_DATASET_URI" translate="no">TRAINING_DATASET_URI</var>: Cloud Storage URI of your training dataset. The dataset must be formatted as a JSONL file. For best results, provide at least 100 to 500 examples. For more information, see [About supervised tuning datasets](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/tuning/supervised-tuning/prepare-data.md.txt).
- <var class="edit" scope="VALIDATION_DATASET_URI" translate="no">VALIDATION_DATASET_URI</var> Optional: The Cloud Storage URI of your validation dataset file.
- <var class="edit" scope="EPOCH_COUNT" translate="no">EPOCH_COUNT</var> Optional: The number of complete passes the model makes over the entire training dataset during training. Leave it unset to use the [pre-populated recommended value](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/models/tuning.md.txt#supervisedtuningspec).
- <var class="edit" scope="ADAPTER_SIZE" translate="no">ADAPTER_SIZE</var> Optional: The [Adapter size](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/models/tuning.md.txt#adaptersize) to use for the tuning job. The adapter size influences the number of trainable parameters for the tuning job. A larger adapter size implies that the model can learn more complex tasks, but it requires a larger training dataset and longer training times.
- <var class="edit" scope="LEARNING_RATE_MULTIPLIER" translate="no">LEARNING_RATE_MULTIPLIER</var> Optional: A multiplier to apply to the recommended learning rate. Leave it unset to use the [recommended value](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/models/tuning.md.txt#supervisedtuningspec).
- <var class="edit" scope="EXPORT_LAST_CHECKPOINT_ONLY" translate="no">EXPORT_LAST_CHECKPOINT_ONLY</var> Optional: Set to `true` to use only the latest checkpoint.
- <var class="edit" scope="METRIC_SPEC" translate="no">METRIC_SPEC</var> Optional: One or more [metric specs](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/models/evaluation.md.txt) you are using to run an evaluation using the Gen AI evaluation service. You can use the following metric specs: `pointwiseMetricSpec`, `pairwiseMetricSpec`, `exactMatchSpec`, `bleuSpec`, and `rougeSpec`.
- <var class="edit" scope="METRIC_SPEC_FIELD_NAME" translate="no">METRIC_SPEC_FIELD_NAME</var> Optional: The required fields for your chosen metric spec. For example, `metricPromptTemplate`
- <var class="edit" scope="METRIC_SPEC_FIELD_CONTENT" translate="no">METRIC_SPEC_FIELD_CONTENT</var> Optional: The field content for your chosen metric spec. For example, you can use the following field content for a pointwise evaluation: `"Evaluate the fluency of this sentence: {response}. Give score from 0 to
  1. 0 - not fluent at all. 1 - very fluent."`
- <var class="edit" scope="CLOUD_STORAGE_BUCKET" translate="no">CLOUD_STORAGE_BUCKET</var> Optional: The Cloud Storage bucket to store the results of an evaluation run by the Gen AI evaluation service.
- <var class="edit" scope="TUNED_MODEL_DISPLAYNAME" translate="no">TUNED_MODEL_DISPLAYNAME</var> Optional: A display name for the tuned model. If not set, a random name is generated.
- <var class="edit" scope="KMS_KEY_NAME" translate="no">KMS_KEY_NAME</var> Optional: The Cloud Key Management Service resource identifier of the customer-managed encryption key used to protect a resource. The key has the format: `projects/my-project/locations/my-region/keyRings/my-kr/cryptoKeys/my-key`. The key needs to be in the same region as where the compute resource is created. For more information, see [Customer-managed encryption keys (CMEK)](https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/general/cmek.md.txt).
- <var class="edit" scope="SERVICE_ACCOUNT" translate="no">SERVICE_ACCOUNT</var> Optional: The service account that the tuningJob workload runs as. If not specified, the Agent Platform Secure Fine-Tuning Service Agent in the project is used. See [Tuning Service Agent](https://cloud.google.com/iam/docs/service-agents#vertex-ai-secure-fine-tuning-service-account). If you plan to use a customer-managed Service Account, you must grant the `roles/aiplatform.tuningServiceAgent` role to the service account. Also grant the [Tuning Service Agent](https://cloud.google.com/iam/docs/service-agents#vertex-ai-secure-fine-tuning-service-account) `roles/iam.serviceAccountTokenCreator` role to the customer-managed Service Account.


HTTP method and URL:

```
POST https://TUNING_JOB_REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs
```


Request JSON body:

```
{
  "baseModel": "BASE_MODEL",
  "supervisedTuningSpec" : {
      "trainingDatasetUri": "TRAINING_DATASET_URI",
      "validationDatasetUri": "VALIDATION_DATASET_URI",
      "hyperParameters": {
          "epochCount": EPOCH_COUNT,
          "adapterSize": "ADAPTER_SIZE",
          "learningRateMultiplier": LEARNING_RATE_MULTIPLIER
      },
      "exportLastCheckpointOnly": EXPORT_LAST_CHECKPOINT_ONLY,
      "evaluationConfig": {
          "metrics": [
              {
                  "aggregationMetrics": ["AVERAGE", "STANDARD_DEVIATION"],
                  "METRIC_SPEC": {
                      "METRIC_SPEC_FIELD_NAME":
                          METRIC_SPEC_FIELD_CONTENT
                  }
              }
          ],
          "outputConfig": {
              "gcsDestination": {
                  "outputUriPrefix": "CLOUD_STORAGE_BUCKET"
              }
          }
      }
  },
  "tunedModelDisplayName": "TUNED_MODEL_DISPLAYNAME",
  "encryptionSpec": {
    "kmsKeyName": "KMS_KEY_NAME"
  },
  "serviceAccount": "SERVICE_ACCOUNT"
}
```

To send your request, choose one of these options:

#### curl

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://TUNING_JOB_REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs"
```

#### PowerShell

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://TUNING_JOB_REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following.

#### Response

```
{
  "name": "projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs/TUNING_JOB_ID",
  "createTime": "CREATE_TIME",
  "updateTime": "UPDATE_TIME",
  "state": "STATE",
  "supervisedTuningSpec": {
        "trainingDatasetUri": "TRAINING_DATASET_URI",
        "validationDatasetUri": "VALIDATION_DATASET_URI",
        "hyperParameters": {
            "epochCount": EPOCH_COUNT,
            "adapterSize": "ADAPTER_SIZE",
            "learningRateMultiplier": LEARNING_RATE_MULTIPLIER
        }
    },
  "tunedModelDisplayName": "TUNED_MODEL_DISPLAYNAME",
  "encryptionSpec": {
    "kmsKeyName": "KMS_KEY_NAME"
  },
  "serviceAccount": "SERVICE_ACCOUNT"
}
```

#### Example curl command

```
PROJECT_ID=PROJECT_ID
LOCATION=us-central1
curl \
-X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
"https://${LOCATION}-aiplatform.googleapis.com/v1/projects/${PROJECT_ID}/locations/${LOCATION}/tuningJobs" \
-d \
$'{
   "baseModel": "gemini-2.5-flash",
   "supervisedTuningSpec" : {
      "trainingDatasetUri": "TRAINING_DATASET_URI",
      "validationDatasetUri": "VALIDATION_DATASET_URI"
   },
   "tunedModelDisplayName": "tuned_gemini"
}'
```

### Colab Enterprise

You can create a model tuning job in Agent Platform by using the
side panel in Colab Enterprise. The side panel
adds the relevant code snippets to your notebook. Then, you modify
the code snippets and run them to create your tuning job. To learn more
about using the side panel with your Agent Platform tuning jobs,
see [Interact with Agent Platform
to tune a model](https://docs.cloud.google.com/colab/docs/tuning).

1. In the Google Cloud console, go to
   the Colab Enterprise **My notebooks** page.

   [Go to My notebooks](https://console.cloud.google.com/colab/notebooks)
2. In the **Region** menu, select the region that contains your notebook.

3. Click the notebook that you want to open. If you haven't created a notebook yet,
   [create a notebook](https://docs.cloud.google.com/colab/docs/create-console-quickstart.md.txt#create).

4.
   To the right of your notebook, in the side panel, click the
   ![](https://docs.cloud.google.com/static/colab/images/icon-tuning.png) **Tuning**
   button.

   The side panel expands the **Tuning** tab.
5. Click the **Tune a Gemini model** button.


   Colab Enterprise adds code cells to your notebook for
   tuning a Gemini model.
6.
   In your notebook, find the code cell that stores parameter values.
   You'll use these parameters to interact with Agent Platform.

7. Update the values for the following parameters:

   - `PROJECT_ID`: The ID of the project that your notebook is in.
   - `REGION`: The region that your notebook is in.
   - `TUNED_MODEL_DISPLAY_NAME`: The name of your tuned model.
8. In the next code cell, update the model tuning parameters:

   - `source_model`: The Gemini model that you want to use, for example, `gemini-2.0-flash-001`.
   - `train_dataset`: The URL of your training dataset.
   - `validation_dataset`: The URL of your validation dataset.
   - Adjust the remaining parameters as needed.
9. Run the code cells that the side panel added to your notebook.

10.
    After the last code cell runs, click the
    ![](https://docs.cloud.google.com/static/colab/images/icon-tuning.png) **View
    tuning job** button that appears.

11. The side panel shows information about your model tuning job.

    - The **Monitor** tab shows tuning metrics when the metrics are ready.
    - The **Dataset** tab shows a summary and metrics about your dataset after the dataset has been processed.
    - The **Details** tab shows information about your tuning job, such as the tuning method and the base model (source model) that you used.
12.
    After the tuning job has completed, you can go directly from
    the **Tuning details** tab to a page where you can test your model.
    Click **Test**.


    The Google Cloud console opens to the Agent Platform
    **Text chat** page, where you can test your model.

### Tuning hyperparameters

It's recommended to submit your first tuning job without changing the
hyperparameters. The default value is the recommended value based on our
benchmarking results to yield the best model output quality.

- Epochs: The number of complete passes the model makes over the entire training dataset during training. Gemini Enterprise Agent Platform automatically adjusts the default value to your training dataset size. This value is based on benchmarking results to optimize model output quality.
- Adapter size: The adapter size to use for the tuning job. The adapter size influences the number of trainable parameters for the tuning job. A larger adapter size implies that the model can learn more complex tasks, but it requires a larger training dataset and longer training times.
- Learning rate multiplier: A multiplier to apply to the recommended learning rate. You can increase the value to converge faster, or decrease the value to avoid overfitting.

For a discussion of best practices for supervised fine-tuning, see the blog post
[Supervised Fine Tuning for Gemini: A best practices
guide](https://cloud.google.com/blog/products/ai-machine-learning/master-gemini-sft).

## View a list of tuning jobs

You can view a list of tuning jobs in your current project by using the
Google Cloud console, the Google Gen AI SDK, or by
sending a GET request by using the [`tuningJobs.list`](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/rest/v1/projects.locations.tuningJobs/list.md.txt) method.

### Console

> [!NOTE]
> **Note:** Viewing supervised fine-tuning jobs using the console is only available for Gemini 2.5 and earlier models.


To view your tuning jobs in the Google Cloud console, go to the
**Agent Studio** page.


[Go to Agent Studio](https://console.cloud.google.com/agent-platform/generative/language/tuning)


Your Gemini tuning jobs are listed in the table under the
**Tuned Models** section.

### Python

    from google import genai
    from google.genai.types import HttpOptions

    client = genai.Client(http_options=HttpOptions(api_version="v1"))

    responses = client.tunings.list()
    for response in responses:
        print(response.name)
        # Example response:
        # projects/123456789012/locations/us-central1/tuningJobs/123456789012345

### REST


To view a list of model tuning jobs, send a GET request by using the
[`tuningJobs.list`](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/rest/v1/projects.locations.tuningJobs/list.md.txt)
method.


Before using any of the request data,
make the following replacements:

- <var class="edit" scope="PROJECT_ID" translate="no">PROJECT_ID</var>: Your [project ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifiers).
- <var class="edit" scope="TUNING_JOB_REGION" translate="no">TUNING_JOB_REGION</var>: The [region](https://docs.cloud.google.com/gemini-enterprise-agent-platform/resources/locations.md.txt) where the tuning job runs. This is also the default region for where the tuned model is uploaded.


HTTP method and URL:

```
GET https://aiplatform.TUNING_JOB_REGION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs
```

To send your request, choose one of these options:

#### curl

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
curl -X GET \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     "https://aiplatform.TUNING_JOB_REGION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs"
```

#### PowerShell

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method GET `
    -Headers $headers `
    -Uri "https://aiplatform.TUNING_JOB_REGION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following.

#### Response

```
{
  "tuningJobs": [
    TUNING_JOB_1, TUNING_JOB_2, ...
  ]
}
```

### REST


To view a list of model tuning jobs, send a GET request by using the
[`tuningJobs.list`](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/rest/v1/projects.locations.tuningJobs/list.md.txt)
method.


Before using any of the request data,
make the following replacements:

- <var class="edit" scope="PROJECT_ID" translate="no">PROJECT_ID</var>: Your [project ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifiers).
- <var class="edit" scope="TUNING_JOB_REGION" translate="no">TUNING_JOB_REGION</var>: The [region](https://docs.cloud.google.com/gemini-enterprise-agent-platform/resources/locations.md.txt) where the tuning job runs. This is also the default region for where the tuned model is uploaded.


HTTP method and URL:

```
GET https://TUNING_JOB_REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs
```

To send your request, choose one of these options:

#### curl

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
curl -X GET \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     "https://TUNING_JOB_REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs"
```

#### PowerShell

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method GET `
    -Headers $headers `
    -Uri "https://TUNING_JOB_REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following.

#### Response

```
{
  "tuningJobs": [
    TUNING_JOB_1, TUNING_JOB_2, ...
  ]
}
```

## Get details of a tuning job

You can get the details of a tuning job in your current project by using the
Google Cloud console, the Google Gen AI SDK, or by
sending a GET request by using the [`tuningJobs.get`](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/rest/v1/projects.locations.tuningJobs/get.md.txt) method.

### Console

> [!NOTE]
> **Note:** Viewing details of supervised fine-tuning jobs using the console is only available for Gemini 2.5 and earlier models.

1.
   To view your tuning jobs in the Google Cloud console, go to the
   **Agent Studio** page.


   [Go to Agent Studio](https://console.cloud.google.com/agent-platform/generative/language/tuning)
2.
   In the **Tuned Models** table, find your model and click **Details**.


   The details of your model are shown.

### Python

    from google import genai
    from google.genai.types import HttpOptions

    client = genai.Client(http_options=HttpOptions(api_version="v1"))

    # Get the tuning job and the tuned model.
    # Eg. tuning_job_name = "projects/123456789012/locations/us-central1/tuningJobs/123456789012345"
    tuning_job = client.tunings.get(name=tuning_job_name)

    print(tuning_job.tuned_model.model)
    print(tuning_job.tuned_model.endpoint)
    print(tuning_job.experiment)
    # Example response:
    # projects/123456789012/locations/us-central1/models/1234567890@1
    # projects/123456789012/locations/us-central1/endpoints/123456789012345
    # projects/123456789012/locations/us-central1/metadataStores/default/contexts/tuning-experiment-2025010112345678

### REST


To view details of a model tuning job, send a GET request by using the
[`tuningJobs.get`](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/rest/v1/projects.locations.tuningJobs/get.md.txt)
method and specify the `TUNING_JOB_ID`.


Before using any of the request data,
make the following replacements:

- <var class="edit" scope="PROJECT_ID" translate="no">PROJECT_ID</var>: Your [project ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifiers).
- <var class="edit" scope="TUNING_JOB_REGION" translate="no">TUNING_JOB_REGION</var>: The [region](https://docs.cloud.google.com/gemini-enterprise-agent-platform/resources/locations.md.txt) where the tuning job runs. This is also the default region for where the tuned model is uploaded.
- <var class="edit" scope="TUNING_JOB_ID" translate="no">TUNING_JOB_ID</var>: The ID of the tuning job.


HTTP method and URL:

```
GET https://aiplatform.TUNING_JOB_REGION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs/TUNING_JOB_ID
```

To send your request, choose one of these options:

#### curl

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
curl -X GET \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     "https://aiplatform.TUNING_JOB_REGION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs/TUNING_JOB_ID"
```

#### PowerShell

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method GET `
    -Headers $headers `
    -Uri "https://aiplatform.TUNING_JOB_REGION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs/TUNING_JOB_ID" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following.

#### Response

```
{
  "name": "projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs/TUNING_JOB_ID",
  "tunedModelDisplayName": "TUNED_MODEL_DISPLAYNAME",
  "createTime": "CREATE_TIME",
  "endTime": "END_TIME",
  "tunedModel": {
      "model": "projects/PROJECT_ID/locations/TUNING_JOB_REGION/models/MODEL_ID",
      "endpoint": "projects/PROJECT_ID/locations/TUNING_JOB_REGION/endpoints/ENDPOINT_ID"
  },
  "experiment": "projects/PROJECT_ID/locations/TUNING_JOB_REGION/metadataStores/default/contexts/EXPERIMENT_ID",
  "tuningDataStats": {
      "supervisedTuningDataStats": {
          "tuningDatasetExampleCount": "TUNING_DATASET_EXAMPLE_COUNT",
          "totalBillableTokenCount": "TOTAL_BILLABLE_TOKEN_COUNT",
          "tuningStepCount": "TUNING_STEP_COUNT"
      }
  },
  "state": "STATE",
  "supervisedTuningSpec" : {
        "trainingDatasetUri": "TRAINING_DATASET_URI",
        "validationDatasetUri": "VALIDATION_DATASET_URI",
        "hyperParameters": {
            "epochCount": EPOCH_COUNT,
            "learningRateMultiplier": LEARNING_RATE_MULTIPLIER
        }
    }
}
```

### REST


To view details of a model tuning job, send a GET request by using the
[`tuningJobs.get`](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/rest/v1/projects.locations.tuningJobs/get.md.txt)
method and specify the `TUNING_JOB_ID`.


Before using any of the request data,
make the following replacements:

- <var class="edit" scope="PROJECT_ID" translate="no">PROJECT_ID</var>: Your [project ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifiers).
- <var class="edit" scope="TUNING_JOB_REGION" translate="no">TUNING_JOB_REGION</var>: The [region](https://docs.cloud.google.com/gemini-enterprise-agent-platform/resources/locations.md.txt) where the tuning job runs. This is also the default region for where the tuned model is uploaded.
- <var class="edit" scope="TUNING_JOB_ID" translate="no">TUNING_JOB_ID</var>: The ID of the tuning job.


HTTP method and URL:

```
GET https://TUNING_JOB_REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs/TUNING_JOB_ID
```

To send your request, choose one of these options:

#### curl

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
curl -X GET \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     "https://TUNING_JOB_REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs/TUNING_JOB_ID"
```

#### PowerShell

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method GET `
    -Headers $headers `
    -Uri "https://TUNING_JOB_REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs/TUNING_JOB_ID" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following.

#### Response

```
{
  "name": "projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs/TUNING_JOB_ID",
  "tunedModelDisplayName": "TUNED_MODEL_DISPLAYNAME",
  "createTime": "CREATE_TIME",
  "endTime": "END_TIME",
  "tunedModel": {
      "model": "projects/PROJECT_ID/locations/TUNING_JOB_REGION/models/MODEL_ID",
      "endpoint": "projects/PROJECT_ID/locations/TUNING_JOB_REGION/endpoints/ENDPOINT_ID"
  },
  "experiment": "projects/PROJECT_ID/locations/TUNING_JOB_REGION/metadataStores/default/contexts/EXPERIMENT_ID",
  "tuningDataStats": {
      "supervisedTuningDataStats": {
          "tuningDatasetExampleCount": "TUNING_DATASET_EXAMPLE_COUNT",
          "totalBillableTokenCount": "TOTAL_BILLABLE_TOKEN_COUNT",
          "tuningStepCount": "TUNING_STEP_COUNT"
      }
  },
  "state": "STATE",
  "supervisedTuningSpec" : {
        "trainingDatasetUri": "TRAINING_DATASET_URI",
        "validationDatasetUri": "VALIDATION_DATASET_URI",
        "hyperParameters": {
            "epochCount": EPOCH_COUNT,
            "learningRateMultiplier": LEARNING_RATE_MULTIPLIER
        }
    }
}
```

## Cancel a tuning job

You can cancel a tuning job in your current project by using the Google Cloud console, the Google Gen AI SDK, or by sending a POST request using the [`tuningJobs.cancel`](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/rest/v1/projects.locations.tuningJobs/cancel.md.txt) method.

### Console

> [!NOTE]
> **Note:** Canceling supervised fine-tuning jobs using the console is only available for Gemini 2.5 and earlier models.

1.
   To cancel a tuning job in the Google Cloud console, go to the
   **Agent Studio** page.


   [Go to Agent Studio](https://console.cloud.google.com/agent-platform/generative/language/tuning)
2. In the **Tuned Models** table, click **Manage run**.
3. Click **Cancel**.

### Python


    from google import genai
    from google.genai.types import HttpOptions


    def cancel_tuning_job(tuning_job_name: str) -> None:
        client = genai.Client(http_options=HttpOptions(api_version="v1"))

        # Cancel the tuning job.
        # Eg. tuning_job_name = "projects/123456789012/locations/us-central1/tuningJobs/123456789012345"
        client.tunings.cancel(name=tuning_job_name)

### REST


To cancel a model tuning job, send a POST request by using the
[`tuningJobs.cancel`](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/rest/v1/projects.locations.tuningJobs/cancel.md.txt)
method and specify the `TUNING_JOB_ID`.


Before using any of the request data,
make the following replacements:

- <var class="edit" scope="PROJECT_ID" translate="no">PROJECT_ID</var>: Your [project ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifiers).
- <var class="edit" scope="TUNING_JOB_REGION" translate="no">TUNING_JOB_REGION</var>: The [region](https://docs.cloud.google.com/gemini-enterprise-agent-platform/resources/locations.md.txt) where the tuning job runs. This is also the default region for where the tuned model is uploaded.
- <var class="edit" scope="TUNING_JOB_ID" translate="no">TUNING_JOB_ID</var>: The ID of the tuning job.


HTTP method and URL:

```
POST https://aiplatform.TUNING_JOB_REGION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs/TUNING_JOB_ID:cancel
```

To send your request, choose one of these options:

#### curl

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d "" \
     "https://aiplatform.TUNING_JOB_REGION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs/TUNING_JOB_ID:cancel"
```

#### PowerShell

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -Uri "https://aiplatform.TUNING_JOB_REGION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs/TUNING_JOB_ID:cancel" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following.

#### Response

```
{}
```

### REST


To cancel a model tuning job, send a POST request by using the
[`tuningJobs.cancel`](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/rest/v1/projects.locations.tuningJobs/cancel.md.txt)
method and specify the `TUNING_JOB_ID`.


Before using any of the request data,
make the following replacements:

- <var class="edit" scope="PROJECT_ID" translate="no">PROJECT_ID</var>: Your [project ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifiers).
- <var class="edit" scope="TUNING_JOB_REGION" translate="no">TUNING_JOB_REGION</var>: The [region](https://docs.cloud.google.com/gemini-enterprise-agent-platform/resources/locations.md.txt) where the tuning job runs. This is also the default region for where the tuned model is uploaded.
- <var class="edit" scope="TUNING_JOB_ID" translate="no">TUNING_JOB_ID</var>: The ID of the tuning job.


HTTP method and URL:

```
POST https://TUNING_JOB_REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs/TUNING_JOB_ID:cancel
```

To send your request, choose one of these options:

#### curl

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d "" \
     "https://TUNING_JOB_REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs/TUNING_JOB_ID:cancel"
```

#### PowerShell

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -Uri "https://TUNING_JOB_REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/tuningJobs/TUNING_JOB_ID:cancel" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following.

#### Response

```
{}
```

> [!NOTE]
> **Note:** If you configured the Gen AI evaluation service to run automatically during tuning, any evaluations that are in progress still run to completion even if you cancel the tuning job.

## Evaluate the tuned model

If you didn't [configure the Gen AI evaluation service](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/tuning/supervised-tuning/use.md.txt#create_a_text_model_supervised_tuning_job) to run automatically after the tuning job, you can interact with the tuned model endpoint the same way as base
Gemini by using the Google Gen AI SDK,
or by sending a POST request using the `generateContent` method.

> [!NOTE]
> **Note:** For global endpoint serving, the REST URL should use `aiplatform.googleapis.com` instead of the `.rep.googleapis.com` multi-region endpoint. Use the following endpoint format:
>
> ```
> https://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/global/endpoints/ENDPOINT_ID:generateContent
> ```

For thinking models, we recommend setting the thinking budget to `0` (for
Gemini 2.5 and earlier models) or the thinking level to `MINIMAL` (for
Gemini 3 and later models) on tuned tasks for optimal performance and
cost efficiency. During supervised fine-tuning, the model learns to mimic the
ground truth in the tuning dataset, omitting the thinking process. Therefore,
the tuned model can handle the task effectively without a thinking budget.

The following example prompts a model with the question "Why is sky blue?".

### Console

> [!NOTE]
> **Note:** Testing tuned models using the console is only available for Gemini 2.5 and earlier models.

1.
   To view details of a tuned model in the Google Cloud console, go to the
   **Agent Studio** page.


   [Go to **Agent Studio**](https://console.cloud.google.com/agent-platform/generative/language/tuning)
2.
   In the **Tuned Models** table, select **Test**.


   A page where you can create a conversation with your tuned model is
   displayed.

### Python

    from google import genai
    from google.genai.types import HttpOptions

    client = genai.Client(http_options=HttpOptions(api_version="v1"))

    # Get the tuning job and the tuned model.
    # Eg. tuning_job_name = "projects/123456789012/locations/us-central1/tuningJobs/123456789012345"
    tuning_job = client.tunings.get(name=tuning_job_name)

    contents = "Why is the sky blue?"

    # Predicts with the tuned endpoint.
    response = client.models.generate_content(
        model=tuning_job.tuned_model.endpoint,
        contents=contents,
    )
    print(response.text)
    # Example response:
    # The sky is blue because ...

### REST


To test a tuned model with a prompt, send a POST request and
specify the `MREP_LOCATION` and `ENDPOINT_ID`.
For global endpoint serving, use the `aiplatform.googleapis.com`
endpoint format described in the note above.


Before using any of the request data,
make the following replacements:

- <var class="edit" scope="MREP_LOCATION" translate="no">MREP_LOCATION</var>: The Google Cloud multi-region endpoint location that the tuning job runs in.
- <var class="edit" scope="PROJECT_ID" translate="no">PROJECT_ID</var>: Your [project ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifiers).
- <var class="edit" scope="ENDPOINT_ID" translate="no">ENDPOINT_ID</var>: The tuned model endpoint ID from the GET API.
- <var class="edit" scope="TEMPERATURE" translate="no">TEMPERATURE</var>: The temperature is used for sampling during response generation, which occurs when `topP` and `topK` are applied. Temperature controls the degree of randomness in token selection. Lower temperatures are good for prompts that require a less open-ended or creative response, while higher temperatures can lead to more diverse or creative results. A temperature of `0` means that the highest probability tokens are always selected. In this case, responses for a given prompt are mostly deterministic, but a small amount of variation is still possible.

  If the model returns a response that's too generic, too short, or the model gives a fallback
  response, try increasing the temperature. If the model enters infinite generation, increasing the
  temperature to at least `0.1` may lead to improved results.
  `1.0` is the recommended starting value for temperature.
- <var class="edit" scope="TOP_P" translate="no">TOP_P</var>: Top-P changes how the model selects tokens for output. Tokens are selected from the most probable to least probable until the sum of their probabilities equals the top-P value. For example, if tokens A, B, and C have a probability of 0.3, 0.2, and 0.1 and the top-P value is `0.5`, then the model will select either A or B as the next token by using temperature and excludes C as a candidate.

  Specify a lower value for less random responses and a higher value for more
  random responses.
- <var class="edit" scope="TOP_K" translate="no">TOP_K</var>: Top-K changes how the model selects tokens for output. A top-K of `1` means the next selected token is the most probable among all tokens in the model's vocabulary (also called greedy decoding), while a top-K of `3` means that the next token is selected from among the three most probable tokens by using temperature.

  For each token selection step, the top-K tokens with the highest
  probabilities are sampled. Then tokens are further filtered based on top-P with
  the final token selected using temperature sampling.

  Specify a lower value for less random responses and a higher value for more
  random responses.
- <var class="edit" scope="MAX_OUTPUT_TOKENS" translate="no">MAX_OUTPUT_TOKENS</var>: Maximum number of tokens that can be generated in the response. A token is approximately four characters. 100 tokens correspond to roughly 60-80 words.

  Specify a lower value for shorter responses and a higher value for potentially longer
  responses.


HTTP method and URL:

```
POST https://aiplatform.MREP_LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/MREP_LOCATION/endpoints/ENDPOINT_ID:generateContent
```


Request JSON body:

```
{
    "contents": [
        {
            "role": "USER",
            "parts": [
                {
                    "text": "Why is sky blue?"
                }
            ]
        }
    ],
    "generationConfig": {
        "temperature": TEMPERATURE,
        "topP": TOP_P,
        "topK": TOP_K,
        "maxOutputTokens": MAX_OUTPUT_TOKENS
    }
}
```

To send your request, choose one of these options:

#### curl

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://aiplatform.MREP_LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/MREP_LOCATION/endpoints/ENDPOINT_ID:generateContent"
```

#### PowerShell

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://aiplatform.MREP_LOCATION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/MREP_LOCATION/endpoints/ENDPOINT_ID:generateContent" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following.

#### Response

```
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {
            "text": "The sky appears blue due to a phenomenon called Rayleigh
            scattering, where shorter blue wavelengths of sunlight are scattered
            more strongly by the Earth's atmosphere than longer red
            wavelengths."
          }
        ]
      },
      "finishReason": "STOP",
      "safetyRatings": [
        {
          "category": "HARM_CATEGORY_HATE_SPEECH",
          "probability": "NEGLIGIBLE",
          "probabilityScore": 0.06325052,
          "severity": "HARM_SEVERITY_NEGLIGIBLE",
          "severityScore": 0.03179867
        },
        {
          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
          "probability": "NEGLIGIBLE",
          "probabilityScore": 0.09334688,
          "severity": "HARM_SEVERITY_NEGLIGIBLE",
          "severityScore": 0.027742893
        },
        {
          "category": "HARM_CATEGORY_HARASSMENT",
          "probability": "NEGLIGIBLE",
          "probabilityScore": 0.17356819,
          "severity": "HARM_SEVERITY_NEGLIGIBLE",
          "severityScore": 0.025419652
        },
        {
          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
          "probability": "NEGLIGIBLE",
          "probabilityScore": 0.07864238,
          "severity": "HARM_SEVERITY_NEGLIGIBLE",
          "severityScore": 0.020332353
        }
      ]
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 5,
    "candidatesTokenCount": 33,
    "totalTokenCount": 38
  }
}
```

### REST


To test a tuned model with a prompt, send a POST request and
specify the `ENDPOINT_ID`.


Before using any of the request data,
make the following replacements:

- <var class="edit" scope="PROJECT_ID" translate="no">PROJECT_ID</var>: Your [project ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifiers).
- <var class="edit" scope="TUNING_JOB_REGION" translate="no">TUNING_JOB_REGION</var>: The region where the tuning job runs. This is also the default region for where the tuned model is uploaded.
- <var class="edit" scope="ENDPOINT_ID" translate="no">ENDPOINT_ID</var>: The tuned model endpoint ID from the GET API.
- <var class="edit" scope="TEMPERATURE" translate="no">TEMPERATURE</var>: The temperature is used for sampling during response generation, which occurs when `topP` and `topK` are applied. Temperature controls the degree of randomness in token selection. Lower temperatures are good for prompts that require a less open-ended or creative response, while higher temperatures can lead to more diverse or creative results. A temperature of `0` means that the highest probability tokens are always selected. In this case, responses for a given prompt are mostly deterministic, but a small amount of variation is still possible.

  If the model returns a response that's too generic, too short, or the model gives a fallback
  response, try increasing the temperature. If the model enters infinite generation, increasing the
  temperature to at least `0.1` may lead to improved results.
  `1.0` is the recommended starting value for temperature.
- <var class="edit" scope="TOP_P" translate="no">TOP_P</var>: Top-P changes how the model selects tokens for output. Tokens are selected from the most probable to least probable until the sum of their probabilities equals the top-P value. For example, if tokens A, B, and C have a probability of 0.3, 0.2, and 0.1 and the top-P value is `0.5`, then the model will select either A or B as the next token by using temperature and excludes C as a candidate.

  Specify a lower value for less random responses and a higher value for more
  random responses.
- <var class="edit" scope="TOP_K" translate="no">TOP_K</var>: Top-K changes how the model selects tokens for output. A top-K of `1` means the next selected token is the most probable among all tokens in the model's vocabulary (also called greedy decoding), while a top-K of `3` means that the next token is selected from among the three most probable tokens by using temperature.

  For each token selection step, the top-K tokens with the highest
  probabilities are sampled. Then tokens are further filtered based on top-P with
  the final token selected using temperature sampling.

  Specify a lower value for less random responses and a higher value for more
  random responses.
- <var class="edit" scope="MAX_OUTPUT_TOKENS" translate="no">MAX_OUTPUT_TOKENS</var>: Maximum number of tokens that can be generated in the response. A token is approximately four characters. 100 tokens correspond to roughly 60-80 words.

  Specify a lower value for shorter responses and a higher value for potentially longer
  responses.


HTTP method and URL:

```
POST https://TUNING_JOB_REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/endpoints/ENDPOINT_ID:generateContent
```


Request JSON body:

```
{
    "contents": [
        {
            "role": "USER",
            "parts": [
                {
                    "text": "Why is sky blue?"
                }
            ]
        }
    ],
    "generationConfig": {
        "temperature": TEMPERATURE,
        "topP": TOP_P,
        "topK": TOP_K,
        "maxOutputTokens": MAX_OUTPUT_TOKENS
    }
}
```

To send your request, choose one of these options:

#### curl

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
curl -X POST \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     -H "Content-Type: application/json; charset=utf-8" \
     -d @request.json \
     "https://TUNING_JOB_REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/endpoints/ENDPOINT_ID:generateContent"
```

#### PowerShell

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Save the request body in a file named `request.json`,
and execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method POST `
    -Headers $headers `
    -ContentType: "application/json; charset=utf-8" `
    -InFile request.json `
    -Uri "https://TUNING_JOB_REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/TUNING_JOB_REGION/endpoints/ENDPOINT_ID:generateContent" | Select-Object -Expand Content
```

You should receive a JSON response similar to the following.

#### Response

```
{
  "candidates": [
    {
      "content": {
        "role": "model",
        "parts": [
          {
            "text": "The sky appears blue due to a phenomenon called Rayleigh
            scattering, where shorter blue wavelengths of sunlight are scattered
            more strongly by the Earth's atmosphere than longer red
            wavelengths."
          }
        ]
      },
      "finishReason": "STOP",
      "safetyRatings": [
        {
          "category": "HARM_CATEGORY_HATE_SPEECH",
          "probability": "NEGLIGIBLE",
          "probabilityScore": 0.06325052,
          "severity": "HARM_SEVERITY_NEGLIGIBLE",
          "severityScore": 0.03179867
        },
        {
          "category": "HARM_CATEGORY_DANGEROUS_CONTENT",
          "probability": "NEGLIGIBLE",
          "probabilityScore": 0.09334688,
          "severity": "HARM_SEVERITY_NEGLIGIBLE",
          "severityScore": 0.027742893
        },
        {
          "category": "HARM_CATEGORY_HARASSMENT",
          "probability": "NEGLIGIBLE",
          "probabilityScore": 0.17356819,
          "severity": "HARM_SEVERITY_NEGLIGIBLE",
          "severityScore": 0.025419652
        },
        {
          "category": "HARM_CATEGORY_SEXUALLY_EXPLICIT",
          "probability": "NEGLIGIBLE",
          "probabilityScore": 0.07864238,
          "severity": "HARM_SEVERITY_NEGLIGIBLE",
          "severityScore": 0.020332353
        }
      ]
    }
  ],
  "usageMetadata": {
    "promptTokenCount": 5,
    "candidatesTokenCount": 33,
    "totalTokenCount": 38
  }
}
```

## Copy a tuned model and serve in another region

To serve a tuned model on a global endpoint, copy an existing tuned model from
a source region (such as `us` or `eu`) to the `global` region, create a global
endpoint, and deploy the model to the endpoint.

For more information, see the
[Copy Model documentation](https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/model-registry/copy-model.md.txt).

> [!NOTE]
> **Note:** The global region does not support Customer-Managed Encryption Keys (CMEK) and does not support Data Residency Zones (DRZ). Tuned model artifacts (adapters) for global models are stored in the US region because Cloud Storage does not offer a global bucket location.

The following REST command examples demonstrate how to copy a model to the
global region, create a global endpoint, and deploy the model:

- Copy Model to Global Region:

  ```bash
  curl -X POST \
       -H "Authorization: Bearer $(gcloud auth print-access-token)" \
       -H "Content-Type: application/json; charset=utf-8" \
       -d '{
          "sourceModel": "projects/SRC_PROJECT_ID/locations/SRC_LOCATION/models/MODEL_ID"
        }' \
       "https://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/global/models:copy"
  ```
- Create Global Endpoint:

  ```bash
  curl -X POST \
       -H "Authorization: Bearer $(gcloud auth print-access-token)" \
       -H "Content-Type: application/json" \
       "https://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/global/endpoints" \
       -d '{
         "displayName": "tuned_global_endpoint"
       }'
  ```
- Deploy Model to Global Endpoint:

  ```bash
  curl -X POST \
       -H "Authorization: Bearer $(gcloud auth print-access-token)" \
       -H "Content-Type: application/json" \
       "https://aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/global/endpoints/ENDPOINT_ID:deployModel" \
       -d '{
         "deployedModel": {
           "model": "projects/PROJECT_ID/locations/global/models/MODEL_ID",
           "displayName": "tuned_deploy_model",
           "automaticResources": {"minReplicaCount": 1, "maxReplicaCount": 1}
         }
       }'
  ```

## Delete a tuned model

To delete a tuned model:

### REST


Call the [`models.delete`](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/rest/v1/projects.locations.models/delete.md.txt) method.


Before using any of the request data,
make the following replacements:

- <var class="edit" scope="PROJECT_ID" translate="no">PROJECT_ID</var>: Your [project ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifiers).
- <var class="edit" scope="REGION" translate="no">REGION</var>: The region where the tuned model is located.
- <var class="edit" scope="MODEL_ID" translate="no">MODEL_ID</var>: The ID of the tuned model to delete.


HTTP method and URL:

```
DELETE https://aiplatform.REGION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/models/MODEL_ID
```

To send your request, choose one of these options:

#### curl

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
curl -X DELETE \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     "https://aiplatform.REGION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/models/MODEL_ID"
```

#### PowerShell

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method DELETE `
    -Headers $headers `
    -Uri "https://aiplatform.REGION.rep.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/models/MODEL_ID" | Select-Object -Expand Content
```

You should receive a successful status code (2xx) and an empty response.

### REST


Call the [`models.delete`](https://docs.cloud.google.com/gemini-enterprise-agent-platform/reference/rest/v1/projects.locations.models/delete.md.txt) method.


Before using any of the request data,
make the following replacements:

- <var class="edit" scope="PROJECT_ID" translate="no">PROJECT_ID</var>: Your [project ID](https://docs.cloud.google.com/resource-manager/docs/creating-managing-projects.md.txt#identifiers).
- <var class="edit" scope="REGION" translate="no">REGION</var>: The region where the tuned model is located.
- <var class="edit" scope="MODEL_ID" translate="no">MODEL_ID</var>: The ID of the tuned model to delete.


HTTP method and URL:

```
DELETE https://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/models/MODEL_ID
```

To send your request, choose one of these options:

#### curl

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) , or by using [Cloud Shell](https://docs.cloud.google.com/shell/docs.md.txt), which automatically logs you into the `gcloud` CLI . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
curl -X DELETE \
     -H "Authorization: Bearer $(gcloud auth print-access-token)" \
     "https://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/models/MODEL_ID"
```

#### PowerShell

> [!NOTE]
> **Note:** The following command assumes that you have logged in to the `gcloud` CLI with your user account by running [`gcloud init`](https://docs.cloud.google.com/sdk/gcloud/reference/init) or [`gcloud auth login`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/login.md.txt) . You can check the currently active account by running [`gcloud auth list`](https://docs.cloud.google.com/sdk/gcloud/reference/auth/list.md.txt).


Execute the following command:

```
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
    -Method DELETE `
    -Headers $headers `
    -Uri "https://REGION-aiplatform.googleapis.com/v1/projects/PROJECT_ID/locations/REGION/models/MODEL_ID" | Select-Object -Expand Content
```

You should receive a successful status code (2xx) and an empty response.

## Tuning and validation metrics

You can configure a model tuning job to collect and report model tuning and
model evaluation metrics, which can then be visualized in
**Agent Studio**.

> [!NOTE]
> **Note:** Viewing tuning metrics using the console is only available for Gemini 2.5 and earlier models.

1. To view details of a tuned model in the Google Cloud console, go to the
   **Agent Studio** page.

   [Go to **Agent Studio**](https://console.cloud.google.com/agent-platform/generative/language/tuning)
2. In the **Tune and Distill** table, click the name of the tuned model
   that you want to view metrics for.

   The tuning metrics appear under the **Monitor** tab.

### Model tuning metrics

The model tuning job automatically collects the following tuning metrics
for the model:

- `/train_total_loss`: Loss for the tuning dataset at a training step.
- `/train_fraction_of_correct_next_step_preds`: The token accuracy at a training step. A single inference consists of a sequence of predicted tokens. This metric measures the accuracy of the predicted tokens when compared to the ground truth in the tuning dataset.
- `/train_num_predictions`: Number of predicted tokens at a training step.

### Model validation metrics

You can configure a model tuning job to collect the following validation metrics
for the model:

- `/eval_total_loss`: Loss for the validation dataset at a validation step.
- `/eval_fraction_of_correct_next_step_preds`: The token accuracy at a validation step. A single inference consists of a sequence of predicted tokens. This metric measures the accuracy of the predicted tokens when compared to the ground truth in the validation dataset.
- `/eval_num_predictions`: Number of predicted tokens at a validation step.

The metrics visualizations are available after the tuning job starts running.
It will be updated in real time as tuning progresses.
If you don't specify a validation dataset when you create the tuning job, only
the visualizations for the tuning metrics are available.

## What's next

- Learn about [deploying a tuned Gemini model](https://docs.cloud.google.com/gemini-enterprise-agent-platform/models/deploy/overview.md.txt#deploy_a_tuned_model).