> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/developer/python-sdk/authenticate-with-the-python-sdk.md).

# Authenticate with the Python SDK

The Python SDK accepts an API key three ways. Pick whichever fits your runtime - they all end up at the same `Roboflow` object.

## Option 1: Environment variable (recommended for scripts and agents)

Set `ROBOFLOW_API_KEY` in your shell or CI environment:

```bash
export ROBOFLOW_API_KEY=rf_xxxxx
```

```python
import roboflow

rf = roboflow.Roboflow()  # picks up ROBOFLOW_API_KEY
```

This is the cleanest path for scripts, notebooks, and AI coding agents - no interactive prompts and no on-disk state.

## Option 2: Pass the key explicitly

```python
import roboflow

rf = roboflow.Roboflow(api_key="rf_xxxxx")
```

Useful when you have multiple keys for multiple workspaces in the same process.

## Option 3: Interactive login

```python
import roboflow

roboflow.login()
```

Opens an authentication URL in the browser, prompts for a token, and saves credentials to `~/.config/roboflow/config.json`. Subsequent `Roboflow()` calls (with no arguments) read from that file.

To re-authenticate against a different account or refresh the token:

```python
roboflow.login(force=True)
```

The CLI's `roboflow login` writes to the same on-disk location, so once either tool authenticates, the other picks up the credentials too.

## Where to find your API key

In the [Roboflow web app](https://app.roboflow.com/), navigate to **Settings → API Key**. Each workspace has its own key - the key you use determines the workspace your code authenticates against.

For [scoped API keys](/developer/authentication/scoped-api-keys.md) (limit a key to specific resources or operations), see the Authentication section.

## Override the config location

If you need credentials stored somewhere other than `~/.config/roboflow/`, set `ROBOFLOW_CONFIG_DIR`:

```bash
export ROBOFLOW_CONFIG_DIR=/etc/roboflow
```

See [Environment Variables](/developer/environment-variables.md) for the full list of variables the SDK and CLI respect.
