Create GCP API Key for Pricing Data
Last updated
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.
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.
Navigate to https://console.cloud.google.com and select the project where your GKE cluster is running.
In the left navigation menu, go to APIs & Services → Library.
In the search bar, type Cloud Billing API.
Click Cloud Billing API from the results.
If the API is not already enabled, click Enable.
Wait for the API to be enabled. This takes a few seconds.
If the API is already enabled, you will see a Manage button instead of Enable. You can proceed to the next step.
In the left navigation menu, go to APIs & Services → Credentials.
At the top of the page, click + CREATE CREDENTIALS.
Select API key from the dropdown menu.
A dialog will appear with your newly created API key.
Copy the API key and store it securely. You will need it during OneLens agent installation.
Restricting the key ensures it can only be used to access the Cloud Billing API and nothing else.
In the API key created dialog, click Edit API key or click the key name in the Credentials list.
Under Set an application restriction (optional), select None or configure IP restrictions if your cluster has a fixed egress IP.
Under API restrictions:
Select Restrict key.
Click the Select APIs dropdown.
Search for and select Cloud Billing API.
Click OK.
Click Save at the bottom of the page.
The API key OpenCost uses accesses only the following:
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 and Cloud Storage pricing. The API key simply provides programmatic access to these public rates.
Last updated

