本页面介绍如何开始使用 Cost Estimation API,并包含常见费用方案的 API 请求示例。如果您想使用 Google Cloud 控制台,请了解如何在 Google Cloud 控制台中获取估算费用。
您可以使用 Cost Estimation API 来获取假设性工作负载的费用。例如,如果您要获取新应用的预算,可以借助该 API 估算应用基础架构随时间推移产生的费用。您还可以获取考虑承诺使用折扣 (CUD) 赠金的估算费用。
此 API 支持以下服务的估算费用:
- Compute Engine
- Cloud Storage
- CDN 互连
- Cloud CDN
- VPC
如果您有协议价合同,则还可以使用协议价来估算费用。
准备工作
若要调用该 API,您需要先获取 API 密钥。
如果您要使用合同价格进行估算,则必须具有
billing.accounts.getPricing
权限。如果您要使用服务账号调用 API,则该服务账号必须具有相应权限。以下预定义角色提供
billing.accounts.getPricing
权限:- Billing Account Administrator
- Billing Account Viewer
(可选)为 CUD 启用折扣共享。如果未启用折扣共享,并且您的使用量发生在未涵盖在承诺范围的项目中,则估算费用和实际费用可能会存在很大差异。
了解估算费用的组成部分
定义工作负载来进行费用估算时,请考虑以下因素:
工作负载:表示单个 Google Cloud 产品在估算时间范围内的使用情况。例如,工作负载可能是 1 个 n2 Compute Engine 虚拟机,持续 1 周时间。
在 API 请求中,您可以在
workloads
对象中定义工作负载列表。费用方案:一组工作负载,代表您的应用所需的 Google Cloud 产品。例如,费用方案可能是 5 个 n2 虚拟机和 4 GiB 的 Cloud Storage 存储空间,持续 1 周时间。
在 API 请求中,您可以在
costScenario
对象中配置费用方案,其中包括时间范围和工作负载列表。时间范围:您要进行费用估算的时长。您可以获得 1 小时到 10 年之间的估算费用。
在 API 请求中,您可以使用
estimateDuration
对象定义时间范围。时间段:您可以将估算费用按时间段拆分,其中您的用量会根据特定时段而变化。例如,您可以请求对 4 周时长的费用进行估算,在此期间,您最一开始使用 5 个虚拟机持续一周,之后增加到 8 个虚拟机持续 2 周,最后一周则减少到 3 个虚拟机。
在 API 请求中,您可以使用
usageRateTimeline
对象定义时间段,并使用estimationTimeFrameOffset
设置时间段起点。用量:表示某个时间段内的用量。例如,您可以将时间段定义为 5 天,在此期间,要在 Cloud Storage 存储桶中使用 6 吉比字节 (GiB) 的存储空间。
在 API 请求中,您可以使用
usage
对象指定用量。当您发出 API 请求时,如果提供的用量单位不正确,错误消息将包含正确的单位。
限制
使用 API 建模的工作负载无法完全还原您的实际用量模式。例如,您可以使用 API 对每小时发生更改的工作负载进行建模,但 Compute Engine 的用量是以微秒为单位记录的。
估算过程会对单个项目中发生的用量进行建模。如果您有承诺使用折扣 (CUD) 并且已在多个项目中启用折扣共享,则 CUD 的费用和赠金将计入使用该服务的所有项目中。例如,如果项目 A 的使用费为 $75,项目 B 的使用费为 $25,则项目 A 最多可使用 75% 的可用赠金,项目 B 则最多可使用 25% 的可用赠金。
如果您的用量是在接近月底的时间发生,则该用量可能会被记录在下一个账单月份。
这些估算费用不含在费用方案中关联到 Compute Engine 虚拟机的网络的费用。
这些估算费用不计入持续使用折扣 (SUD)。
这些估算费用不计入您账号的赠金,例如促销赠金或 Cloud Marketplace 上的非公开优惠提供的折扣。
这些估算费用不会考虑 Google Cloud 产品未来价格的变化。
费用方案示例
以下示例展示了用于获取估算费用的 API 调用。如需详细了解请求格式,请参阅 API 参考文档。
在 API 响应中,可以在以下对象中找到净估算费用:
segmentTotalCostEstimate
:某个时间段的估算费用。workloadTotalCostEstimate
:某个工作负载的估算费用。
按定价估算虚拟机费用
以下 API 请求按定价获取 5 个自定义 n1 虚拟机 (VM) 100 小时用量的估算费用。
在该请求中,usageRate
表示费用方案中有多少资源。
在使用任何请求数据之前,请先进行以下替换:
- API_KEY:您的 Google Cloud API 密钥
HTTP 方法和网址:
POST https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY
请求 JSON 正文:
{ "costScenario": { "scenarioConfig": { "estimateDuration": "360000s" }, "workloads": [ { "name": "vm-example", "computeVmWorkload": { "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 5 } ] } }, "machineType": { "customMachineType": { "machineSeries": "n1", "virtualCpuCount": 4, "memorySizeGb": 4 } }, "region": "us-central1" } } ] } }
如需发送请求,请选择以下方式之一:
curl
将请求正文保存在名为 request.json
的文件中。
在终端中运行以下命令,在当前目录中创建或覆盖此文件:
cat > request.json << 'EOF' { "costScenario": { "scenarioConfig": { "estimateDuration": "360000s" }, "workloads": [ { "name": "vm-example", "computeVmWorkload": { "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 5 } ] } }, "machineType": { "customMachineType": { "machineSeries": "n1", "virtualCpuCount": 4, "memorySizeGb": 4 } }, "region": "us-central1" } } ] } } EOF
然后,执行以下命令以发送 REST 请求:
curl -X POST \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
--output cost-estimate.json \
"https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY"
PowerShell
将请求正文保存在名为 request.json
的文件中。
在终端中运行以下命令,在当前目录中创建或覆盖此文件:
@' { "costScenario": { "scenarioConfig": { "estimateDuration": "360000s" }, "workloads": [ { "name": "vm-example", "computeVmWorkload": { "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 5 } ] } }, "machineType": { "customMachineType": { "machineSeries": "n1", "virtualCpuCount": 4, "memorySizeGb": 4 } }, "region": "us-central1" } } ] } } '@ | Out-File -FilePath request.json -Encoding utf8
然后,执行以下命令以发送 REST 请求:
$headers = @{ }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-OutFile cost-estimate.json `
-Uri "https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY"
cost-estimate.json
的文件中,其中包含以下内容。{ { "costEstimationResult": { "segmentCostEstimates": [ { "segmentStartTime": { "estimationTimeFrameOffset": "0s" }, "workloadCostEstimates": [ { "name": "vm-example", "skuCostEstimates": [ { "sku": "services/6F81-5844-456A/skus/ACBC-6999-A1C4", "usageAmount": 2000, "usageUnit": "h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "66", "nanos": 348000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "66", "nanos": 348000000 } } }, { "sku": "services/6F81-5844-456A/skus/51E2-59BD-7A6E", "usageAmount": 2000, "usageUnit": "GiBy.h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 892000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 892000000 } } } ], "workloadTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "75", "nanos": 240000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "75", "nanos": 240000000 } } } ], "segmentTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "75", "nanos": 240000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "75", "nanos": 240000000 } } } ], "skus": [ { "sku": "services/6F81-5844-456A/skus/ACBC-6999-A1C4", "displayName": "Custom Instance Core running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 33174000 } } ], "unit": "h", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/51E2-59BD-7A6E", "displayName": "Custom Instance Ram running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 4446000 } } ], "unit": "GiBy.h", "unitCount": 1 } } ] } ], "currencyCode": "USD" } } }
按合同价估算 Cloud Storage 使用费
以下 API 会请求按合同价获取 asia-southeast2 位置 500 GiB 存储空间 1 个月的估算费用:
在使用任何请求数据之前,请先进行以下替换:
- BILLING_ACCOUNT_ID:您的 Cloud Billing 账号 ID。该账号必须具有与之关联的自定义合同。
HTTP 方法和网址:
POST https://cloudbilling.googleapis.com/v1beta/billingAccounts/BILLING_ACCOUNT_ID:estimateCostScenario
请求 JSON 正文:
{ "costScenario": { "workloads": [ { "name": "combined-example-storage", "cloudStorageWorkload": { "region": { "name": "us-central1" }, "storageClass": "archive", "dataStored": { "usageRateTimeline": { "unit": "GiBy", "usageRateTimelineEntries": [ { "usageRate": 7000 } ] } } } }, { "name": "combined-example-compute", "computeVmWorkload": { "machineType": { "predefinedMachineType": { "machineType": "n2-standard-4" } }, "region": "us-central1", "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 8 }, { "usageRate": 11, "effectiveTime": { "estimationTimeFrameOffset": "1209600s" } } ] } } } } ], "scenarioConfig": { "estimateDuration": "2628000s" } } }
如需发送请求,请选择以下方式之一:
curl
将请求正文保存在名为 request.json
的文件中。
在终端中运行以下命令,在当前目录中创建或覆盖此文件:
cat > request.json << 'EOF' { "costScenario": { "workloads": [ { "name": "combined-example-storage", "cloudStorageWorkload": { "region": { "name": "us-central1" }, "storageClass": "archive", "dataStored": { "usageRateTimeline": { "unit": "GiBy", "usageRateTimelineEntries": [ { "usageRate": 7000 } ] } } } }, { "name": "combined-example-compute", "computeVmWorkload": { "machineType": { "predefinedMachineType": { "machineType": "n2-standard-4" } }, "region": "us-central1", "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 8 }, { "usageRate": 11, "effectiveTime": { "estimationTimeFrameOffset": "1209600s" } } ] } } } } ], "scenarioConfig": { "estimateDuration": "2628000s" } } } EOF
然后,执行以下命令以发送 REST 请求:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
--output cost-estimate.json \
"https://cloudbilling.googleapis.com/v1beta/billingAccounts/BILLING_ACCOUNT_ID:estimateCostScenario"
PowerShell
将请求正文保存在名为 request.json
的文件中。
在终端中运行以下命令,在当前目录中创建或覆盖此文件:
@' { "costScenario": { "workloads": [ { "name": "combined-example-storage", "cloudStorageWorkload": { "region": { "name": "us-central1" }, "storageClass": "archive", "dataStored": { "usageRateTimeline": { "unit": "GiBy", "usageRateTimelineEntries": [ { "usageRate": 7000 } ] } } } }, { "name": "combined-example-compute", "computeVmWorkload": { "machineType": { "predefinedMachineType": { "machineType": "n2-standard-4" } }, "region": "us-central1", "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 8 }, { "usageRate": 11, "effectiveTime": { "estimationTimeFrameOffset": "1209600s" } } ] } } } } ], "scenarioConfig": { "estimateDuration": "2628000s" } } } '@ | Out-File -FilePath request.json -Encoding utf8
然后,执行以下命令以发送 REST 请求:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-OutFile cost-estimate.json `
-Uri "https://cloudbilling.googleapis.com/v1beta/billingAccounts/BILLING_ACCOUNT_ID:estimateCostScenario"
cost-estimate.json
的文件中,其中包含以下内容。{ "costEstimationResult": { "segmentCostEstimates": [ { "segmentStartTime": { "estimationTimeFrameOffset": "0s" }, "workloadCostEstimates": [ { "name": "combined-example-storage", "skuCostEstimates": [ { "sku": "services/95FF-2EF5-5EA1/skus/EC4B-C190-470D", "usageAmount": 7000, "usageUnit": "GiBy.mo", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 400000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 400000000 } } } ], "workloadTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 400000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 400000000 } } }, { "name": "combined-example-compute", "skuCostEstimates": [ { "sku": "services/6F81-5844-456A/skus/BB77-5FDA-69D9", "usageAmount": 28088, "usageUnit": "h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "887", "nanos": 889768000 }, "creditEstimates": [ { "creditAmount": { "currencyCode": "USD", "units": "-159", "nanos": -850504800 }, "creditType": "Sustained Use Discount" } ], "netCostEstimate": { "currencyCode": "USD", "units": "728", "nanos": 39263200 } } }, { "sku": "services/6F81-5844-456A/skus/5B01-D157-A097", "usageAmount": 112352, "usageUnit": "GiBy.h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "476", "nanos": 35424000 }, "creditEstimates": [ { "creditAmount": { "currencyCode": "USD", "units": "-85", "nanos": -702646400 }, "creditType": "Sustained Use Discount" } ], "netCostEstimate": { "currencyCode": "USD", "units": "390", "nanos": 332777600 } } } ], "workloadTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "1363", "nanos": 925192000 }, "creditEstimates": [ { "creditAmount": { "currencyCode": "USD", "units": "-245", "nanos": -553151200 }, "creditType": "Sustained Use Discount" } ], "netCostEstimate": { "currencyCode": "USD", "units": "1118", "nanos": 372040800 } } } ], "segmentTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "1372", "nanos": 325192000 }, "creditEstimates": [ { "creditAmount": { "currencyCode": "USD", "units": "-245", "nanos": -553151200 }, "creditType": "Sustained Use Discount" } ], "netCostEstimate": { "currencyCode": "USD", "units": "1126", "nanos": 772040800 } } } ], "skus": [ { "sku": "services/95FF-2EF5-5EA1/skus/EC4B-C190-470D", "displayName": "Archive Storage Iowa", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 1200000 } } ], "unit": "GiBy.mo", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/BB77-5FDA-69D9", "displayName": "N2 Instance Core running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 31611000 } } ], "unit": "h", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/5B01-D157-A097", "displayName": "N2 Instance Ram running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 4237000 } } ], "unit": "GiBy.h", "unitCount": 1 } } ] } ], "currencyCode": "USD" } }
估算会随时间变化的工作负载费用
以下 API 请求按自定义合同价获取以下资源 1 个月的估算使用费:
- 7000 GiB 存储空间
- 8 个 n2-standard-4 虚拟机
- 当月有 14 天需使用 3 个额外的 n2-standard-4 虚拟机
此示例使用 estimationTimeFrameOffset
字段来确定新时间段的起始时间。如以下代码段所示,1209600 秒(14 天)之后,虚拟机的数量由 8
变为 11
(usageRate
):
"usageRateTimeline": {
"usageRateTimelineEntries": [
{
"usageRate": 8
},
{
"usageRate": 11,
"effectiveTime": {
"estimationTimeFrameOffset": "1209600s"
}
}
]
同样,如果您想要工作负载在时间段开始 20 天后减少至 3 个虚拟机,这种情况下若要估算费用,您可以向 usageRateTimelineEntries
再添加一段代码,如以下示例所示:
"usageRateTimeline": {
"usageRateTimelineEntries": [
{
"usageRate": 8
},
{
"usageRate": 11,
"effectiveTime": {
"estimationTimeFrameOffset": "1209600s"
}
}
{
"usageRate": 3,
"effectiveTime": {
"estimationTimeFrameOffset": "1728000s"
}
}
]
在使用任何请求数据之前,请先进行以下替换:
- API_KEY:您的 Google Cloud API 密钥
HTTP 方法和网址:
POST https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY
请求 JSON 正文:
{ "costScenario": { "workloads": [ { "name": "combined-example-storage", "cloudStorageWorkload": { "region": { "name": "us-central1" }, "storageClass": "archive", "dataStored": { "usageRateTimeline": { "unit": "GiBy", "usageRateTimelineEntries": [ { "usageRate": 7000 } ] } } } }, { "name": "combined-example-compute", "computeVmWorkload": { "machineType": { "predefinedMachineType": { "machineType": "n2-standard-4" } }, "region": "us-central1", "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 8 }, { "usageRate": 11, "effectiveTime": { "estimationTimeFrameOffset": "1209600s" } } ] } } } } ], "scenarioConfig": { "estimateDuration": "2628000s" } } }
如需发送请求,请选择以下方式之一:
curl
将请求正文保存在名为 request.json
的文件中。
在终端中运行以下命令,在当前目录中创建或覆盖此文件:
cat > request.json << 'EOF' { "costScenario": { "workloads": [ { "name": "combined-example-storage", "cloudStorageWorkload": { "region": { "name": "us-central1" }, "storageClass": "archive", "dataStored": { "usageRateTimeline": { "unit": "GiBy", "usageRateTimelineEntries": [ { "usageRate": 7000 } ] } } } }, { "name": "combined-example-compute", "computeVmWorkload": { "machineType": { "predefinedMachineType": { "machineType": "n2-standard-4" } }, "region": "us-central1", "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 8 }, { "usageRate": 11, "effectiveTime": { "estimationTimeFrameOffset": "1209600s" } } ] } } } } ], "scenarioConfig": { "estimateDuration": "2628000s" } } } EOF
然后,执行以下命令以发送 REST 请求:
curl -X POST \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
--output cost-estimate.json \
"https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY"
PowerShell
将请求正文保存在名为 request.json
的文件中。
在终端中运行以下命令,在当前目录中创建或覆盖此文件:
@' { "costScenario": { "workloads": [ { "name": "combined-example-storage", "cloudStorageWorkload": { "region": { "name": "us-central1" }, "storageClass": "archive", "dataStored": { "usageRateTimeline": { "unit": "GiBy", "usageRateTimelineEntries": [ { "usageRate": 7000 } ] } } } }, { "name": "combined-example-compute", "computeVmWorkload": { "machineType": { "predefinedMachineType": { "machineType": "n2-standard-4" } }, "region": "us-central1", "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 8 }, { "usageRate": 11, "effectiveTime": { "estimationTimeFrameOffset": "1209600s" } } ] } } } } ], "scenarioConfig": { "estimateDuration": "2628000s" } } } '@ | Out-File -FilePath request.json -Encoding utf8
然后,执行以下命令以发送 REST 请求:
$headers = @{ }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-OutFile cost-estimate.json `
-Uri "https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY"
cost-estimate.json
的文件中,其中包含以下内容。{ "costEstimationResult": { "segmentCostEstimates": [ { "segmentStartTime": { "estimationTimeFrameOffset": "0s" }, "workloadCostEstimates": [ { "name": "combined-example-storage", "skuCostEstimates": [ { "sku": "services/95FF-2EF5-5EA1/skus/EC4B-C190-470D", "usageAmount": 7000, "usageUnit": "GiBy.mo", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 400000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 400000000 } } } ], "workloadTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 400000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 400000000 } } }, { "name": "combined-example-compute", "skuCostEstimates": [ { "sku": "services/6F81-5844-456A/skus/BB77-5FDA-69D9", "usageAmount": 28088, "usageUnit": "h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "887", "nanos": 889768000 }, "netCostEstimate": { "currencyCode": "USD", "units": "887", "nanos": 889768000 } } }, { "sku": "services/6F81-5844-456A/skus/5B01-D157-A097", "usageAmount": 112352, "usageUnit": "GiBy.h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "476", "nanos": 35424000 }, "netCostEstimate": { "currencyCode": "USD", "units": "476", "nanos": 35424000 } } } ], "workloadTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "1363", "nanos": 925192000 }, "netCostEstimate": { "currencyCode": "USD", "units": "1363", "nanos": 925192000 } } } ], "segmentTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "1372", "nanos": 325192000 }, "netCostEstimate": { "currencyCode": "USD", "units": "1372", "nanos": 325192000 } } } ], "skus": [ { "sku": "services/95FF-2EF5-5EA1/skus/EC4B-C190-470D", "displayName": "Archive Storage Iowa", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 1200000 } } ], "unit": "GiBy.mo", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/BB77-5FDA-69D9", "displayName": "N2 Instance Core running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 31611000 } } ], "unit": "h", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/5B01-D157-A097", "displayName": "N2 Instance Ram running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 4237000 } } ], "unit": "GiBy.h", "unitCount": 1 } } ] } ], "currencyCode": "USD" } }
估算具有承诺使用折扣 (CUD) 的工作负载的费用
以下示例中的 API 请求按合同价估算配备 NVIDIA Tesla A100 GPU 和极端永久性磁盘且具有 1 年承诺的 a2-megagpu 虚拟机的费用(使用时长 5 小时,即 18,000 秒)。
在使用任何请求数据之前,请先进行以下替换:
- BILLING_ACCOUNT_ID:您的 Cloud Billing 账号 ID。该账号必须具有与之关联的自定义合同。
HTTP 方法和网址:
POST https://cloudbilling.googleapis.com/v1beta/billingAccounts/BILLING_ACCOUNT_ID:estimateCostScenario
请求 JSON 正文:
{ "costScenario": { "workloads": [{ "name": "Custom VM", "computeVmWorkload": { "region": "us-central1", "machineType": { "predefinedMachineType": { "machineType": "a2-megagpu-16g" } }, "guestAccelerator": { "acceleratorType": "nvidia-tesla-a100", "acceleratorCount": "1" }, "persistentDisks": [{ "diskType": "pd-extreme", "scope": "SCOPE_ZONAL", "diskSize": { "usageRateTimeline": { "unit": "GiBy", "usageRateTimelineEntries": [{ "usageRate": 1000.0 }] } }, "provisionedIops": { "usageRateTimeline": { "usageRateTimelineEntries": [{ "usageRate": 15000.0 }] } } }], "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [{ "usageRate": 1.0 }] } } } }], "commitments": [{ "name": "VM commitment", "vmResourceBasedCud": { "region": "us-central1", "virtualCpuCount": "48", "memorySizeGb": 680.0, "plan": "TWELVE_MONTH", "machineSeries": "a2" } }], "scenarioConfig": { "estimateDuration": "18000s" } } }
如需发送请求,请选择以下方式之一:
curl
将请求正文保存在名为 request.json
的文件中。
在终端中运行以下命令,在当前目录中创建或覆盖此文件:
cat > request.json << 'EOF' { "costScenario": { "workloads": [{ "name": "Custom VM", "computeVmWorkload": { "region": "us-central1", "machineType": { "predefinedMachineType": { "machineType": "a2-megagpu-16g" } }, "guestAccelerator": { "acceleratorType": "nvidia-tesla-a100", "acceleratorCount": "1" }, "persistentDisks": [{ "diskType": "pd-extreme", "scope": "SCOPE_ZONAL", "diskSize": { "usageRateTimeline": { "unit": "GiBy", "usageRateTimelineEntries": [{ "usageRate": 1000.0 }] } }, "provisionedIops": { "usageRateTimeline": { "usageRateTimelineEntries": [{ "usageRate": 15000.0 }] } } }], "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [{ "usageRate": 1.0 }] } } } }], "commitments": [{ "name": "VM commitment", "vmResourceBasedCud": { "region": "us-central1", "virtualCpuCount": "48", "memorySizeGb": 680.0, "plan": "TWELVE_MONTH", "machineSeries": "a2" } }], "scenarioConfig": { "estimateDuration": "18000s" } } } EOF
然后,执行以下命令以发送 REST 请求:
curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
--output cost-estimate.json \
"https://cloudbilling.googleapis.com/v1beta/billingAccounts/BILLING_ACCOUNT_ID:estimateCostScenario"
PowerShell
将请求正文保存在名为 request.json
的文件中。
在终端中运行以下命令,在当前目录中创建或覆盖此文件:
@' { "costScenario": { "workloads": [{ "name": "Custom VM", "computeVmWorkload": { "region": "us-central1", "machineType": { "predefinedMachineType": { "machineType": "a2-megagpu-16g" } }, "guestAccelerator": { "acceleratorType": "nvidia-tesla-a100", "acceleratorCount": "1" }, "persistentDisks": [{ "diskType": "pd-extreme", "scope": "SCOPE_ZONAL", "diskSize": { "usageRateTimeline": { "unit": "GiBy", "usageRateTimelineEntries": [{ "usageRate": 1000.0 }] } }, "provisionedIops": { "usageRateTimeline": { "usageRateTimelineEntries": [{ "usageRate": 15000.0 }] } } }], "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [{ "usageRate": 1.0 }] } } } }], "commitments": [{ "name": "VM commitment", "vmResourceBasedCud": { "region": "us-central1", "virtualCpuCount": "48", "memorySizeGb": 680.0, "plan": "TWELVE_MONTH", "machineSeries": "a2" } }], "scenarioConfig": { "estimateDuration": "18000s" } } } '@ | Out-File -FilePath request.json -Encoding utf8
然后,执行以下命令以发送 REST 请求:
$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-OutFile cost-estimate.json `
-Uri "https://cloudbilling.googleapis.com/v1beta/billingAccounts/BILLING_ACCOUNT_ID:estimateCostScenario"
cost-estimate.json
的文件中,其中包含以下内容。您可以在“commitmentCostEstimates”对象中找到通过 CUD 节省的估算费用:
{ "costEstimationResult": { "segmentCostEstimates": [ { "segmentStartTime": { "estimationTimeFrameOffset": "0s" }, "workloadCostEstimates": [ { "name": "Custom VM", "skuCostEstimates": [ { "sku": "services/6F81-5844-456A/skus/2922-40C5-B19F", "usageAmount": 480, "usageUnit": "h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "15", "nanos": 173280000 }, "creditEstimates": [ { "creditAmount": { "currencyCode": "USD", "units": "-7", "nanos": -586640000 }, "creditType": "Committed Use Discount" } ], "netCostEstimate": { "currencyCode": "USD", "units": "7", "nanos": 586640000 } } }, { "sku": "services/6F81-5844-456A/skus/2390-DCAF-DA38", "usageAmount": 6800, "usageUnit": "GiBy.h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "28", "nanos": 811600000 }, "creditEstimates": [ { "creditAmount": { "currencyCode": "USD", "units": "-6", "nanos": -609720000 }, "creditType": "Committed Use Discount" } ], "netCostEstimate": { "currencyCode": "USD", "units": "22", "nanos": 201880000 } } }, { "sku": "services/6F81-5844-456A/skus/039F-D0DA-4055", "usageAmount": 5, "usageUnit": "h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "14", "nanos": 669540000 }, "netCostEstimate": { "currencyCode": "USD", "units": "14", "nanos": 669540000 } } }, { "sku": "services/6F81-5844-456A/skus/165B-942F-F345", "usageAmount": 6.8493150684931505, "usageUnit": "GiBy.mo", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "nanos": 856164383 }, "netCostEstimate": { "currencyCode": "USD", "nanos": 856164383 } } }, { "sku": "services/6F81-5844-456A/skus/DCA4-F1BE-57C4", "usageAmount": 102.73972602739725, "usageUnit": "mo", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "6", "nanos": 678082191 }, "netCostEstimate": { "currencyCode": "USD", "units": "6", "nanos": 678082191 } } } ], "workloadTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "66", "nanos": 188666574 }, "creditEstimates": [ { "creditAmount": { "currencyCode": "USD", "units": "-14", "nanos": -196360000 }, "creditType": "Committed Use Discount" } ], "netCostEstimate": { "currencyCode": "USD", "units": "51", "nanos": 992306574 } } } ], "segmentTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "75", "nanos": 131906574 }, "creditEstimates": [ { "creditAmount": { "currencyCode": "USD", "units": "-14", "nanos": -196360000 }, "creditType": "Committed Use Discount" } ], "netCostEstimate": { "currencyCode": "USD", "units": "60", "nanos": 935546574 } }, "commitmentCostEstimates": [ { "name": "VM commitment", "skuCostEstimates": [ { "sku": "services/6F81-5844-456A/skus/3A31-931E-6360", "usageAmount": 240, "usageUnit": "h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "4", "nanos": 779600000 }, "netCostEstimate": { "currencyCode": "USD", "units": "4", "nanos": 779600000 } } }, { "sku": "services/6F81-5844-456A/skus/220C-35D0-70E0", "usageAmount": 1560, "usageUnit": "GiBy.h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "4", "nanos": 163640000 }, "netCostEstimate": { "currencyCode": "USD", "units": "4", "nanos": 163640000 } } } ], "commitmentTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 943240000 }, "netCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 943240000 } } } ] } ], "skus": [ { "sku": "services/6F81-5844-456A/skus/3A31-931E-6360", "displayName": "Commitment v1: A2 Cpu in Americas for 1 Year", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 19915000 } } ], "unit": "h", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/220C-35D0-70E0", "displayName": "Commitment v1: A2 Ram in Americas for 1 Year", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 2669000 } } ], "unit": "GiBy.h", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/039F-D0DA-4055", "displayName": "Nvidia Tesla A100 GPU running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "units": "2", "nanos": 933908000 } } ], "unit": "h", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/165B-942F-F345", "displayName": "Extreme PD Capacity", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 125000000 } } ], "unit": "GiBy.mo", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/DCA4-F1BE-57C4", "displayName": "Extreme PD IOPS", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 65000000 } } ], "unit": "mo", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/2922-40C5-B19F", "displayName": "A2 Instance Core running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 31611000 } } ], "unit": "h", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/2390-DCAF-DA38", "displayName": "A2 Instance Ram running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 4237000 } } ], "unit": "GiBy.h", "unitCount": 1 } } ] } ], "currencyCode": "USD" } }
按定价估算具有付费许可的虚拟机的费用
以下示例中的 API 请求按定价估算具有 Windows Server 2022 DC 付费许可的 5 个自定义 n1 虚拟机的费用(使用时长 100 小时)。
在使用任何请求数据之前,请先进行以下替换:
- API_KEY:您的 Google Cloud API 密钥
HTTP 方法和网址:
POST https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY
请求 JSON 正文:
{ "costScenario": { "scenarioConfig": { "estimateDuration": "360000s" }, "workloads": [ { "name": "vm-example", "computeVmWorkload": { "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 5 } ] } }, "machineType": { "customMachineType": { "machineSeries": "n1", "virtualCpuCount": 4, "memorySizeGb": 4 } }, "region": "us-central1", "licenses": "projects/windows-cloud/global/licenses/windows-server-2022-dc" } } ] } }
如需发送请求,请选择以下方式之一:
curl
将请求正文保存在名为 request.json
的文件中。
在终端中运行以下命令,在当前目录中创建或覆盖此文件:
cat > request.json << 'EOF' { "costScenario": { "scenarioConfig": { "estimateDuration": "360000s" }, "workloads": [ { "name": "vm-example", "computeVmWorkload": { "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 5 } ] } }, "machineType": { "customMachineType": { "machineSeries": "n1", "virtualCpuCount": 4, "memorySizeGb": 4 } }, "region": "us-central1", "licenses": "projects/windows-cloud/global/licenses/windows-server-2022-dc" } } ] } } EOF
然后,执行以下命令以发送 REST 请求:
curl -X POST \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
--output cost-estimate.json \
"https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY"
PowerShell
将请求正文保存在名为 request.json
的文件中。
在终端中运行以下命令,在当前目录中创建或覆盖此文件:
@' { "costScenario": { "scenarioConfig": { "estimateDuration": "360000s" }, "workloads": [ { "name": "vm-example", "computeVmWorkload": { "instancesRunning": { "usageRateTimeline": { "usageRateTimelineEntries": [ { "usageRate": 5 } ] } }, "machineType": { "customMachineType": { "machineSeries": "n1", "virtualCpuCount": 4, "memorySizeGb": 4 } }, "region": "us-central1", "licenses": "projects/windows-cloud/global/licenses/windows-server-2022-dc" } } ] } } '@ | Out-File -FilePath request.json -Encoding utf8
然后,执行以下命令以发送 REST 请求:
$headers = @{ }
Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-OutFile cost-estimate.json `
-Uri "https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY"
cost-estimate.json
的文件中,其中包含以下内容。{ "costEstimationResult": { "segmentCostEstimates": [ { "segmentStartTime": { "estimationTimeFrameOffset": "0s" }, "workloadCostEstimates": [ { "name": "vm-example", "skuCostEstimates": [ { "sku": "services/6F81-5844-456A/skus/ACBC-6999-A1C4", "usageAmount": 2000, "usageUnit": "h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "66", "nanos": 348000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "66", "nanos": 348000000 } } }, { "sku": "services/6F81-5844-456A/skus/51E2-59BD-7A6E", "usageAmount": 2000, "usageUnit": "GiBy.h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 892000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "8", "nanos": 892000000 } } }, { "sku": "services/6F81-5844-456A/skus/92D2-8A8F-DF54", "usageAmount": 2000, "usageUnit": "h", "costEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "92" }, "netCostEstimate": { "currencyCode": "USD", "units": "92" } } } ], "workloadTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "167", "nanos": 240000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "167", "nanos": 240000000 } } } ], "segmentTotalCostEstimate": { "preCreditCostEstimate": { "currencyCode": "USD", "units": "167", "nanos": 240000000 }, "netCostEstimate": { "currencyCode": "USD", "units": "167", "nanos": 240000000 } } } ], "skus": [ { "sku": "services/6F81-5844-456A/skus/92D2-8A8F-DF54", "displayName": "Licensing Fee for Windows Server 2022 Datacenter Edition on VM", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 46000000 } } ], "unit": "h", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/ACBC-6999-A1C4", "displayName": "Custom Instance Core running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 33174000 } } ], "unit": "h", "unitCount": 1 } } ] }, { "sku": "services/6F81-5844-456A/skus/51E2-59BD-7A6E", "displayName": "Custom Instance Ram running in Americas", "prices": [ { "priceType": "RATE", "rate": { "tiers": [ { "price": { "currencyCode": "USD", "nanos": 4446000 } } ], "unit": "GiBy.h", "unitCount": 1 } } ] } ], "currencyCode": "USD" } }