This page shows you how to get started with the Cost Estimation API, and includes examples of API requests for common cost scenarios. If you want to use the Google Cloud console, learn how to get estimates in the Google Cloud console
You can use the Cost Estimation API to get an idea of the costs for hypothetical workloads. For example, if you want to budget for a new application, the API helps you estimate how much the infrastructure for the application might cost over time. You can also get an estimate that includes credits from a committed use discount (CUD).
The API supports estimates for the following services:
- Compute Engine
- Cloud Storage
- CDN Interconnect
- Cloud CDN
- VPC
If you have a negotiated pricing contract, you can also estimate your costs with your negotiated prices.
Before you begin
To call the API, get an API key.
If you want to get estimates with your contract prices, you must have the
billing.accounts.getPricing
permission. If you're calling the API using a service account, the service account must have the permission.The following predefined roles have the
billing.accounts.getPricing
permission:- Billing Account Administrator
- Billing Account Viewer
Optionally, enable discount sharing for your CUDs. If you don't enable discount sharing and your usage occurs in a project that isn't part of the commitment, your estimated costs and actual costs might differ significantly.
Understand the components of an estimate
When you're defining your workloads for a cost estimate, consider these factors:
Workload: Represents your use of a single Google Cloud product for the timeframe of the estimate. For example, a workload might be An n2 Compute Engine virtual machine for 1 week.
In your API request, you define a list of workloads in the
workloads
object.Cost Scenario: A collection of workloads, representing the Google Cloud products that your application needs. For example, a cost scenario might be 5 n2 virtual machines and 4 Gibibytes (GiB) of Cloud Storage for one week.
In your API request, you configure your cost scenario in the
costScenario
object, which includes your time frame and list of workloads.Time frame: The duration that you want to estimate costs for. You can get estimates for durations between 1 hour and 10 years.
In your API request, you define the time frame using the
estimateDuration
object.Time segments: You can split your estimate into time segments, where your usage varies over a certain period of time. For example, you can request an estimate for a time frame of four weeks, during which you start with 5 VMs for a week, then increase to 8 VMs for two weeks, and reduce to 3 VMs for the final week.
In your API request, you define time segments using the
usageRateTimeline
object, and setting the start of a segment usingestimationTimeFrameOffset
.Usage: Represents the amount of usage during a time segment. For example, you might define a time segment of 5 days, during which you want to use 6 Gibibytes (GiB) in a Cloud Storage bucket.
In your API request, you specify usage using the
usage
object. When you make your API request, if you provide an incorrect unit for usage, the error message includes the correct unit.
Limitations
The workloads that you can model using the API cannot perfectly mirror your real-world usage patterns. For example, you can model workloads that change hourly using the API, but Compute Engine usage is recorded at the microsecond level.
The estimates model usage that occurs in a single project. If you have committed use discounts (CUDs) and have enabled discount sharing across multiple projects, the fees and credits for the CUD are attributed across all projects that use the service. For example, if project A consumed $75 worth of usage and project B consumed $25, project A would be covered by up to 75% of available credit and project B would be covered by up to 25%.
If your usage occurs towards the end of a month, that usage might be recorded in the next invoice month.
The estimates don't include the cost of networking attached to the Compute Engine VMs in your cost scenario.
The estimates don't account for Sustained Use Discounts (SUDs).
The estimates don't account for credits on your account, such as promotional credits, or discounts from private offers on Cloud Marketplace.
The estimates don't account for future changes in pricing for Google Cloud products.
Example cost scenarios
The following examples show API calls for getting cost estimates. For detailed information on the request format, see the API reference.
In the API response, the net estimated costs are in the following objects:
segmentTotalCostEstimate
: The estimated cost for a time segment.workloadTotalCostEstimate
: The estimated cost for a workload.
Estimate the cost of virtual machines at list price
The following API request gets the estimate for 5 custom n1 virtual machines (VMs), at list price, for 100 hours of usage.
In the request, usageRate
indicates how many resources are part of the cost
scenario.
Before using any of the request data, make the following replacements:
- API_KEY: Your Google Cloud API key
HTTP method and URL:
POST https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY
Request JSON body:
{ "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" } } ] } }
To send your request, choose one of these options:
curl
Save the request body in a file named request.json
.
Run the following command in the terminal to create or overwrite
this file in the current directory:
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
Then execute the following command to send your REST request:
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
Save the request body in a file named request.json
.
Run the following command in the terminal to create or overwrite
this file in the current directory:
@' { "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
Then execute the following command to send your REST request:
$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
, with
the following contents.
{ { "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" } } }
Estimate the cost of Cloud Storage use at contract price
The following API request gets the estimate for 1 month of 500 GibiBytes (GiB) in asia-southeast2, at a contract price:
Before using any of the request data, make the following replacements:
- BILLING_ACCOUNT_ID: Your Cloud Billing account ID. The account must have a custom pricing contract associated with it.
HTTP method and URL:
POST https://cloudbilling.googleapis.com/v1beta/billingAccounts/BILLING_ACCOUNT_ID:estimateCostScenario
Request JSON body:
{ "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" } } }
To send your request, choose one of these options:
curl
Save the request body in a file named request.json
.
Run the following command in the terminal to create or overwrite
this file in the current directory:
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
Then execute the following command to send your REST request:
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
Save the request body in a file named request.json
.
Run the following command in the terminal to create or overwrite
this file in the current directory:
@' { "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
Then execute the following command to send your REST request:
$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
, with
the following contents.
{ "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" } }
Estimate the cost of workloads that change over time
The following API request gets an estimate for 1 month of usage, with custom contract prices, for the following resources:
- 7000 GiB of storage
- 8 n2-standard-4 VMs
- 3 additional n2-standard-4 VMs 14 days into the month
This sample uses the estimationTimeFrameOffset
field to determine when a new
time segment starts. The number of VMs changes from 8
to 11
(usageRate
)
after 1209600 seconds (14 days), as shown in this snippet:
"usageRateTimeline": {
"usageRateTimelineEntries": [
{
"usageRate": 8
},
{
"usageRate": 11,
"effectiveTime": {
"estimationTimeFrameOffset": "1209600s"
}
}
]
Similarly, if you want to estimate the cost if your workload reduced to 3 VMs
20 days from the start of the time frame, you can add one more segment to
usageRateTimelineEntries
, shown in this example:
"usageRateTimeline": {
"usageRateTimelineEntries": [
{
"usageRate": 8
},
{
"usageRate": 11,
"effectiveTime": {
"estimationTimeFrameOffset": "1209600s"
}
}
{
"usageRate": 3,
"effectiveTime": {
"estimationTimeFrameOffset": "1728000s"
}
}
]
Before using any of the request data, make the following replacements:
- API_KEY: Your Google Cloud API key
HTTP method and URL:
POST https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY
Request JSON body:
{ "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" } } }
To send your request, choose one of these options:
curl
Save the request body in a file named request.json
.
Run the following command in the terminal to create or overwrite
this file in the current directory:
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
Then execute the following command to send your REST request:
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
Save the request body in a file named request.json
.
Run the following command in the terminal to create or overwrite
this file in the current directory:
@' { "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
Then execute the following command to send your REST request:
$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
, with
the following contents.
{ "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" } }
Estimate the cost of workloads when you have a committed use discount (CUD)
The following example shows an API request for an a2-megagpu VM, with an NVIDIA Tesla A100 GPU and an Extreme persistent disk, for 5 hours (18,000 seconds), with contract pricing and a 1-year commitment.
Before using any of the request data, make the following replacements:
- BILLING_ACCOUNT_ID: Your Cloud Billing account ID. The account must have a custom pricing contract associated with it.
HTTP method and URL:
POST https://cloudbilling.googleapis.com/v1beta/billingAccounts/BILLING_ACCOUNT_ID:estimateCostScenario
Request JSON body:
{ "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" } } }
To send your request, choose one of these options:
curl
Save the request body in a file named request.json
.
Run the following command in the terminal to create or overwrite
this file in the current directory:
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
Then execute the following command to send your REST request:
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
Save the request body in a file named request.json
.
Run the following command in the terminal to create or overwrite
this file in the current directory:
@' { "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
Then execute the following command to send your REST request:
$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
, with
the following contents. The estimate for the savings from the
CUD is in the `commitmentCostEstimates` object:
{ "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" } }
Estimate the cost of a VM with a premium license, at list price
The following example shows an API request for 5 custom n1 virtual machines with a premium license of Windows Server 2022 DC at list price, for 100 hours.
Before using any of the request data, make the following replacements:
- API_KEY: Your Google Cloud API key
HTTP method and URL:
POST https://cloudbilling.googleapis.com/v1beta:estimateCostScenario?key=API_KEY
Request JSON body:
{ "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" } } ] } }
To send your request, choose one of these options:
curl
Save the request body in a file named request.json
.
Run the following command in the terminal to create or overwrite
this file in the current directory:
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
Then execute the following command to send your REST request:
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
Save the request body in a file named request.json
.
Run the following command in the terminal to create or overwrite
this file in the current directory:
@' { "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
Then execute the following command to send your REST request:
$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
, with
the following contents.
{ "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" } }