# Sign in

Source: https://openpanel.sh/docs/cli/sign-in

Sign the CLI in through your browser with a one-time code, or with an API key on a server or in CI.

The CLI signs in two ways:

| | How | It acts as | Use it |
|---|---|---|---|
| [Through the browser](#through-the-browser) | `openpanel login`, then you approve a code in the console | You, with your access, in every organization you belong to | On your own computer |
| [With an API key](#with-an-api-key) | `OPENPANEL_TOKEN`, or `openpanel login --with-token` | The person who made the key, capped by the key's scope, in the key's organization | On a server, in CI, for an AI agent |

`openpanel whoami` shows which one is in use, who you are and the organization commands work in.

## Through the browser [#through-the-browser]

<Steps>
<Step>
### Ask for a code [#ask-for-a-code]

```sh
openpanel login
```

The CLI prints a code such as `RDML-MNGN` and opens `https://openpanel.sh/cli` in your browser. On a machine where no browser opens, add `--no-browser` and open the address yourself, on any device.
</Step>

<Step>
### Type the code [#type-the-code]

Sign in to the console if you are not, then type the code from your terminal and choose **Continue**. The link never carries the code: you type it, so a link someone else sends you cannot sign their terminal in as you.

The CLI starts in the organization that is active in the console. To start it in another one, switch organization at the top of the console first.
</Step>

<Step>
### Check and approve [#check-and-approve]

The page asks **Sign in the CLI as you?** and shows what asked: the CLI and the computer it runs on, the code, the address it asked from, and when the code expires. If the address is not the one your browser uses, the page says so. Approve only a code you asked for yourself, just now.

Choose **Sign in the CLI**. The terminal continues within seconds and prints `Signed in as you@example.com in Your organization.` Choose **It wasn't me** to refuse; the terminal then stops with "The sign-in was refused in the browser."
</Step>
</Steps>

A code lasts 10 minutes and works once. Run `openpanel login` again for a new one. Approving or refusing a code is written to the organization's [audit log](/docs/monitoring/audit-log).

### The CLI's session [#the-clis-session]

The CLI gets a session of its own, the same kind your browser has. It acts as you, with your access, and works in every organization you belong to:

- `openpanel orgs` lists them, and `openpanel orgs switch <slug>` changes the one commands work in.
- `--org <slug>` picks another one for a single command.

The session is listed with your others in the console, under **Account settings**, **Sign-in and security**, **Where you are signed in**. It ends when:

- you run `openpanel logout`;
- you sign it out there;
- you change or reset your password;
- it goes unused for 30 days. Each day you use it, it is kept for another 30 days.

## With an API key [#with-an-api-key]

On a server, in CI or for an AI agent, use an [API key](/docs/api/authentication#api-keys) instead of a person's session. Set it in the environment, and every command uses it:

```sh
export OPENPANEL_TOKEN=opk_…
openpanel whoami
```

`OPENPANEL_TOKEN` wins over a saved sign-in. To save the key instead, pipe it into `login --with-token`, which keeps it out of your shell's history:

```sh
printf %s "$OPENPANEL_TOKEN" | openpanel login --with-token
```

The CLI checks the key with OpenPanel before it saves it.

A key acts as the person who made it, never with more than their access, capped by its scope (view, deploy or admin) and, if it was made so, limited to some projects. It works only in the organization it was made in.

### Make a key [#make-a-key]

API keys are made by a person, never by another key. Sign in through the browser first, then:

```sh
openpanel keys create --name "CI" --scope deploy --project shop
```

The key is printed once; store it right away. `--project` limits the key to that project (repeat it for more), and `--expires 2027-06-30` makes it stop working on that date. `openpanel keys` lists your keys and `openpanel keys revoke <id>` revokes one. The console has the same under Organization settings, API keys.

## Where the sign-in is kept [#where-the-sign-in-is-kept]

`openpanel login` saves the token, the OpenPanel address and the organization in `config.json` in:

| System | Folder |
|---|---|
| macOS and Linux | `~/.config/openpanel`, or `$XDG_CONFIG_HOME/openpanel` when that is set |
| Windows | `%APPDATA%\openpanel` |

Only you can read the file. `OPENPANEL_CONFIG_DIR` names another folder.

## Sign out [#sign-out]

```sh
openpanel logout
```

This ends the CLI's session at once and deletes the saved token. With a saved API key, it deletes the key from the file; the key itself keeps working until it is revoked. `logout` does not touch `OPENPANEL_TOKEN`.

## Another OpenPanel [#another-openpanel]

To use the CLI with an OpenPanel at another address, sign in with `--url`:

```sh
openpanel login --url https://openpanel.example.com
```

The address is saved with the sign-in. `OPENPANEL_URL` or `--url` on a single command overrides it.

## What can go wrong [#what-can-go-wrong]

| Message | What it means |
|---|---|
| "You are not signed in. Run openpanel login, or set OPENPANEL_TOKEN to an API key." | No saved sign-in and no `OPENPANEL_TOKEN`. |
| "The code expired. Run openpanel login again." | Nobody approved the code within 10 minutes. |
| "The sign-in was refused in the browser." | Someone chose **It wasn't me**. |
| "Too many sign-in codes from this address. Try again in an hour." | More than 20 codes were asked for from one address in an hour. |
| "Pipe an API key (opk_…) into openpanel login --with-token." | Standard input did not hold a key. |
| "API keys are made and revoked by a person: in the console under Organization settings, API keys, or with the CLI after `openpanel login`." | A `keys` command ran with an API key. Run `openpanel login` and try again. |
| "This API key belongs to another organization." | `--org` or `OPENPANEL_ORG` names another organization than the key's. |