# Authentication

Fleet uses API keys to authenticate all requests. Keys are tied to your account and grant full access. Treat them like passwords.

## Getting a key

Log in with the CLI:

```bash
fleet login
```

This opens a browser window, authenticates via your Fleet account, and saves a key locally at `~/.fleet/credentials`. The SDK and CLI read it automatically, with no environment variables needed.

You can also generate a key from the **API Keys** page in the dashboard.

## Using a key

**CLI:** credentials are loaded automatically after `fleet login`. To use a specific key:

```bash
FLEET_API_KEY=fleet_sk_... fleet jobs
```

**SDK:** credentials are loaded automatically from `~/.fleet/credentials`. To pass a key explicitly:

```python
from fleet import Fleet

client = Fleet(api_key="fleet_sk_...")
```

**Environment variable:** the SDK also reads `FLEET_API_KEY` if set:

```bash
export FLEET_API_KEY="fleet_sk_..."
```

```python
client = Fleet()  # picks up FLEET_API_KEY automatically
```

## Checking your identity

```bash
fleet whoami
```

```
Email:    you@example.com
User ID:  user_abc123
```

Or from Python:

```python
info = client._http.get("/v1/auth/me")
print(info["email"])
```

## Logging out

```bash
fleet logout
```

This removes the saved credentials from `~/.fleet/credentials`.
