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

# Authenticate CLI commands

> Sign in to the Algolia CLI with OAuth, or provide your application ID and API key with environment variables or command-line flags.

Every CLI command that communicates with Algolia requires authentication.
We recommend **signing in with OAuth**, which stores your credentials automatically.
Alternatively, provide your Algolia application ID and API key with environment variables or command-line flags.

<Note>
  In general, use an API key with minimal permissions, just enough to run the commands you want to run.
  For more information, see [API keys](/doc/guides/security/api-keys#rights-and-restrictions).
</Note>

## Sign in with OAuth

Signing in with OAuth is the quickest way to get started.
The CLI stores your credentials for you, so you don't need to copy or manage API keys.

```sh icon=square-terminal theme={"system"}
algolia auth login
```

This opens the Algolia dashboard in your browser so you can sign in or create a new account.
After you sign in, the CLI stores your credentials in your system keychain.

<Tip>
  To directly create a new account, use `algolia auth signup`.
</Tip>

If you're running the CLI in an environment without a browser, such as an SSH session or container, add `--no-browser`.
The CLI prints an authorization URL and waits for you to complete the sign-in process.

After signing in, select the application for your commands:

```sh icon=square-terminal theme={"system"}
algolia application select
```

This command creates a local profile for the selected application if one doesn't already exist and sets it as the default.
The profile stores an API key that the CLI uses for subsequent commands, so you don't need to pass `--application-id` or `--api-key`.
To select an application without an interactive prompt, use `--app-name`.

### Authentication commands

To see a list of available authentication commands, see [`algolia auth`](/doc/tools/cli/commands/auth).

## Provide credentials directly

For CI pipelines, scripts, or if you prefer to manage credentials yourself,
provide your application ID and API key instead of signing in.
You can find both in the [Algolia dashboard](https://dashboard.algolia.com/account/api-keys/all).

### Environment variables

Set these environment variables:

* `ALGOLIA_APPLICATION_ID`
* `ALGOLIA_API_KEY`

Environment variables take precedence over command-line options and profiles.
That means you can't switch profiles while using environment variables.

### Command-line options

Provide these options when running commands:

* `--application-id`
* `--api-key`

Command-line options take precedence over profiles.

<Warning>
  These options are supported on macOS, Linux, and Windows Subsystem for Linux (WSL).
  **They're ignored in the native Windows build** of the Algolia CLI.
</Warning>

## Profiles

Profiles store an application ID and API key under a friendly name in `~/.config/algolia/config.toml`.

<Warning>
  The `--profile` flag is deprecated.
  Sign in with `algolia auth login` and select an application with `algolia application select` instead.

  `algolia application select` manages the profile and API key for you.
</Warning>

You can still refer to a profile with the `--profile` option,
for example: `algolia indices list -p PROFILE_NAME`.
See [`algolia profile`](/doc/tools/cli/commands/profile) for the deprecated profile commands.

<Note>
  Profiles are stored in **plain text** in the file `~/.config/algolia/config.toml`.
  If you manage your configuration files ("dotfiles") with GitHub, don't commit this file.
</Note>

## Crawler credentials

[Crawler commands](/doc/tools/cli/commands/crawler) require separate Crawler API credentials.
Configure them in one of the following ways.

### Configure the Crawler API key after signing in

If you've [signed in with OAuth](#sign-in-with-oauth) and selected an application, run:

```sh icon=square-terminal theme={"system"}
algolia auth crawler
```

This fetches your Crawler API key for the current application and stores it securely in your operating system's keychain.
You don't need to copy the key from the Algolia dashboard.

### Crawler environment variables

Export your Crawler user ID and Crawler API key as environment variables:
`ALGOLIA_CRAWLER_USER_ID` and `ALGOLIA_CRAWLER_API_KEY`.

You can find both in the Algolia dashboard:

1. Go to the [Algolia dashboard](https://dashboard.algolia.com/explorer/browse) and select your Algolia application.
2. On the left sidebar, select **Data sources**.
3. Select **Crawler** and go to the **Settings** tab.

### Crawler profiles

<Warning>
  Like the [`--profile` flag](#profiles), manually managed crawler profiles are deprecated.
  Configure the Crawler API key with `algolia auth crawler` instead.
</Warning>

Add the keys `crawler_user_id` and `crawler_api_key`
to an application profile in `~/.config/algolia/config.toml`.

An example profile for an Algolia application with Crawler
could look like the following:

```toml icon=braces highlight={4,5} theme={"system"}
[PROFILE_NAME]
application_id = "ALGOLIA_APPLICATION_ID"
api_key = "ALGOLIA_API_KEY"
crawler_user_id = "ALGOLIA_CRAWLER_ID"
crawler_api_key = "ALGOLIA_CRAWLER_API_KEY"
```
