question

MarkWhitney-7466 avatar image
1 Vote"
MarkWhitney-7466 asked ·

Querying prices for Azure Spot VMs

Is there a way to query the current Azure Spot VM price for a specific VM family/type + region?

azure-spot
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

msrini-MSFT avatar image
0 Votes"
msrini-MSFT answered ·

Hi,

Azure Spot VMs pricing are not constant and the pricing changes periodically. As of now, there are no established API available for the consumers to check the current pricing for Spot instances.

But you can check the pricing from Azure portal. You need to select Create New VM --> Select Region and Azure Spot to Yes --> Click on Change Size.

You can see the current price for each size in the region which you have selected.

· 4 · Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks, understood. It would be helpful in the future to be able to query the current price via API/SDK.

3 Votes 3 · ·

Can we get an API?

2 Votes 2 · ·

Thanks @MarkWhitney-7466 and @gpoort for the feedback regarding API.
I have shared this feedback with the product team as a feature request.

0 Votes 0 · ·

I've found two very kludgy methods:

  1. There is a private API that the portal calls called GetCurrentSpotPricing that you can use Portal credentials to retrieve programatically. It is extremely not easy to use, and in the 3 days of hourly checks that I've been monitoring it, the prices haven't changed at all. These are the prices shown in the azure portal.

  2. Try creating a VM with a max price of 0.00001, the error message will tell you what the current spot price is. e.g.

    "Unable to perform operation 'Create VM' since the provided max price '1E-05 USD' is lower than the current spot price '0.014683 USD' for Azure Spot VM size 'Standard_DS1_v2'

In my limited testing so far this price does not match the portal price, so either the portal price is an inaccurate guess or something else is going on here.



0 Votes 0 · ·
MarkScu-1297 avatar image
1 Vote"
MarkScu-1297 answered ·

There's now a public API that will return pricing, including that for Spot VMs - https://docs.microsoft.com/rest/api/cost-management/retail-prices/azure-retail-prices

The result set is large, so I'd highly recommend using filtering to only request prices for VMs and Consumption pricing; e.g. https://prices.azure.com/api/retail/prices?$skip=0&$filter=serviceName%20eq%20%27Virtual%20Machines%27%20and%20priceType%20eq%20%27Consumption%27

The API does return the results in batches (up to 100 at a time when I tried), so you'll need a mechanism to handle paging to get all the results.

· Share
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.