# Authentication - Checkly Docs

> How to authenticate with the Checkly CLI

Source: https://www.checklyhq.com/docs/cli/authentication/

---

Back to top
- Interactive
- Working with several accounts
- From CI
- Troubleshooting

Getting Started

# Authentication

How to authenticate with the Checkly CLI

This page describes Checkly CLI version 10 and later.

Before you can use the Checkly CLI, you need to authenticate with your Checkly account. There are different ways to authenticate depending on the environment where you are running the CLI from.

## Interactive

When **running the CLI interactively** from your dev environment, just use the built-in `login` command. It shows a URL and a code
that you can open in a browser on any device, so it also works over SSH and from AI agents. If you have multiple
Checkly accounts, it will prompt which account you want to target.
Terminal

```
npx checkly login
```

Once authenticated, you can switch between accounts using:
Terminal

```
npx checkly switch
```

… or quickly find out which account you are currently targeting with:
Terminal

```
npx checkly whoami
```

To log out and clear your stored credentials:
Terminal

```
npx checkly logout
```

## Working with several accounts

Your `checkly login` belongs to you, not to one account, so it works with every account you’re a member of. Commands use your default account, which you choose when you log in and change with `checkly switch`. `checkly whoami` lists your accounts and their IDs.
To use another account for a single command without changing the default, set `CHECKLY_ACCOUNT_ID` on that command:
Terminal

```
CHECKLY_ACCOUNT_ID=a43... npx checkly test-sessions get
```

Set in your shell, or in a `.env` file in the directory you run the CLI from, `CHECKLY_ACCOUNT_ID` applies to every command until you remove it. A project can use this to pin its account while each developer logs in with their own `checkly login`. A value on the command line wins over `.env`.

## From CI

You can also authenticate using environment variables, which is useful for CI/CD pipelines and automated environments.
You will need to export two environment variables in the shell:

- `CHECKLY_API_KEY`

- `CHECKLY_ACCOUNT_ID`

`CHECKLY_API_KEY` takes precedence over a stored login, and `checkly login` refuses to run while it’s set. Always set both variables: without `CHECKLY_ACCOUNT_ID`, the CLI uses the default account from your last `checkly login`, and on its own `CHECKLY_ACCOUNT_ID` only picks the account for your login.
To get your API key, go to your Settings page in Checkly and grab a API key from [the API keys tab](https://app.checklyhq.com/settings/user/api-keys) and your Account ID from the [Account settings tab](https://app.checklyhq.com/settings/account/general).
Set the account ID and API key as follows:
Terminal

```
# Set your Checkly API key
export CHECKLY_API_KEY=your_api_key_here

# Set your Checkly account ID
export CHECKLY_ACCOUNT_ID=your_account_id_here
```

To verify you’re properly authenticated:
Terminal

```
npx checkly whoami
```

This will display your account information and confirm your authentication status.

## Troubleshooting

`npx checkly login` doesn't open a browser window

`npx checkly login` prints the login URL and a code. If no browser window opens, open the URL in a browser on any device and enter the code.

Was this page helpful?

[Suggest edits](https://github.com/checkly/docs/edit/main/cli/authentication.mdx)[Raise issue](https://github.com/checkly/docs/issues/new?title=Issue%20on%20docs&body=Path:%20/cli/authentication)

[Installation Previous](https://www.checklyhq.com/docs/cli/installation)[Environment variables Next](https://www.checklyhq.com/docs/cli/environment-variables)

[x](https://x.com/checklyhq)[github](https://github.com/checkly)[linkedin](https://linkedin.com/company/checkly)

[Powered by This documentation is built and hosted on Mintlify, a developer documentation platform](https://www.mintlify.com/?utm_campaign=poweredBy&utm_medium=referral&utm_source=checkly-422f444a)
