# How to authenticate using an API key

> Authenticate your Boulder Opal session without a browser

Source: https://docs.q-ctrl.com/boulder-opal/toolkit/discover/set-up/how-to-authenticate-using-an-api-key

You can seamlessly authenticate to the Q-CTRL platform using API key-based authentication by passing an API key from your Python client environment.

In this guide, you will learn how to retrieve an API key and use it to authenticate your session.

## 1. Retrieve your API key 

Sign in to [Q-CTRL Accounts](https://accounts.q-ctrl.com/). Under [Sign in and security](https://accounts.q-ctrl.com/security?organization=), copy the pre-generated API key. You also have the ability to generate additional keys.

## 2. Authenticate using your API key

In your client environment, you can call [`boulderopal.cloud.authenticate`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/cloud/authenticate.md) and pass the respective API key to authenticate with the Q-CTRL platform.


```python
import boulderopal as bo

bo.cloud.authenticate(api_key="YOUR_QCTRL_API_KEY")
```

## 3. Set an environment variable to persist authentication (optional)

To avoid re-authenticating, you may choose to simply set the `QCTRL_API_KEY` environment variable to your key's value. Note that if you don't set the environment variable or call [`boulderopal.cloud.authenticate`](https://docs.q-ctrl.com/references/boulder-opal/boulderopal/cloud/authenticate.md) explicitly, you will be redirected to a browser for authentication.


```python
export QCTRL_API_KEY="YOUR_QCTRL_API_KEY"
```
