Skip to main content

Plan JSON API

note

The majority of users should use the Infracost CLI, which does not send the Terraform plan file to the Cloud Pricing API; instead it sends cost-related parameters, such as the instance type or disk size, so cloud prices can be found.

We plan to move and open source the API described in this page to the Cloud Pricing API, as it can be useful for CI/CD integrations such as Atlantis. In such cases, it might be easier to use curl or an HTTP library instead of installing the Infracost CLI. Terraform plan JSON files can be sent to this API, which runs infracost and returns the results. Whilst this API deletes files from the server after they are processed, it is a good security practice to remove secrets from the file before sending it to the API. For example, AWS provides a grep command that can be used to do this.

To use this API, send an HTTP POST request to desired endpoint (e.g. https://pricing.api.infracost.io/diff) with a Terraform plan JSON file sent in the path parameter using the multipart/form-data request body format, as shown in the following example curl request. The x-api-key header must be set to your Infracost API key.

Breakdown

Show full breakdown of costs.

Send an HTTP POST to: https://pricing.api.infracost.io/breakdown

HeaderDescriptionNotes
x-api-keyInfracost API KeyRequired. Must be set to your Infracost API key.
ParameterDescriptionNotes
pathTerraform plan JSON fileRequired. Use '@' to upload the file with curl, e.g. -F "path=@plan.json"
usage-fileInfracost usage file that specifies values for usage-based resourcesNot required. Use '@' to upload the file with curl, e.g. -F "usage-file=@infracost-usage.yml"
show-skippedShow unsupported resources.Not required. Defaults to false
no-colorTurn off colored output, useful for CI/CD usersNot required. Defaults to false
formatContent type of the responseNot required. Must be one of table, html or json. Defaults to table
fieldsFields to include in the responseNot required, supported by table and html formats. Must be a comma separated list of fields: all, price, monthlyQuantity, unit, hourlyCost, monthlyCost. Defaults to monthlyQuantity,unit,monthlyCost

Examples

cd path/to/code
terraform init
terraform plan -out tfplan.binary
terraform show -json tfplan.binary > plan.json

curl -X POST -H "x-api-key: my-api-key" -F "ci-platform=atlantis" \
-F "path=@plan.json" \
https://pricing.api.infracost.io/breakdown

Diff

Show diff of monthly costs between current and planned state.

Send an HTTP POST to: https://pricing.api.infracost.io/diff

HeaderDescriptionNotes
x-api-keyInfracost API KeyRequired. Must be set to your Infracost API key.
ParameterDescriptionNotes
pathTerraform plan JSON fileRequired. Use '@' to upload the file with curl, e.g. -F "path=@plan.json"
usage-fileInfracost usage file that specifies values for usage-based resourcesNot required. Use '@' to upload the file with curl, e.g. -F "usage-file=@infracost-usage.yml"
show-skippedShow unsupported resources.Not required. Defaults to false
no-colorTurn off colored output, useful for CI/CD usersNot required. Defaults to false

Examples

cd path/to/code
terraform init
terraform plan -out tfplan.binary
terraform show -json tfplan.binary > plan.json

curl -X POST -H "x-api-key: my-api-key" -F "ci-platform=atlantis" \
-F "path=@plan.json" \
https://pricing.api.infracost.io/diff