Skip to main content

Choose a sign-in method

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

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

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:
If it is lower than 0.3.0, upgrade a CLI installed with uv tool install 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:
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:
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:
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

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

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 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.

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.