> ## Documentation Index
> Fetch the complete documentation index at: https://checkly-422f444a-simo-red-943-deploy-plan-docs.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Authentication

> How to authenticate with the Checkly CLI

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.

```bash Terminal theme={null}
npx checkly login
```

Once authenticated, you can switch between accounts using:

```bash Terminal theme={null}
npx checkly switch
```

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

```bash Terminal theme={null}
npx checkly whoami
```

To log out and clear your stored credentials:

```bash Terminal theme={null}
npx checkly logout
```

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

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:

```bash Terminal theme={null}
# 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:

```bash Terminal theme={null}
npx checkly whoami
```

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

## Troubleshooting

<AccordionGroup>
  <Accordion title="`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.
  </Accordion>
</AccordionGroup>


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