获取 Google Cloud 工作负载的估算费用

本页面介绍如何开始使用 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% 的可用赠金。

    了解如何计算 CUD 赠金分配

  • 如果您的用量是在接近月底的时间发生,则该用量可能会被记录在下一个帐单月份。

  • 这些估算费用不含在费用方案中关联到 Compute Engine 虚拟机的网络的费用。

  • 这些估算费用不计入持续使用折扣 (SUD)

  • 这些估算费用不计入您帐号的赠金,例如促销赠金或 Cloud Marketplace 上的非公开优惠提供的折扣。

  • 这些估算费用不会考虑 Google Cloud 产品未来价格的变化。

费用方案示例

以下示例展示了用于获取估算费用的 API 调用。如需详细了解请求格式,请参阅 API 参考文档

在 API 响应中,可以在以下对象中找到净估算费用:

  • segmentTotalCostEstimate:某个时间段的估算费用。
  • workloadTotalCostEstimate:某个工作负载的估算费用。

按定价估算虚拟机费用

以下 API 请求按定价获取 5 个自定义 n1 虚拟机 (VM) 100 小时用量的估算费用。

在该请求中,usageRate 表示费用方案中有多少资源。

POST https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=BILLING_ACCOUNT_ID HTTP/1.1

Accept: application/json
Content-Type: application/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"
        }
      }
    ]
  }
}

预期响应如下所示:

点击展开示例响应。

{
  "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 个月的估算费用:

POST https://cloudbilling.googleapis.com/v1beta/billingAccounts/BILLING_ACCOUNT_ID:estimateCostScenario HTTP/1.1

Authorization: Bearer API_ACCESS_TOKEN
Accept: application/json
Content-Type: application/json

{
  "costScenario": {
    "workloads": [
      {
        "name": "storage-example",
        "cloudStorageWorkload": {
          "storageClass": "archive",
          "dataStored": {
            "usageRateTimeline": {
              "unit": "GiBy",
              "usageRateTimelineEntries": [
                {
                  "usageRate": 500
                }
              ]
            }
          },
          "region": {
            "name": "asia-southeast2"
          }
        }
      }
    ],
    "scenarioConfig": {
      "estimateDuration": "2628000s"
    }
  }
}

预期响应如下所示:

点击展开示例响应。

{
  "costEstimationResult": {
    "segmentCostEstimates": [
      {
        "segmentStartTime": {
          "estimationTimeFrameOffset": "0s"
        },
        "workloadCostEstimates": [
          {
            "name": "storage-example",
            "skuCostEstimates": [
              {
                "sku": "services/95FF-2EF5-5EA1/skus/62E5-3AA6-3149",
                "usageAmount": 493.15068493150687,
                "usageUnit": "GiBy.mo",
                "costEstimate": {
                  "preCreditCostEstimate": {
                    "currencyCode": "USD",
                    "units": "1",
                    "nanos": 232876712
                  },
                  "netCostEstimate": {
                    "currencyCode": "USD",
                    "units": "1",
                    "nanos": 232876712
                  }
                }
              }
            ],
            "workloadTotalCostEstimate": {
              "preCreditCostEstimate": {
                "currencyCode": "USD",
                "units": "1",
                "nanos": 232876712
              },
              "netCostEstimate": {
                "currencyCode": "USD",
                "units": "1",
                "nanos": 232876712
              }
            }
          }
        ],
        "segmentTotalCostEstimate": {
          "preCreditCostEstimate": {
            "currencyCode": "USD",
            "units": "1",
            "nanos": 232876712
          },
          "netCostEstimate": {
            "currencyCode": "USD",
            "units": "1",
            "nanos": 232876712
          }
        }
      }
    ],
    "skus": [
      {
        "sku": "services/95FF-2EF5-5EA1/skus/62E5-3AA6-3149",
        "displayName": "Archive Storage Jakarta",
        "prices": [
          {
            "priceType": "RATE",
            "rate": {
              "tiers": [
                {
                  "price": {
                    "currencyCode": "USD",
                    "nanos": 2500000
                  }
                }
              ],
              "unit": "GiBy.mo",
              "unitCount": 1
            }
          }
        ]
      }
    ],
    "currencyCode": "USD"
  }
}
    

估算会随时间变化的工作负载费用

以下 API 请求按自定义合同价获取以下资源 1 个月的估算使用费

  • 7000 GiB 存储空间
  • 8 个 n2-standard-4 虚拟机
  • 当月有 14 天需使用 3 个额外的 n2-standard-4 虚拟机
POST https://cloudbilling.googleapis.com/v1beta/billingAccounts/BILLING_ACCOUNT_ID:estimateCostScenario HTTP/1.1

Authorization: Bearer API_ACCESS_TOKEN
Accept: application/json
Content-Type: application/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"
    }
  }
}

此示例使用 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"
      }
    }
  ]

预期响应如下所示:

点击展开示例响应。

{
  "costEstimationResult": {
    "segmentCostEstimates": [
      {
        "segmentStartTime": {
          "estimationTimeFrameOffset": "0s"
        },
        "workloadCostEstimates": [
          {
            "name": "combined-example-storage",
            "skuCostEstimates": [
              {
                "sku": "services/95FF-2EF5-5EA1/skus/EC4B-C190-470D",
                "usageAmount": 6904.1095890410961,
                "usageUnit": "GiBy.mo",
                "costEstimate": {
                  "preCreditCostEstimate": {
                    "currencyCode": "USD",
                    "units": "8",
                    "nanos": 284931506
                  },
                  "netCostEstimate": {
                    "currencyCode": "USD",
                    "units": "8",
                    "nanos": 284931506
                  }
                }
              }
            ],
            "workloadTotalCostEstimate": {
              "preCreditCostEstimate": {
                "currencyCode": "USD",
                "units": "8",
                "nanos": 284931506
              },
              "netCostEstimate": {
                "currencyCode": "USD",
                "units": "8",
                "nanos": 284931506
              }
            }
          },
          {
            "name": "combined-example-compute",
            "skuCostEstimates": [
              {
                "sku": "services/6F81-5844-456A/skus/BB77-5FDA-69D9",
                "usageAmount": 27648,
                "usageUnit": "h",
                "costEstimate": {
                  "preCreditCostEstimate": {
                    "currencyCode": "USD",
                    "units": "873",
                    "nanos": 980928000
                  },
                  "netCostEstimate": {
                    "currencyCode": "USD",
                    "units": "873",
                    "nanos": 980928000
                  }
                }
              },
              {
                "sku": "services/6F81-5844-456A/skus/5B01-D157-A097",
                "usageAmount": 110592,
                "usageUnit": "GiBy.h",
                "costEstimate": {
                  "preCreditCostEstimate": {
                    "currencyCode": "USD",
                    "units": "468",
                    "nanos": 578304000
                  },
                  "netCostEstimate": {
                    "currencyCode": "USD",
                    "units": "468",
                    "nanos": 578304000
                  }
                }
              }
            ],
            "workloadTotalCostEstimate": {
              "preCreditCostEstimate": {
                "currencyCode": "USD",
                "units": "1342",
                "nanos": 559232000
              },
              "netCostEstimate": {
                "currencyCode": "USD",
                "units": "1342",
                "nanos": 559232000
              }
            }
          }
        ],
        "segmentTotalCostEstimate": {
          "preCreditCostEstimate": {
            "currencyCode": "USD",
            "units": "1350",
            "nanos": 844163506
          },
          "netCostEstimate": {
            "currencyCode": "USD",
            "units": "1350",
            "nanos": 844163506
          }
        }
      }
    ],
    "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 秒)。

POST https://cloudbilling.googleapis.com/v1beta/billingAccounts/BILLING_ACCOUNT_ID:estimateCostScenario HTTP/1.1

Authorization: Bearer API_ACCESS_TOKEN
Accept: application/json
Content-Type: application/json

{
  "costScenario": {
    "workloads": [{
      "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": [{
      "vmResourceBasedCud": {
        "region": "us-central1",
        "virtualCpuCount": "48",
        "memorySizeGb": 680.0,
        "plan": "TWELVE_MONTH",
        "machineSeries": "a2"
      }
    }],
    "scenarioConfig": {
      "estimateDuration": "18000s"
    }
  }
}

预期响应如下所示。您可以在 commitmentCostEstimates 对象中找到通过 CUD 节省的估算费用:

点击展开示例响应。

{
  "costEstimationResult": {
    "segmentCostEstimates": [
      {
        "segmentStartTime": {
          "estimationTimeFrameOffset": "0s"
        },
        "workloadCostEstimates": [
          {
            "name": "workload",
            "skuCostEstimates": [
              {
                "sku": "services/6F81-5844-456A/skus/2922-40C5-B19F",
                "usageAmount": 533.33333333333337,
                "usageUnit": "h",
                "costEstimate": {
                  "preCreditCostEstimate": {
                    "currencyCode": "USD",
                    "units": "16",
                    "nanos": 859200000
                  },
                  "creditEstimates": [
                    {
                      "creditAmount": {
                        "currencyCode": "USD",
                        "units": "-8",
                        "nanos": -429600000
                      },
                      "creditType": "Committed Use Discount"
                    }
                  ],
                  "netCostEstimate": {
                    "currencyCode": "USD",
                    "units": "8",
                    "nanos": 429600000
                  }
                }
              },
              {
                "sku": "services/6F81-5844-456A/skus/2390-DCAF-DA38",
                "usageAmount": 7555.5555555555557,
                "usageUnit": "GiBy.h",
                "costEstimate": {
                  "preCreditCostEstimate": {
                    "currencyCode": "USD",
                    "units": "32",
                    "nanos": 12888888
                  },
                  "creditEstimates": [
                    {
                      "creditAmount": {
                        "currencyCode": "USD",
                        "units": "-7",
                        "nanos": -344133333
                      },
                      "creditType": "Committed Use Discount"
                    }
                  ],
                  "netCostEstimate": {
                    "currencyCode": "USD",
                    "units": "24",
                    "nanos": 668755555
                  }
                }
              },
              {
                "sku": "services/6F81-5844-456A/skus/039F-D0DA-4055",
                "usageAmount": 5.5555555555555554,
                "usageUnit": "h",
                "costEstimate": {
                  "preCreditCostEstimate": {
                    "currencyCode": "USD",
                    "units": "16",
                    "nanos": 299488888
                  },
                  "netCostEstimate": {
                    "currencyCode": "USD",
                    "units": "16",
                    "nanos": 299488888
                  }
                }
              },
              {
                "sku": "services/6F81-5844-456A/skus/165B-942F-F345",
                "usageAmount": 7.6103500761035008,
                "usageUnit": "GiBy.mo",
                "costEstimate": {
                  "preCreditCostEstimate": {
                    "currencyCode": "USD",
                    "nanos": 951293759
                  },
                  "netCostEstimate": {
                    "currencyCode": "USD",
                    "nanos": 951293759
                  }
                }
              },
              {
                "sku": "services/6F81-5844-456A/skus/DCA4-F1BE-57C4",
                "usageAmount": 114.15525114155251,
                "usageUnit": "mo",
                "costEstimate": {
                  "preCreditCostEstimate": {
                    "currencyCode": "USD",
                    "units": "7",
                    "nanos": 420091324
                  },
                  "netCostEstimate": {
                    "currencyCode": "USD",
                    "units": "7",
                    "nanos": 420091324
                  }
                }
              }
            ],
            "workloadTotalCostEstimate": {
              "preCreditCostEstimate": {
                "currencyCode": "USD",
                "units": "73",
                "nanos": 542962859
              },
              "creditEstimates": [
                {
                  "creditAmount": {
                    "currencyCode": "USD",
                    "units": "-15",
                    "nanos": -773733333
                  },
                  "creditType": "Committed Use Discount"
                }
              ],
              "netCostEstimate": {
                "currencyCode": "USD",
                "units": "57",
                "nanos": 769229526
              }
            }
          }
        ],
        "segmentTotalCostEstimate": {
          "preCreditCostEstimate": {
            "currencyCode": "USD",
            "units": "83",
            "nanos": 479896191
          },
          "creditEstimates": [
            {
              "creditAmount": {
                "currencyCode": "USD",
                "units": "-15",
                "nanos": -773733333
              },
              "creditType": "Committed Use Discount"
            }
          ],
          "netCostEstimate": {
            "currencyCode": "USD",
            "units": "67",
            "nanos": 706162858
          }
        },
        "commitmentCostEstimates": [
          {
            "name": "test1",
            "skuCostEstimates": [
              {
                "sku": "services/6F81-5844-456A/skus/3A31-931E-6360",
                "usageAmount": 266.66666666666669,
                "usageUnit": "h",
                "costEstimate": {
                  "preCreditCostEstimate": {
                    "currencyCode": "USD",
                    "units": "5",
                    "nanos": 310666666
                  },
                  "netCostEstimate": {
                    "currencyCode": "USD",
                    "units": "5",
                    "nanos": 310666666
                  }
                }
              },
              {
                "sku": "services/6F81-5844-456A/skus/220C-35D0-70E0",
                "usageAmount": 1733.3333333333333,
                "usageUnit": "GiBy.h",
                "costEstimate": {
                  "preCreditCostEstimate": {
                    "currencyCode": "USD",
                    "units": "4",
                    "nanos": 626266666
                  },
                  "netCostEstimate": {
                    "currencyCode": "USD",
                    "units": "4",
                    "nanos": 626266666
                  }
                }
              }
            ],
            "commitmentTotalCostEstimate": {
              "preCreditCostEstimate": {
                "currencyCode": "USD",
                "units": "9",
                "nanos": 936933332
              },
              "netCostEstimate": {
                "currencyCode": "USD",
                "units": "9",
                "nanos": 936933332
              }
            }
          }
        ]
      }
    ],
    "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 小时)

POST https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=[YOUR_API_KEY] HTTP/1.1

Accept: application/json
Content-Type: application/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"
        }
      }
    ]
  }
}

预期响应如下所示:

点击展开示例响应。

{
  "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.0,
                "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": "GiBy.h",
              "unitCount": 1.0
            }
          }
        ]
      },
      {
        "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
            }
          }
        ]
      },
      {
        "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
            }
          }
        ]
      }
    ],
    "currencyCode": "USD"
  }
}