Source: https://datafa.st/docs/cli-introduction
Markdown source: https://datafa.st/docs/cli-introduction.md
Description: Install and authenticate the DataFast CLI to query analytics and manage your account from the terminal.

# DataFast CLI — Get started

The DataFast CLI lets you query analytics, manage websites, tokens, alerts, and funnels directly from your terminal. Useful for AI agents and LLMs 🤖

> See [DataFast package on NPM](https://www.npmjs.com/package/@datafast/cli)

## 1. Run or install

Run the CLI without installing it:

```sh
npx @datafast/cli login
bunx @datafast/cli login
```

Or install it globally if you plan to use it often:

```sh
npm install -g @datafast/cli
```

This installs the `datafast` binary globally.

## 2. Authenticate

Use the login command to authenticate the CLI. It will open your [DataFast account](https://datafa.st/dashboard/settings?tab=api) page in your browser, prompt you to create an account token, and paste it into the CLI.

```sh
datafast login
```

> The token is saved locally at `~/.config/datafast/config.json`.

By default, `datafast login` uses a `dft_` account token so the CLI can manage your DataFast account. If you only want analytics access for one website, you can use a `df_` website API key instead. Read the [permissions & roles guide](/docs/cli-permissions) for the full difference.

## 3. Use (commands)

Most commands are interactive when you omit IDs or required flags. For example, `datafast analytics overview` prompts you to choose a website when using a `dft_` account token, and `datafast websites update` opens a guided editor. Press `Ctrl+C` at any prompt to exit cleanly.

- [Manage websites](/docs/cli-websites)
- [Manage tokens](/docs/cli-tokens)
- [Query analytics](/docs/cli-analytics)
- [Get visitor details](/docs/cli-visitors)
- [Manage alerts](/docs/cli-alerts)
- [Manage funnels](/docs/cli-funnels)
- [Set up shell completion](/docs/cli-completion)

And more to come... DataFast aims to give your AI agent full control over your DataFast account.

## More about the CLI

### Permissions & roles

Read more about [roles & permissions](/docs/cli-permissions)

### Log out

```sh
datafast logout
```

Removes the saved token from `~/.config/datafast/config.json`.

### Global flags

These flags work with every command:

| Flag | Description |
|---|---|
| `--json` | Compact JSON output (default: pretty-printed) |
| `--verbose` | Print the request URL and response status to stderr |

```sh
# Compact JSON output — pipe it into jq, save to file, etc.
datafast --json websites list | jq '.[].domain'
```

### Environment variables (override the saved config)

```sh
DATAFAST_TOKEN=dft_xxx            # user token
DATAFAST_SITE_KEY=df_xxx          # analytics-only site key
DATAFAST_API_BASE=http://localhost:3000  # default: https://datafa.st
```

### Other ways to authenticate

```sh
# Pipe the token via stdin (great for CI)
echo $MY_TOKEN | datafast login

# Pass it inline (avoid: it leaks into shell history)
datafast login --token dft_xxx
```
