You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行az consumption usage list报错,如何获取Azure各区域消费/成本?

解决Azure区域消费/成本数据获取问题

错误原因

你遇到的400错误是因为默认使用的API版本低于2019-10-01,订阅级别的用量查询需要更高版本的API支持;另外consumption命令组目前处于预览阶段,功能稳定性不如正式版命令。

解决方案

1. 指定API版本使用consumption命令

在原命令中添加--api-version参数,指定2019-10-01之后的稳定版本(比如2021-10-01):

az consumption usage list --api-version 2021-10-01 --query "[?properties.instanceLocation=='swedensouth'].{Resource:properties.instanceName, Cost:properties.pretaxCost}" --output table

2. 使用正式版costmanagement命令(推荐)

az costmanagement是正式发布的命令组,功能更稳定,适合查询区域成本数据:

  • 查询指定区域(如瑞典南部)的资源及对应成本:
az costmanagement query --type ActualCost --dataset-aggregation "[{'name':'PreTaxCost','function':'Sum'}]" --dataset-grouping "[{'name':'ResourceLocation','type':'Dimension'},{'name':'ResourceName','type':'Dimension'}]" --filter "ResourceLocation eq 'swedensouth'" --output table
  • 查询所有区域的消费数据,只需移除--filter参数:
az costmanagement query --type ActualCost --dataset-aggregation "[{'name':'PreTaxCost','function':'Sum'}]" --dataset-grouping "[{'name':'ResourceLocation','type':'Dimension'},{'name':'ResourceName','type':'Dimension'}]" --output table

内容的提问来源于stack exchange,提问作者Melissa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.29 08:32:39