> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/cortex-xsiam/reference-and-developer-docs/about-cortex-cli/connect-cortex-cli/authenticate-credentials.md).

# Authenticate credentials

Configure Cortex CLI credentials for secure scans in Cortex XSIAM.

Configure credentials before running Cortex CLI. The installer does not save them.

Choose the method that fits your workflow:

* Use a configuration file for persistent local authentication.
* Use environment variables for CI/CD pipelines.
* Use command-line flags for one-off commands or overrides.

Generate API keys in the UI, or use the self-service workflow to create role-restricted CLI and IDE keys through the Public API. The self-service workflow uses a Primary API key. See [Self-service API keys for CLI scans](/cortex-xsiam/reference-and-developer-docs/about-cortex-cli/connect-cortex-cli/self-service-api-keys-for-cli-scans.md).

{% hint style="warning" %}
Do not commit API keys or credential files to source control.
{% endhint %}

### Configuration file

Use a `cortex.env` file for persistent local authentication. Cortex CLI reads this file automatically from your home or current working directory.

The file uses `KEY=VALUE` pairs.

#### macOS and Linux

Create `~/cortex.env` and restrict access to it.

```shell
cat > ~/cortex.env << EOF
CORTEX_API_BASE_URL=https://api-<TENANT>.xdr.us.paloaltonetworks.com
CORTEX_API_KEY=<YOUR_API_KEY>
CORTEX_API_KEY_ID=<YOUR_KEY_ID>
EOF
chmod 600 ~/cortex.env
```

#### Windows

Create `cortex.env` in your user profile.

```powershell
$configPath = "$env:USERPROFILE\cortex.env"
@"
CORTEX_API_BASE_URL=https://api-<TENANT>.xdr.us.paloaltonetworks.com
CORTEX_API_KEY=<YOUR_API_KEY>
CORTEX_API_KEY_ID=<YOUR_KEY_ID>
"@ | Out-File -FilePath $configPath -Encoding UTF8
```

### Environment variables

Use environment variables for CI/CD pipelines. Store values in your CI/CD platform's secret store.

| Variable name         | Description                                                                 |
| --------------------- | --------------------------------------------------------------------------- |
| `CORTEX_API_BASE_URL` | Your tenant URL (such as <https://api-example.xdr.us.paloaltonetworks.com>) |
| `CORTEX_API_KEY`      | The secret key token                                                        |
| `CORTEX_API_KEY_ID`   | The ID associated with the key                                              |

#### macOS and Linux

```shell
export CORTEX_API_BASE_URL="https://api-<TENANT>.xdr.us.paloaltonetworks.com"
export CORTEX_API_KEY="<YOUR_API_KEY>"
export CORTEX_API_KEY_ID="<YOUR_KEY_ID>"
```

#### Windows

```powershell
$env:CORTEX_API_BASE_URL="https://api-<TENANT>.xdr.us.paloaltonetworks.com"
$env:CORTEX_API_KEY="<YOUR_API_KEY>"
$env:CORTEX_API_KEY_ID="<YOUR_KEY_ID>"
```

### Command-line flags

Use flags for one-off scans or to override configured credentials. Place global flags before the module name.

```shell
cortexcli --api-base-url <URL> --api-key <KEY> --api-key-id <ID> code scan ...
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://cortex-docs.paloaltonetworks.com/cortex-xsiam/reference-and-developer-docs/about-cortex-cli/connect-cortex-cli/authenticate-credentials.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
