# div login

> Sign this machine in through the browser and save an API key.

## Synopsis

```text
div login [flags]
```

Opens the dashboard to approve this machine, then saves a new API key to the settings file.

## Flags

| Flag | Description | Default |
| --- | --- | --- |
| `--no-browser` | Print the approval link instead of opening it. | |
| `--api-url <url>` | Sign in to a different API URL, and save it for later commands. | `https://api.divergentlabs.xyz` |

## Behavior

1. `div login` prints a code such as `QZHR-LVKG` and opens the dashboard with it. Over SSH, or with `--no-browser`, it prints the link for you to open.
2. In the dashboard, check that the code matches the terminal, then approve. Approving requires a signed-in dashboard session. If the dashboard asks you to sign in, enter your email address and open the link it sends you. The link returns you to the approval page.
3. `div login` saves the key and prints the account and the file it saved to.

The code expires after 10 minutes and works once.

## The key

| Property | Value |
| --- | --- |
| Name | `div on <hostname>`, shown under **Settings** in the dashboard |
| Owner | the person who approved it |
| Scopes | `runs:read`, `runs:write`, `storage:read`, `storage:write`, `secrets:read`, `secrets:write`, `sandboxes:read`, `sandboxes:write` |
| Saved to | `~/.config/divergent/config.json`, or `$XDG_CONFIG_HOME/divergent/config.json`. Readable only by you. |

`div login` replaces the saved key and keeps the file's other fields. To sign the machine out, revoke the key under **Settings**. For other scopes, such as `inference:invoke`, create a key under **Settings**.

If `DIVERGENT_API_KEY` is set in your shell, it takes precedence over the saved key, and `div login` warns you. Unset it to use the new key.

## Output

```text
Code: QZHR-LVKG
Opened https://app.divergentlabs.xyz/cli?code=QZHR-LVKG. Approve the request there if the code matches.
Waiting for approval…
Signed in to Divergent as founder@divergentlabs.xyz.
Saved API key "div on MacBook-Pro.local" to /Users/you/.config/divergent/config.json. To sign this machine out, revoke the key under Settings in the dashboard.
```

## Exit codes

| Code | Meaning |
| --- | --- |
| `0` | Signed in. |
| `1` | The request was denied, expired, or the API could not be reached. |
| `2` | Invalid flags. |

## Examples

```bash
div login
div login --no-browser
div login --api-url http://localhost:4000
```
