[Total: 0    Average: 0/5]

Google Cloud supports a Cloud Billing Catalog API. I have not worked with this API yet. Today, I plan to experiment.

Documentation page to get started with Google Cloud Platform Pricing:

Get Google Cloud Platform Pricing Information

This API requires an API Key.

  1. Go to the Google Cloud Console.
  2. Go to APIs & Services.
  3. Select Credentials.
  4. Click the “Create Credentials” button, which displays a popup menu. Select API key.
  5. Save your API key.

Using API Keys

I will use curl to play with the API.

Listing public services from the catalog. Replace API_KEY with your key.

This resulted in the following error:

To solve this I went to the Google Console -> APIs & Services -> API Library. In the search box, enter “Cloud Billing API”. Enabled the API.

I then tried the command again which resulted in a long listing. I have truncated the output for this article. 60 services were returned.

Now lets use “jq” to process the output to get a list of the displayNames. We will sort the output and save to services.txt. The “-f” flag makes the sort case insensitive.

Now we have a list like this (truncated):

The next step is to get the list of SKUs for a service. We will use curl for this. I am interested in Compute Engine. The SERVICE_ID for Compute Engine is 6F81-5844-456A which I obtained from the services.json file.

This command returned a huge amount of information. In my case 210,420 lines of information. Truncated example:

Again we can use “jq” to start to understand the data. We begin by just looking at the “description” key for each item.

This command returned 5,000 lines. Let’s look at one of the “skus”.

In this example, “Cloud Interconnect – 500Mbps VLAN attachment via Google partner” let’s look at the pricing. Pricing is set by these three fields:

The key “units” is in dollars if the “currencyCode” is “USD”. The key “nanos” is number of nano units. For example $1.25 would be:

The key “nanos” is 250,000,000 / 1,000,000,000 or 1/4 or $0.25.

This means that a 500 Mbps Cloud Interconnect Attachment is billed by the hour (“usageUnit”: “h”) and the cost is $0.1736 per hour (“units”: “0”, “nanos”: “173600000”). This is approximately $125.00 per month which matches published pricing on this page.

Very interesting how Google breaks everything down into a large number of details.

From the output we can see that the skuId for this Cloud Interconnect Attachment is “4AB4-96FF-A1F6”. We can combine curl with jq to only extract this sku to automate getting pricing.

Which returns this:

Which can be easily processed by any json library.

Update: I realized that I could not find some of the SKUs in the downloaded json. The bottom of the json had “nextPageToken”. Consulting the documentation I realized that you need to make multiple calls to download the entire list of SKUs.

After more research I learned about this Platform SKUs Explorer which makes it easy to browse the SKUs if you know the “skuId”.