> For the complete documentation index, see [llms.txt](https://docs.onelens.cloud/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.onelens.cloud/integrations/kubernetes/onelens-agent/create-gcp-api-key-for-pricing-data.md).

# Create GCP API Key for Pricing Data

The OneLens agent uses OpenCost to collect cost allocation data from GKE clusters. OpenCost requires a Google Cloud API key with access to the **Cloud Billing API** to fetch real-time GCP pricing information, including compute instance rates, storage costs, and network egress.

Without this key, OpenCost cannot retrieve pricing data and the cost metrics collected by the agent will be unavailable.

## Prerequisites

* Access to the Google Cloud Console with one of the following:
  * **Owner**
  * **Editor**
  * Roles `roles/serviceusage.apiKeysAdmin` + `roles/serviceusage.serviceUsageAdmin`
* The GCP project should be linked to a billing account.

## Step-by-Step Guide

{% stepper %}
{% step %}

### Open Google Cloud Console

Navigate to [https://console.cloud.google.com](https://console.cloud.google.com/) and select the project where your GKE cluster is running.
{% endstep %}

{% step %}

### Enable the Cloud Billing API

1. In the left navigation menu, go to **APIs & Services → Library**.
2. In the search bar, type **Cloud Billing API**.
3. Click **Cloud Billing API** from the results.
4. If the API is not already enabled, click **Enable**.
5. Wait for the API to be enabled. This takes a few seconds.

{% hint style="info" %}
If the API is already enabled, you will see a **Manage** button instead of **Enable**. You can proceed to the next step.
{% endhint %}
{% endstep %}

{% step %}

### Create the API Key

1. In the left navigation menu, go to **APIs & Services → Credentials**.
2. At the top of the page, click **+ CREATE CREDENTIALS**.
3. Select **API key** from the dropdown menu.
4. A dialog will appear with your newly created API key.
5. Copy the API key and store it securely. You will need it during OneLens agent installation.
   {% endstep %}

{% step %}

### Restrict the API Key (Recommended)

Restricting the key ensures it can only be used to access the Cloud Billing API and nothing else.

1. In the API key created dialog, click **Edit API key** or click the key name in the Credentials list.
2. Under **Set an application restriction** (optional), select **None** or configure IP restrictions if your cluster has a fixed egress IP.
3. Under **API restrictions**:
   * Select **Restrict key**.
   * Click the **Select APIs** dropdown.
   * Search for and select **Cloud Billing API**.
   * Click **OK**.
4. Click **Save** at the bottom of the page.
   {% endstep %}

{% step %}

### Provide the API Key During Installation

Pass the API key as an environment variable when running the OneLens deployer:

```bash
--set-string job.env.GCP_API_KEY="<YOUR_API_KEY>"
```

The installer will automatically configure OpenCost to use this key for fetching GCP pricing data.
{% endstep %}
{% endstepper %}

## What Data Does This Key Access?

The API key OpenCost uses accesses only the following:

| Authentication | Data Returned           | Used by OpenCost? |
| -------------- | ----------------------- | ----------------- |
| API key        | Public list prices only | Yes               |

**An API key can only access public pricing data.** This is the same pricing information published on Google's service-specific pricing pages, for example, [Compute Engine pricing](https://cloud.google.com/compute/all-pricing) and [Cloud Storage pricing](https://cloud.google.com/storage/pricing). The API key simply provides programmatic access to these public rates.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.onelens.cloud/integrations/kubernetes/onelens-agent/create-gcp-api-key-for-pricing-data.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
