Infracost API
The majority of users should use the Infracost CLI, which does not send the Terraform statefile to the open-source Cloud Pricing API; instead it sends the relevant data for finding a unique cloud price point.
The API described in this page can be useful for CI/CD integrations, such as Atlantis, where 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 the CLI 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 https://pricing.api.infracost.io/terraform-json-file with the terraform-json-file
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.
Parameter | Description | Required? | Notes |
---|---|---|---|
terraform-json-file | Terraform plan JSON file | Yes | Use '@' to upload the file with curl, e.g. -F "terraform-json-file=@plan.json" |
usage-file | Infracost usage file that specifies values for usage-based resources | No | Use '@' to upload the file with curl, e.g. -F "usage-file=@infracost-usage.yml" |
show-skipped | Show unsupported resources, some of which might be free. Only for table and HTML output | No | Defaults to false |
output | Output format: json, table, html | No | Defaults to table and returns a text/plain response. If output is set to json , an application/json response is returned; and if output is set to html , a text/html response is returned. |
no-color | Turn off colored output, useful for table output or Windows users (color output has a bug we need to fix on Windows) | No | Defaults to false |
- Example request
- Table response
- JSON response
- HTML response
Tip: You can use jq
to extract values. For example, to see the total monthly cost increase of a project you can use:
Here is an example of the full JSON output:
