> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# mouter auth

> Sign in with a browser, a device code, or an API key, and understand how the CLI stores and refreshes credentials.

```bash theme={null}
mouter auth login
mouter auth status
mouter auth logout
```

## Choose a sign-in method

| Method | Use it when | Command | Requirements and limits |
| - | - | - | - |
| Browser OAuth | You work on a machine with a browser. | `mouter auth login` | The browser must be able to reach a temporary callback on `127.0.0.1` on the same machine. Waits 180 seconds by default (`--login-timeout`, at most 600). `--no-browser` only stops the CLI from opening a browser and prints the URL; open it on the same machine. |
| Device code | The machine has no browser: an SSH session, a container, or a remote agent sandbox. | `mouter auth login --device` | Needs a CLI version and a Mouter server that both support device codes. You approve in a browser on any device. Cannot be combined with `--api-key`, `--key-stdin`, or `--no-browser`. |
| API key | CI, batch jobs, and other unattended runs. | `MOUTER_API_KEY` in the environment, or `mouter auth login --api-key` / `--key-stdin` | Create the key in the [dashboard](https://mouter.ai/dashboard). A saved key stays valid until you revoke it there. |

For a person at a terminal with a browser, use browser OAuth. When there is no local browser, use a device code instead of copying an API key onto the machine. Use an API key for unattended automation, where nobody can approve a sign-in.

Browser OAuth and device code create an OAuth authorization with the scopes `tools:execute`, `tasks:read`, and `billing:read`. Signing in with OAuth removes any API key saved for the same Mouter origin.

Both OAuth methods refuse to sign in when an OAuth authorization is already saved for the same API origin, even if that authorization has expired or been revoked. In that case, run `mouter auth logout` against the same API origin first, then sign in again.

## Browser OAuth

```bash theme={null}
mouter auth login
```

The CLI prints an authorization URL to stderr, opens your browser, and waits for the sign-in to return to a temporary `127.0.0.1` callback. The CLI never copies browser cookies. When the sign-in succeeds, it prints one JSON document to stdout.

If the CLI already has a saved OAuth authorization for this API origin, `mouter auth login` is rejected. Run `mouter auth logout` first, whether you are changing accounts or the saved authorization has expired or been revoked.

## Device code

```bash theme={null}
mouter auth login --device
```

Use this when the machine running the CLI has no browser. It needs a CLI and a server that both include device code support. If the server does not support it, the command fails and does not fall back to browser sign-in.

Minimum CLI version: `mouter-cli` 0.3.0. Version 0.2.0 does not support `--device` and reports an invalid-argument error. Check your version with:

```bash theme={null}
mouter --version
```

If it is lower than 0.3.0, upgrade a CLI installed with `uv tool install mouter-cli`:

```bash theme={null}
uv tool upgrade mouter-cli
```

As with browser OAuth, this command is rejected if an OAuth authorization is already saved for the same API origin. Run `mouter auth logout` first.

1. Run the command. The CLI prints a verification URL and a one-time code to stderr.
2. Open the URL in a browser on any device, sign in, and enter the code if the URL does not already include it.
3. Check the client name and permissions on the approval page, and confirm that the code shown on the page is the same as the one in your terminal. Approve only if you just ran the command yourself.
4. The CLI waits for your decision, saves the OAuth authorization, and prints one JSON document to stdout.

A trusted agent may relay the verification URL and code, privately, to the person who started this sign-in, within that same authorization. Before approving, avoid posting them publicly or writing them to logs or screenshots, especially a URL that contains the code. The code cannot be exchanged for a token on its own, but that is a separate matter from whether it is safe to share freely. The CLI never prints access tokens, refresh tokens, or the device secret. `--login-timeout` sets how long the CLI waits, capped by the lifetime of the code. If you decline, or the code expires, run the command again.

## API keys

Use an environment variable for unattended runs:

```bash theme={null}
export MOUTER_API_KEY="..."
```

Provide the value from your secret manager. `MOUTER_API_KEY` takes priority over any saved credential, is never written to disk, and works without reading the credential file.

To save a key for later commands, enter it at a hidden prompt, or pipe it in from a secret manager:

```bash theme={null}
mouter auth login --api-key
secret-manager-command | mouter auth login --key-stdin
```

The CLI checks the key with the server before saving it. `--api-key` needs an interactive terminal; use `--key-stdin` for non-interactive input. If an OAuth authorization is saved, run `mouter auth logout` before saving a key.

Do not pass a key as a command argument or place it in a prompt or conversation.

## Where credentials are stored

The CLI keeps credentials in plaintext JSON files, one per Mouter origin, at:

```text theme={null}
$MOUTER_STATE_DIR/credentials/<origin-sha256>.json
```

If `MOUTER_STATE_DIR` is not set, the state directory is `$XDG_STATE_HOME/mouter` (`~/.local/state/mouter` by default). On Windows it is `%LOCALAPPDATA%\Mouter`. `<origin-sha256>` is the SHA-256 of the API origin, which is `https://api.mouter.ai` unless you set `MOUTER_BASE_URL` or `--base-url`. Set `MOUTER_BASE_URL` to override the origin, for example to the test host `https://mouter-api.moox-dev.com`.

* On macOS and Linux, the credentials directory is mode `0700` and each file is mode `0600`. On Windows the files use the permissions inherited from your user profile.
* The files hold access and refresh tokens, or a saved API key, in plain text. The CLI does not use the system keychain.
* Any process running as the same user can read these files. Keep the directory out of shared folders and source control.

## Token lifetime and refresh

| Token | Lifetime |
| - | - |
| Access token | At most 1 hour. |
| Refresh token | 30 days from sign-in. Rotated each time it is used; rotation does not extend the 30 days. |

Before a command that needs credentials, the CLI refreshes the access token when fewer than 60 seconds remain. You do not need to run a command to refresh it. Each refresh replaces the saved access and refresh tokens. After the refresh token expires, run `mouter auth logout` on the same API origin, then sign in again. Concurrent commands take a lock, so they do not refresh at the same time.

If an old, already-rotated refresh token is used again, the server revokes the whole authorization, so do not copy credential files between machines. If the CLI reports `UNAUTHENTICATED` for a saved OAuth authorization, run `mouter auth logout` on the same API origin, then sign in again.

## Sign out

```bash theme={null}
mouter auth logout
```

Logout revokes the saved OAuth authorization on the server, then deletes it locally. If revocation fails, for example because of a network error, the local credentials are kept so you can retry.

Logout also deletes a saved API key from the local file, but it does not revoke the key on the server. Revoke the key in the [dashboard](https://mouter.ai/dashboard) when it should stop working. Logout cannot unset `MOUTER_API_KEY`; the JSON result reports `environment_key_present` when the variable is set.

## Errors

Authentication errors exit with code 3, except invalid arguments, which exit with code 2.

| Code | Meaning | What to do |
| - | - | - |
| `UNAUTHENTICATED` | No usable credential: nothing is saved, the credential is invalid, expired, or revoked, or a sign-in was declined. | If an OAuth authorization is saved for this API origin (expired, revoked, or refresh token expired), run `mouter auth logout` on the same API origin first, because login is rejected while it is saved. Then run `mouter auth login` or `mouter auth login --device`, or set `MOUTER_API_KEY`. |
| `AUTH_TIMEOUT` | The sign-in was not approved before the timeout. | Run the login command again. Increase `--login-timeout` if you need more time (browser OAuth and device code, at most 600 seconds). A device code login can also end earlier, when the server-side code expires first. |
| `AUTH_NETWORK_ERROR` | The CLI could not complete an authorization request. | Check the connection, then run `mouter auth status` before retrying the login. |
| `AUTH_BUSY` | Another CLI process holds the credential lock. | Wait for it to finish and retry. |
| `CREDENTIAL_STORE_UNAVAILABLE` | The CLI cannot read or write the credential file. | Check `MOUTER_STATE_DIR` and file permissions. An environment `MOUTER_API_KEY` works without the file. |
| `INVALID_REQUEST` | Invalid arguments, such as `--device` with `--api-key`. | Fix the command. |

## Keep credentials out of agent conversations

Never put an API key or token in a prompt, a command argument, a file the agent reads, or a conversation. An agent must not ask you for one.

If a command fails with `UNAUTHENTICATED`, the agent should tell you to sign in yourself in a terminal, using `mouter auth login --device` or by setting `MOUTER_API_KEY` in its environment, and then retry. The agent should only relay the URL and code privately to the person who started this login. Confirm the codes match before approving; you approve in your own browser.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.