You can review the cost of your pipeline runs using [Cloud Billing export to BigQuery](https://docs.cloud.google.com/billing/docs/how-to/export-data-bigquery.md.txt).

You can also use the unique pipeline run billing ID of your pipeline run to review the costs of resources created by the pipeline run, as follows:

1. Vertex AI Pipelines automatically attaches the `vertex-ai-pipelines-run-billing-id` label to your pipeline run. The value of this label is your unique pipeline run billing ID.

2. Vertex AI Pipelines propagates this label to Google Cloud resources generated by pipeline components during the pipeline run. Note that for some components and resources, you need to either upgrade the Google Cloud Pipeline Components SDK or update your component code to propagate the labels. For more information about labeling Google Cloud resources, see [Resource labeling by Vertex AI Pipelines](https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/pipelines/gcpc-label-propagation.md.txt).

3. The `vertex-ai-pipelines-run-billing-id` label connects the usage of Google Cloud resources generated by the pipeline run in billing reports. Using the value of this label, you can review the cost of the resource usage in the pipeline run with [Cloud Billing export to BigQuery](https://docs.cloud.google.com/billing/docs/how-to/export-data-bigquery.md.txt).

This page shows you how to do the following:

- [List your ten most expensive pipeline runs](https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/pipelines/understand-pipeline-cost-labels.md.txt#retrieve_ten_most_expensive_pipelines)

- [Use a pipeline run billing ID to locate a pipeline run](https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/pipelines/understand-pipeline-cost-labels.md.txt#locate_pipeline_run)

- [Query the costs of Google Cloud resources in a pipeline run from Cloud Billing](https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/pipelines/understand-pipeline-cost-labels.md.txt#view_pipeline_resources_cost)

## Before you begin

Before you use Cloud Billing to understand the cost of a pipeline run, use the following instructions to set up your Google Cloud project and development environment:

- [Set up Cloud Billing data export to BigQuery](https://docs.cloud.google.com/billing/docs/how-to/export-data-bigquery-setup.md.txt).

- [Install v1.0.31 or higher of the Google Cloud Pipeline Components SDK](https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/pipelines/components-quickstart.md.txt#install_latest_release)

For more information about the schema of Cloud Billing standard usage cost data, see [Schema of the standard usage cost data](https://docs.cloud.google.com/billing/docs/how-to/export-data-bigquery-tables/standard-usage.md.txt#usage-cost-export-more-info).

## List your ten most expensive pipeline runs

Run the following query to view a list of your ten most expensive pipeline runs over a specified time period:

**Standard SQL**

```sql
SELECT
  project.id,
  location.region,
  L.value,
  SUM(cost) AS total_cost
FROM
  `project.dataset.gcp_billing_export_v1_XXXXXX_XXXXXX_XXXXXX` B,
  UNNEST (B.labels) L
WHERE
  DATE(_PARTITIONTIME) >= "START_DATE"
  AND DATE(_PARTITIONTIME) < "END_DATE"
  AND L.key = "vertex-ai-pipelines-run-billing-id"
GROUP BY
  project.id,
  location.region,
  L.value
ORDER BY
  total_cost DESC
LIMIT
  10;
```

Replace the following:

- <var translate="no">START_DATE</var>: Start date of the time period.

- <var translate="no">END_DATE</var>: End date of the time period.

You should see the following columns in the query results:

- `project_id`

- `region`

- `pipeline_run_billing_id`

- `total_cost`

You can now use the unique pipeline run billing ID from the `pipeline_run_billing_id` column of the query results to do the following:

- [Locate or retrieve a pipeline run](https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/pipelines/understand-pipeline-cost-labels.md.txt#locate_pipeline_run)

- [View the costs of Google Cloud resources in a pipeline run](https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/pipelines/understand-pipeline-cost-labels.md.txt#view_pipeline_resources_cost)

> [!TIP]
> **Tip:** The query results display the pipeline runs in the descending order of the cost. The first row represents the most expensive pipeline run.

## Use the billing ID to locate a pipeline run

You can use the unique pipeline run billing ID from the query results in [List your ten most expensive pipeline runs](https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/pipelines/understand-pipeline-cost-labels.md.txt#retrieve_ten_most_expensive_pipelines) to locate a pipeline run.

### Console

Use the following instructions to retrieve a pipeline run in the Google Cloud console.

1. In the Google Cloud console, in the Agent Platform section, go to the **Pipelines** page.

   [Go to Pipelines](https://console.cloud.google.com/agent-platform/pipelines)
2. To locate the pipeline run, filter the list using a unique pipeline run billing ID from the query results in [List your ten most expensive pipeline runs](https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/pipelines/understand-pipeline-cost-labels.md.txt#retrieve_ten_most_expensive_pipelines). To do this:

   1. Click **Filter** and then click **Labels**.

   2. Enter the unique pipeline run billing ID in the following format and press **Enter** :  

      `labels.vertex-ai-pipelines-run-billing-id=PIPELINE_RUN_BILLING_ID`  

      where <var translate="no">PIPELINE_RUN_BILLING_ID</var> is the unique pipeline run billing ID.

### Agent Platform SDK for Python

Use the following code sample to retrieve the pipeline run:

```python
runs = aip.PipelineJob.list(
  project=PROJECT_ID,
  location=LOCATION,
  filter="labels.vertex-ai-pipelines-run-billing-id=PIPELINE_RUN_BILLING_ID")
```

Replace the following:

- <var translate="no">PROJECT_ID</var>: The Google Cloud project that this pipeline runs in.

- <var translate="no">LOCATION</var>: The region that the pipeline runs in. For more information about the regions that Agent Platform Pipelines is available in, see the [Gemini Enterprise Agent Platform locations guide](https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/general/locations.md.txt#feature-availability).

- <var translate="no">PIPELINE_RUN_BILLING_ID</var>: Unique pipeline run billing ID from the query results in [List your ten most expensive pipeline runs](https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/pipelines/understand-pipeline-cost-labels.md.txt#retrieve_ten_most_expensive_pipelines).

## View the costs of Google Cloud resources in a pipeline run

You can use the unique pipeline run billing ID from the query results in [List your ten most expensive pipeline runs](https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/pipelines/understand-pipeline-cost-labels.md.txt#retrieve_ten_most_expensive_pipelines) to view the costs of Google Cloud resources generated by the pipeline run.

Run the following query to view the list of Google Cloud resources generated in a pipeline run, along with the cost of each resource:

**Standard SQL**

```sql
SELECT
  service,
  sku,
  cost
FROM
  `project.dataset.gcp_billing_export_v1_XXXXXX_XXXXXX_XXXXXX` B,
  UNNEST (B.labels) L
WHERE
  DATE(_PARTITIONTIME) >=  "START_DATE"
  AND DATE(_PARTITIONTIME) <  "END_DATE"
  AND L.key = "vertex-ai-pipelines-run-billing-id"
  AND L.value = "PIPELINE_RUN_BILLING_ID";
```

Replace the following:

- <var translate="no">START_DATE</var>: Start date of the time period.

- <var translate="no">END_DATE</var>: End date of the time period.

- <var translate="no">PIPELINE_RUN_BILLING_ID</var>: Unique pipeline run billing ID from the query results in [List your ten most expensive pipeline runs](https://docs.cloud.google.com/gemini-enterprise-agent-platform/machine-learning/pipelines/understand-pipeline-cost-labels.md.txt#retrieve_ten_most_expensive_pipelines).

You should see the following columns in the query results:

- `service.id`

- `service.description`

- `sku.id`

- `sku_description`

- `cost`

The `cost` column represents the cost of a resource corresponding to the `sku.id` in the pipeline run.