> ## 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.

# Configure the CostGraph CLI

> Choose the CostGraph API, inspect configuration sources, return JSON, and enable shell completion

Configure the CLI for your deployment and choose how commands return their results. Settings and saved browser credentials live in separate files.

## Inspect configuration

Use these commands to inspect local settings.

### Configuration file path

Print the configuration file path.

```shell theme={null}
costgraph config path
```

The default path is `~/.config/costgraph/config.toml`.

### Effective settings

Print the effective settings and their sources.

```shell theme={null}
costgraph config list
```

The table identifies each setting, its value, and whether it comes from the environment, a file, or a default. API-key values are masked.

### One setting

To read one setting, pass its name.

```shell theme={null}
costgraph config get api.base_url
```

## Set a file value

Create a configuration file with defaults if you do not already have one.

```shell theme={null}
costgraph config init
```

The command refuses to overwrite an existing file. Its `--force` option replaces that file with defaults.

The following command changes the saved default output format.

```shell theme={null}
costgraph config set defaults.output json
```

An environment variable still overrides the corresponding file value. Use `costgraph config list` to check which value applies.

## Configure a self-hosted deployment

Set `COSTGRAPH_API_URL` before signing in or creating an API key. Use your deployment's API address, rather than its dashboard address.

```shell theme={null}
export COSTGRAPH_API_URL="https://api.costgraph.example.com"
costgraph auth login
```

A saved browser session belongs to the deployment where you approved it. Sign out before switching an existing installation to another deployment, then sign in to that deployment.

The management API and pricing service have separate settings. Changing `COSTGRAPH_API_URL` does not change `COSTGRAPH_PRICING_URL`.

## Supported settings

The following table maps file settings to their environment variables.

| File setting | Environment variable | Default |
| - | - | - |
| `api.base_url` | `COSTGRAPH_API_URL` | `https://api.costgraph.ai` |
| `api.pricing_url` | `COSTGRAPH_PRICING_URL` | `https://pricing.baselinehq.cloud` |
| `api.api_key` | `COSTGRAPH_API_KEY` | Not set. |
| `api.callback_port` | `COSTGRAPH_CALLBACK_PORT` | `9093` |
| `defaults.output` | `COSTGRAPH_OUTPUT` | `table` |
| `telemetry.enabled` | `COSTGRAPH_TELEMETRY` | `true` |

For a setting with a command-line flag, the flag takes precedence over its environment variable and file value. For example, `-o table` overrides `COSTGRAPH_OUTPUT=json`. There is no global `--api-url` flag.

Use `COSTGRAPH_API_KEY` or your CI secret store instead of saving a key in the configuration file. A saved browser session takes precedence over the API key. Refer to [Credentials](https://docs.costgraph.ai/costgraph/cli/overview.md#credentials) for how the CLI chooses its credential.

## Select configuration and credential files

The following options control where the CLI reads its files.

| Input | Effect |
| - | - |
| `--config PATH` | Selects a configuration file for this command. |
| `COSTGRAPH_CONFIG` | Selects a configuration file when `--config` is absent. |
| `COSTGRAPH_CONFIG_DIR` | Selects the default directory for configuration and credentials. |
| `XDG_CONFIG_HOME` | Uses its `costgraph` subdirectory when `COSTGRAPH_CONFIG_DIR` is absent. |
| `COSTGRAPH_CREDENTIALS` | Selects the saved browser credential file. |

If these directory overrides are absent, the CLI uses `~/.config/costgraph`. Credentials default to `credentials.toml` in that directory. Changing `--config` alone does not select a different saved browser session.

To use a separate configuration file for a command, pass its path.

```shell theme={null}
costgraph --config ./costgraph.toml config list
```

## Choose an output format

Data commands such as `cost get`, `tags list`, and `recommendations list` support `table` and `json` output. Add `-o json` for structured data.

```shell theme={null}
costgraph cost get --group-by provider -o json
```

JSON output disables the interactive cost browser. Supply the arguments and flags the command needs. A missing value can cause an error rather than a prompt.

Local commands such as `config path` and `config get` print a path or value. Completion commands print a shell script. Cost-estimate commands also have format-specific options. Check the [Command reference](https://docs.costgraph.ai/costgraph/cli/reference.md) rather than assuming every command returns JSON.

During sign-in and key approval, browser instructions go to standard error so a script can capture the JSON result from standard output. Refer to [Capture the key in a script](https://docs.costgraph.ai/costgraph/cli/api-keys.md#capture-the-key-in-a-script).

## Generate shell completion

The CLI generates completion scripts for Bash, fish, PowerShell, and zsh. The following command writes a zsh completion script to a local file.

```shell theme={null}
costgraph completion zsh > _costgraph
```

This creates the file but does not install it into your shell. Run `costgraph completion zsh --help` for the instructions for your system. Replace `zsh` with `bash`, `fish`, or `powershell` for the other supported scripts.

## Disable usage telemetry

To disable CLI telemetry for the current shell, set the following variable.

```shell theme={null}
export COSTGRAPH_TELEMETRY=false
```

You can also set `telemetry.enabled` to `false` in the file. `DO_NOT_TRACK=true` disables telemetry even when another setting enables it.

## Check the installed release

Run the following command to print the installed version.

```shell theme={null}
costgraph version
```

If a documented command or flag is missing, compare that version with the release you intended to install. Refer to [Install and sign in](https://docs.costgraph.ai/costgraph/cli/install.md#install) for upgrade and PATH checks.

## Command reference

Commands are shown without the `costgraph` prefix. Add `--help` for the complete flag list.

### Read local settings

Run each command with the `costgraph` prefix.

**config path** `command`

Prints the configuration file path.

**config list** `command`

Lists settings and their sources. Masks API key values.

**config get \<key>** `command`

Prints one setting as a value.

### Write local settings

These commands change the local configuration file.

**config init** `command`

Creates defaults. Refuses to overwrite an existing file unless you pass `--force`.

**config set \<key> \<value>** `command`

Changes a supported setting. An environment override still takes precedence.

### Shell completion and version

Completion commands print scripts. Follow each command's `--help` to install its output.

**completion bash** `command`

Generates Bash completion. Requires `bash-completion`.

**completion zsh** `command`

Generates zsh completion.

**completion fish** `command`

Generates fish completion.

**completion powershell** `command`

Generates PowerShell completion.

**version** `command`

Prints the version, commit, and build time.


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