This blog post was written by Santosh Kanala, Solutions Architect

If you are a tech enthusiast trying new azure capabilities or a student working on Cloudskills azure boot camps (Cloudskills) or are part of an enterprise working on your cloud spending budget, one of the questions that always come up is, how much will it cost me for a day, a week, a month or a year to provision an azure service? And to compare prices between different regions and SKUs so that you can estimate your costs and make an informed decision.

Microsoft provides three approaches as of now to get the prices of azure resources.

• Azure Pricing Calculator

• Azure Portal

• Azure Retail Prices API

Using Azure Pricing Calculator or Azure portal will provide the prices for the resources in a GUI format, but it gets very cumbersome when you need to compare prices across different SKUs and regions. This is where Azure Retail Prices API can come in handy to pull data in bulk which opens various possibilities to perform operations on the data and to use it for further analysis.

In this post, you will explore different aspects of the Azure Retail Prices API as listed below

• API Endpoint

• API Response

• Compare API response to Azure price calculator portal

• Available API filters

• Filter Examples

• Export Prices to Excel

• Microsoft Documentation

• References

When you are finished, you will be familiar with the Azure Retail Prices API endpoint, understanding of a typical azure retail price API response, filters that you can apply to the API, and an example of how we can use the API.

Prerequisites

Before you move ahead, you will need the following:

• Basic understanding of APIs (APIs for Beginners) • Basic understanding of JSON (JSON Crash Course)

Azure Retail Prices API Endpoint

The endpoint to retrieve the azure retail prices is below.

https://prices.azure.com/api/retail/prices

This is an unauthenticated API endpoint, which means that you do not need to request an authorization token to use it. You can go ahead and directly make use of the API.

If you send a request to the above API, you will get the prices for all the azure resources available across various geographical locations in a batch of 100 at a time. As of now, all the prices are listed in USD currency.

In the next section, we will look at the response we get after making an azure retail prices API request and go over few properties that are part of the API response.

Azure Retail Prices API Response

When you make an API request to the endpoint https://prices.azure.com/api/retail/prices, you will receive a response similar to what we see below. The initial response contains 100 records, but we are showing a couple of azure service price records here as a sample.

{ "BillingCurrency": "USD", "CustomerEntityId": "Default", "CustomerEntityType": "Retail", "Items": [ { "currencyCode": "USD", "tierMinimumUnits": 0.0, "retailPrice": 10.56, "unitPrice": 10.56, "armRegionName": "uksouth", "location": "UK South", "effectiveStartDate": "2018-11-01T00:00:00Z", "meterId": "0001d427-82df-4d83-8ab2-b60768527e08", "meterName": "E10 Disks", "productId": "DZH318Z0BP88", "skuId": "DZH318Z0BP88/001V", "productName": "Standard SSD Managed Disks", "skuName": "E10 LRS", "serviceName": "Storage", "serviceId": "DZH317F1HKN0", "serviceFamily": "Storage", "unitOfMeasure": "1/Month", "type": "Consumption", "isPrimaryMeterRegion": true, "armSkuName": ""        }, .        .        .        .        .        ., { "currencyCode": "USD", "tierMinimumUnits": 0.0, "retailPrice": 0.655, "unitPrice": 0.655, "armRegionName": "australiacentral", "location": "AU Central", "effectiveStartDate": "2020-02-01T00:00:00Z", "meterId": "0024a94d-7549-4caf-8bc1-b5ddd7e82c6f", "meterName": "A8m v2", "productId": "DZH318Z0BPRJ", "skuId": "DZH318Z0BPRJ/00JZ", "productName": "Virtual Machines Av2 Series", "skuName": "A8m v2", "serviceName": "Virtual Machines", "serviceId": "DZH313Z7MMC8", "serviceFamily": "Compute", "unitOfMeasure": "1 Hour", "type": "Consumption", "isPrimaryMeterRegion": true, "armSkuName": "Standard_A8m_v2"        } ], "NextPageLink": "https://prices.azure.com:443/api/retail/prices?$skip=100", "Count": 100}

As part of the API response, you will always see below properties

BillingCurrency, CustomerEntityID, CustomerEntityType, Items, NextPageLink, Count

Azure retails prices will be listed out as part of the "Items" property in form of an array. If the API request results in more than 100 items, you will see a link to retrieve the next set of prices as part of the "NextPageLink" property. "Count" property gives you the number of records that are part of the "Items" property.

Now, let’s look at few properties that are part of the "Items" property which lists the prices for azure services.

• retailPrice

"retailPrice": 0.029088

This property provides the price of the azure service before any discounts. However, this normally goes hand in hand with another property of the response “unitOfMeasure” which we will be looking at next.

• unitOfMeasure

"unitOfMeasure": "1 Hour"

The “unitOfMeasure” property provides information about how the usage is measured for the azure service. In our sample API response, we have a list of prices for virtual machines, and the price measured is by an hour. However, the “unitOfMeasure” can differ by azure service and by region as well.

For example, Below is the price for a storage service of meter name “Cool LRS Data Stored” and product type of “General Block Blob v2 Hierarchical Namespace”. Here the retail price listed is by “unitOfMeasure” of “1 GB/Month”.

{ "currencyCode": "USD", "tierMinimumUnits": 0.0, "retailPrice": 0.01, "unitPrice": 0.01, "armRegionName": "southcentralus", "location": "US South Central", "effectiveStartDate": "2020-03-01T00:00:00Z", "meterId": "004fc717-c1ff-4ea8-8aa4-f4d657db61e3", "meterName": "Cool LRS Data Stored", "productId": "DZH318Z0C120", "skuId": "DZH318Z0C120/0039", "productName": "General Block Blob v2 Hierarchical Namespace", "skuName": "Cool LRS", "serviceName": "Storage", "serviceId": "DZH317F1HKN0", "serviceFamily": "Storage", "unitOfMeasure": "1 GB/Month", "type": "Consumption", "isPrimaryMeterRegion": true, "armSkuName": ""        }

Here is another property that’s part of the API response.

• Consumption

"type": "Consumption"

This property shows you the price type of the service. Below are the price types that you can expect in the API response.

• Consumption • Reservation • DevTestConsumption

Here is the table that maps API price type to the information shown on the Azure price calculator portal.

API Price TypeAzure Price Calculator Type
ConsumptionPay as you go
Reservation1 year or 3 years reserved
DevTestConsumptionShow Dev/Test Pricing

To view definitions of all the properties that are part of the API response., please visit the Microsoft documentation webpage using the link below.

https://docs.microsoft.com/en-us/rest/api/cost-management/retail-prices/azure-retail-prices#api-property-details

In this section, we looked at a typical azure retail prices API response and saw a breif overview of few properties that are part of the response.

In the next section, we will compare an azure service retail price returned as part of the API to the Azure Price calculator portal.

Compare API response to Azure price calculator portal

Below is the retail price provided as part of the Azure Retail Prices API response for a local redundant cool blob storage service in the south central u.s region.

{ "currencyCode": "USD", "tierMinimumUnits": 0.0, "retailPrice": 0.01, "unitPrice": 0.01, "armRegionName": "southcentralus", "location": "US South Central", "effectiveStartDate": "2020-03-01T00:00:00Z", "meterId": "004fc717-c1ff-4ea8-8aa4-f4d657db61e3", "meterName": "Cool LRS Data Stored", "productId": "DZH318Z0C120", "skuId": "DZH318Z0C120/0039", "productName": "General Block Blob v2 Hierarchical Namespace", "skuName": "Cool LRS", "serviceName": "Storage", "serviceId": "DZH317F1HKN0", "serviceFamily": "Storage", "unitOfMeasure": "1 GB/Month", "type": "Consumption", "isPrimaryMeterRegion": true, "armSkuName": ""        }

Here is the same service pulled on the Azure Price calculator portal.

In this section, we compared a price provided by the API for an azure service to the same service pulled on the azure price calculator portal.

In the next section, we will list the properties that we can use as part of the API request to filter the price list.

Azure Retail Prices API – Available filters

Calling the API endpoint as-is will result in getting the prices for all the azure services across different geographical locations. However, the need to pull all the prices might be rare or even nonexistent. To reduce the data returned by the API, Microsoft provides us the capability to filter on certain properties. According to the Microsoft documentation, here are the filters supported by the API as of now.

  • Region
  • ARM
  • Name
  • Location
  • meterId
  • meterName
  • productid
  • skuId
  • productName
  • skuName
  • serviceName
  • serviceId
  • serviceFamily
  • priceType
  • armSkuName

In the next section, we will look at a couple of API requests with filters applied based on the list that's provided in this section.

Azure Retail Prices API – Filter Examples

API Request:

https://prices.azure.com/api/retail/prices?$filter=serviceName eq 'Storage' and armRegionName eq 'southcentralus'

The above request returns the retail prices for the service name of type “Storage” and in the region “South Central US”.

API Request:

https://prices.azure.com/api/retail/prices?$filter=contains(serviceName,'Kubernetes') and armRegionName eq 'southcentralus'

The above request returns the retail prices for any Kubernetes service in the “South Central US" region.

Azure Retail Prices API supports OData $filter. Here is the OData documentation for supported operators for the $filter, scroll to section 4.5. However, not all operators are supported by the API as of now since all properties returned as part of the API response are not supported.

https://www.odata.org/documentation/odata-version-2-0/uri-conventions/

In this section, we looked at a couple of API requests with filters applied to retrieve prices based on our requirements. Retrieving prices by applying filters is a good practice since the need to look at all the azure prices is very rare.

In the next section, we will look at a use case to retrieve the prices based on a requirement and pull the list into an excel file.

Export Prices to Excel

Below is the link to the github repo which contains a python script to call the Azure Retail Prices API, parse the API response, and store the retail prices in an excel file for further analysis.

GitHub Repo:

https://github.com/santhoshkanala/azureretailpricesapi

The python script calls the azure retails prices api to retrieve prices for virtual machines in the south central u.s region and exports the prices to an excel file.

API Request:

https://prices.azure.com/api/retail/prices?$filter= armRegionName eq 'southcentralus' and serviceName eq 'Virtual Machines'

Here is a screenshot of the retail prices exported into an excel file for API request:

If you want to explore further, You can modify the API request in the script with your own filters based on your needs and export the results to excel.

Microsoft Documentation

Here is the link to Microsoft's official documentation webpage.

https://docs.microsoft.com/en-us/rest/api/cost-management/retail-prices/azure-retail-prices

References

Azure Price Calculator Portal: https://azure.microsoft.com/en-us/pricing/calculator/

Azure Portal: https://portal.azure.com

OData: https://www.odata.org/documentation/odata-version-2-0/uri-conventions/

Conclusion

In this post, you looked at the different ways to retrieve prices for an azure service and got familiarity with the API provided by Microsoft to retrieve prices for azure services in bulk and ways to apply filters to the API and finally were provided with a script to export prices to an excel file if needed.

Now you have an overview of Azure Retail Prices API and can use it to pull the prices of azure services either to integrate it with your existing internal tools for cost evaluation or just to explore further based on your requirement and make informed decisions on your azure service provisioning.