Azure Spot VMs offer up to 90% savings compared to pay-as-you-go pricing. The catch? Your VM can be evicted with 30 seconds notice when Azure needs the capacity back. Making informed decisions about which SKUs to use requires two critical pieces of data: current spot prices and eviction rates.
Getting this data programmatically is surprisingly complicated.
The Easy Part: Current Spot Prices
Microsoft provides the Azure Retail Prices API - a completely public endpoint requiring no authentication:
https://prices.azure.com/api/retail/prices
Filter for spot VMs with:
serviceName eq 'Virtual Machines' and contains(meterName, 'Spot')
No API key. No subscription. No rate limits documented. It just works.
This gives you current spot pricing across all regions and SKUs. Simple enough.
The Hard Part: Eviction Rates
Here's where it gets complicated. Eviction rates - the probability your spot VM gets terminated - aren't in the public pricing API. They live in Azure Resource Graph, specifically the SpotResources table.
To query this, you need:
- An Azure subscription (any subscription works)
- Azure AD authentication
- Reader permissions on the subscription
The query looks deceptively simple:
SpotResources
| where type =~ 'microsoft.compute/skuspotevictionrate/location'
| project skuName = tostring(sku.name), location, evictionRate = tostring(properties.evictionRate)
Eviction rates come as ranges: 0-5%, 5-10%, 10-15%, 15-20%, and 20%+, representing hourly eviction probability based on 7-28 days of historical data.
The Scale Problem
Here's what makes this genuinely difficult: there are thousands of combinations.
- 60+ Azure regions
- Hundreds of VM SKUs per region
- Multiple OS types (Windows/Linux pricing differs)
- Prices change constantly
A full dataset easily exceeds 50,000 price points. The Retail API paginates at 1,000 items per request, and pagination has documented quirks - sometimes NextPageLink returns empty even when more data exists.
90-Day Price History
Want historical spot prices to identify trends? That's another Resource Graph query against a different resource type:
SpotResources
| where type =~ 'microsoft.compute/skuspotpricehistory/ostype/location'
This gives you 90 days of price history - useful for understanding price volatility, but it's yet another authenticated API call to manage.
The Gotchas That Will Bite You
After building tooling around these APIs, here's what we learned:
Filter values are case-sensitive in API version 2023-01-01-preview and later. Use 'Virtual Machines' exactly - 'virtual machines' returns nothing.
Some SKUs are periodically missing from the Retail API. A-series, Av2, BS, D, Dv2, F families have all shown intermittent gaps. If completeness matters, cross-reference with az vm list-skus.
B-series VMs don't support spot pricing at all. Neither do promo SKUs (Dv2Promo, NVPromo). They simply won't appear in spot queries.
Rate limiting exists but isn't documented. Add delays between paginated requests or you'll get empty responses.
Our Approach: AI-Powered Spot Analysis
At Caleta, we built an AI-powered solution that handles this complexity for you. Rather than wrestling with multiple APIs, authentication, and data aggregation, our chatbot queries the current spot pricing data through natural language.
Behind the scenes, we use Azure OpenAI with function calling to translate questions like "What's the cheapest 8-core VM in UK South with low eviction risk?" into the appropriate API calls. The system maintains a regularly-updated cache of pricing and eviction data, queried through our backend with minimal Reader permissions.
The result? You ask a question, you get an answer - without needing to understand the underlying API complexity or maintain your own data collection infrastructure.
When to Use Spot VMs
Even with good data, spot VMs aren't for everything:
Good candidates:
- Batch processing and CI/CD pipelines
- Dev/test environments
- Stateless web workers behind load balancers
- Machine learning training jobs with checkpointing
Poor candidates:
- Production databases
- Single-instance applications
- Anything that can't handle 30-second termination notices
Try It Yourself
Want to explore Azure Spot pricing without the API complexity? Our free assessment tool includes spot pricing analysis as part of our Azure cost review.
Or if you're building your own tooling, start with the Retail Prices API for current prices - it's genuinely easy. Add Resource Graph queries for eviction rates only if you need that data, and be prepared for the authentication overhead.
Need help optimising your Azure costs? Contact us for a free savings analysis.