Blog Logo
TAGS

Azure Cost CLI

This is a simple command line tool to get the cost of your Azure subscription. It uses the Azure Cost Management API to get the cost and output the results to the console or JSON. E.g. so it can be used in a workflow to get the cost of your subscription and use it in subsequent steps. You can install this tool globally, using the dotnet tool command. When there is a new version available on NuGet, you can use the `dotnet tool update` command to upgrade. You can invoke the tool using the `azure-cost` command. If the application is not working properly, you can use the `--debug` parameter to increase the logging verbosity and see more details. This tool uses the Azure Cost Management API to get the cost. Not all subscriptions have access to this API. To check if your subscription has access, you can use the `az account subscription show --subscription-id yourid --query [subscriptionPolicies.quotaId] -o tsv` command. Validate the resulting quota id with the ones on the [Microsoft list](https://learn.microsoft.com/en-us/azure/cost-management-billing/costs/understand-cost-mgt-data#supported-microsoft-azure-offers) to see if it is supported. There is a pretty strict rate limit on the cost api; the calls are retried after a 429 is received, but it might take a while before the call succeeds as it honors the retry time out.