> ## Documentation Index
> Fetch the complete documentation index at: https://docs.costgraph.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Infracost CLI

> Price Infracost estimates at the rates your CostGraph bill shows

CostGraph serves the pricing requests the Infracost CLI makes. Point the CLI at
CostGraph and its estimates use the prices you pay, not list prices.

## Before you begin

* A CostGraph API key with the `pricing:read` scope. Create one in
  **Settings > API keys**. Add `focus:read` to price resources that already exist
  from your bill.
* An Infracost API key, to price AWS, Azure, and Google Cloud resources. Without
  one, see [Without an Infracost key](#without-an-infracost-key).

## Connect your Infracost key

In CostGraph, open Integrations, choose Infracost, and paste the API key your
Infracost CLI already uses. Print it with `infracost configure get api_key`.
Connecting a new key replaces the old one. You need to be an organization owner,
admin, or billing admin.

## Point the CLI at CostGraph

Set two environment variables before you run `infracost`. The value is your
CostGraph API key, not your Infracost key.

<Tabs>
  <Tab title="CLI v0.10">
    ```shell theme={null}
    export INFRACOST_PRICING_API_ENDPOINT=https://api.costgraph.ai/api/v1/tenant/infracost
    export INFRACOST_API_KEY=bl_your_key
    ```
  </Tab>

  <Tab title="CLI v2">
    ```shell theme={null}
    export INFRACOST_CLI_PRICING_ENDPOINT=https://api.costgraph.ai/api/v1/tenant/infracost
    export INFRACOST_CLI_PRICING_API_KEY=bl_your_key
    ```
  </Tab>
</Tabs>

Run `infracost breakdown` as usual.

## What changes

AWS, Azure, and Google Cloud prices come from Infracost with your key. Other
providers come from CostGraph prices.

Prices reflect what your bill shows you pay for each SKU over the last 30 days.
SKUs you haven't used yet show list price.

Bill-rate adjustment applies to AWS. Azure and Google Cloud show list price.

## Price other providers

Infracost does not price every provider. CostGraph prices Terraform resources from providers it skips, and shows what the same machine costs elsewhere, at your account's rates where CostGraph has your bill.

### Run it in GitHub Actions

The CostGraph Terraform cost action prices your plan and keeps one comment on the pull request, updated on every run. Store an API key from **Settings > Account > API keys** as the secret `COSTGRAPH_API_KEY`.

```yaml theme={null}
permissions:
  contents: read
  pull-requests: write

jobs:
  plan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v5
      - uses: hashicorp/setup-terraform@v3
        with:
          terraform_wrapper: false

      - name: Plan
        run: |
          terraform init -input=false
          terraform plan -input=false -out=tfplan
          terraform show -json tfplan > plan.json

      - uses: baselinehq/costgraph-action/terraform-cost@v0
        with:
          api-key: ${{ secrets.COSTGRAPH_API_KEY }}
          plan-path: plan.json
```

The action needs no cloud credentials. List several plans in `plan-path`, one per line, to review several Terraform projects in one comment. It also sets the outputs `total-monthly-cost`, `previous-monthly-cost` and `diff-monthly-cost`.

To keep the estimate as a file, set `artifact-name: cost-estimate` and download it from the workflow run, or read the `estimate-path` output in a later step. The file uses the Infracost JSON format, so Infracost's own commands can read it.

To show what a pull request's CI runs cost in a second comment, see [Show CI cost on pull requests](/costgraph/integrations/github#show-ci-cost-on-pull-requests).

### What the comment shows

* **Monthly cost** of every priced resource. For a plan that changes existing resources, the previous cost and the change are shown too.
* **Same shape elsewhere**, a table of cheaper alternatives for every priced server, with size (vCPU, memory, GPUs), monthly cost and savings. It covers AWS, Azure and Google Cloud compute (EC2, EKS node groups, Azure VMs, Compute Engine). Alternatives are on the same continent, run the same operating system, and compare spot with spot.
* **Not priced**, a list of resources the plan cannot price, each with a reason. They are not counted as \$0.

### AWS, Azure and Google Cloud

Connect your Infracost API key in CostGraph to price AWS, Azure and Google Cloud at your bill rates. Without it, CostGraph prices what its catalog covers and lists the rest under "Not priced". The key stays in CostGraph, so the workflow only needs `COSTGRAPH_API_KEY`.

### Verified prices

Connect your AWS or Google Cloud billing export and CostGraph prices each line at what you paid for that product over the last 30 days. That includes your discounts and commitments. Lines priced from your bill are marked :white\_check\_mark: in the pull request comment and show `bill` in the CLI's SOURCE column. Other lines use public list prices. Products you have not used yet are priced at list price until they appear on your bill.

Resources that already exist are priced at what they cost on your bill over the last 30 days, scaled to a month. Reserved instance and savings plan discounts are included. When a commitment covers the resource, the comment says which one. Resources that Terraform is creating, or changing in a way that changes their price, keep the estimate. This needs an API key with `focus:read`; without it the comment keeps the estimates and the job log says why. Outside GitHub Actions, pass the plan with `--plan plan.json` to `costgraph cost output` or `costgraph cost comment github`.

### Run it in other CI systems

Install the CLI with `uses: baselinehq/costgraph-action@v0` in GitHub Actions, or [install the CostGraph CLI](/costgraph/developers/cli) in any other CI system. Then create a plan file and run the commands:

```shell theme={null}
terraform plan -out plan.out
terraform show -json plan.out > plan.json
costgraph cost breakdown --path plan.json
```

| Command | What it does |
| - | - |
| `costgraph cost breakdown --path plan.json` | Prices the resources in the plan. |
| `costgraph cost diff --path plan.json` | Shows the cost change the plan makes. |
| `costgraph cost output --path infracost.json --path costgraph.json --plan plan.json --format github-comment` | Combines an Infracost result and a CostGraph result into one, pricing resources that already exist from your bill. |
| `costgraph cost comment github --path infracost.json --path costgraph.json --repo owner/name --pull-request 12` | Posts one pull request comment, or updates it if it exists. |
| `costgraph cost setup-infracost` | Prints the environment variables the Infracost CLI needs. |

To set up the Infracost CLI in your shell, run `eval "$(costgraph cost setup-infracost)"`. To keep the values in a file, run `costgraph cost setup-infracost --write infracost.env`, then `set -a; . ./infracost.env; set +a`.

### Supported providers

* Hetzner Cloud: servers and volumes
* DigitalOcean: Droplets and volumes
* Linode (Akamai): instances, volumes, and managed MySQL and PostgreSQL
* Vultr: instances and block storage
* Scaleway: instances and block volumes
* STACKIT: servers, volumes, and PostgreSQL Flex
* OVHcloud: volumes
* Oracle Cloud: fixed-shape instances and block volumes
* IBM Cloud: VPC instances and volumes
* Alibaba Cloud: instances and disks
* UpCloud: servers and storage
* Civo: volumes
* Exoscale: instances and block storage volumes

### Not priced by CostGraph

A resource that CostGraph cannot price is still listed, with the reason. For example, its size may only be known after apply. CostGraph does not count it as \$0.

### Other providers for the same server

For priced servers, the output can show the same shape at other providers. Add `--no-alternatives` to turn this off.

## Without an Infracost key

AWS, Azure, and Google Cloud lines are priced from CostGraph prices where
CostGraph has the exact item. Other lines show as not found.

## Errors

| Message | What to do |
| - | - |
| Infracost rejected the connected API key; reconnect it in CostGraph | Connect a valid Infracost key again. |
| Infracost pricing is unavailable; retry | Run the command again. |
| CostGraph did not accept this API key | INFRACOST\_API\_KEY must be a CostGraph API key with pricing read access, not your Infracost key. |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.