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

> To authenticate with the Algolia API, pass your credentials on the command line or create profiles as a shortcut.

You need to authenticate and authorize your CLI commands with your Algolia credentials (application ID and API key).
You can find both in the [Algolia dashboard](https://dashboard.algolia.com/account/api-keys/all).

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

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

Store your application ID and API key under a friendly name.
Instead of providing the command-line options with every command,
you can refer to the profile with the `--profile` option.
For example: `algolia index list -p PROFILE_NAME`.
For more information, see [`algolia profile add`](/doc/tools/cli/commands/profile/add).

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

The first profile you add is the **default profile**.
You can omit the `--profile` option when using the default profile.
To change the default profile, see [`algolia profile setdefault`](/doc/tools/cli/commands/profile/setdefault).

## Manage applications

Use `algolia application` (alias `app`) to list, create, and select applications in your Algolia account with the Dashboard API.

Before running these commands, authenticate with:

```sh theme={"system"}
algolia auth login
```

This creates an OAuth session for the CLI.

### Set the active application

After authenticating, run `algolia application select` to set the active application for the CLI. The command:

* Checks if a local profile exists for the application
* Creates a profile if needed
* Ensures the profile has an API key (creates one with the required permissions if needed)
* Sets this profile as the default for subsequent commands

After selecting an application, you don't need to pass `--application-id` or `--api-key`.

Use `--app-name` to select an application by name without an interactive prompt.

## Crawler commands

[Crawler commands](/doc/tools/cli/commands/crawler) require different credentials:
a Crawler user ID, and a Crawler API key.
You can find them 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.

You can provide your credentials for Crawler commands
in one of the following ways.

## Environment variables

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

## Profiles

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