# cv login

Sign in from the terminal and save an API key for this machine. `cv logout` revokes it and forgets it.

## Sign in

Usage:

```
cv login [--no-browser]
cv logout
```

`cv login` opens the browser, where you sign in or sign up and pick a project. It then saves a new API key for that project, named after this machine. `--no-browser` prints the link instead of opening it.

On a machine without a browser, such as a server you reach over SSH, open the address it prints on another device and enter its code.

```
$ cv login
Opened https://convert.dev/… in your browser to sign in.
On another device, open https://convert.dev/… and enter the code …
Waiting for you to approve...
Signed in as you@example.com to Acme / Production.
Saved the key for this machine in /home/you/.config/cv/credentials.json.
```

## The saved key

The key is a personal key of the project you picked: it stops working when you leave the organization. A server that must keep working after you leave needs a project key, which an owner makes in the dashboard. See [Personal and project keys](https://convert.dev/docs/keys.md#kinds).

`cv` saves it in `credentials.json`, one key for each server. The file is in `$XDG_CONFIG_HOME/cv` when it is set, in `%APPDATA%\cv` on Windows, and in `~/.config/cv` otherwise. Running `cv login` again saves a new key and revokes the one it replaces.

`CV_API_KEY` and `--key` win over the saved key. `cv login` and `cv logout` say so when `CV_API_KEY` is set.

## Sign out

`cv logout` revokes the key `cv login` saved for this server and forgets it. When the server cannot be reached, it forgets the key and says to revoke it in the dashboard.

With `--json`, `cv login` gives `email`, `org`, `project` and `saved_to`, the file that holds the key, and `cv logout` gives `state`: `revoked`, `forgotten` when the key could not be revoked, or `absent` when no key was saved.

## Environment

| Variable |  |
| --- | --- |
| `CV_API_KEY` | The API key. It wins over the key `cv login` saved, and `--key` wins over both. |
| `CV_API_URL` | The server, `https://api.convert.dev` unless it is set. `--api` wins over it. |
| `XDG_CONFIG_HOME` | Where `cv login` saves the key, in `cv/credentials.json`. |
| `XDG_CACHE_HOME` | Where `cv` keeps the ids of what it uploaded and ran. See [What cv keeps](https://convert.dev/docs/concepts/jobs.md#cache). |
| `CV_VERSION` | For the install script, the version to install. |
| `CV_INSTALL_DIR` | For the install script, the folder to put `cv` in, `~/.local/bin` unless it is set. |

`cv --skill` prints the skill file for agents, and `cv skills get core` prints the usage guide. See [Agent skill](https://convert.dev/docs/skill.md).
