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
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
mouter-cli 0.3.0. Version 0.2.0 does not support --device and reports an invalid-argument error. Check your version with:
uv tool install mouter-cli:
mouter auth logout first.
- Run the command. The CLI prints a verification URL and a one-time code to stderr.
- Open the URL in a browser on any device, sign in, and enter the code if the URL does not already include it.
- 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.
- The CLI waits for your decision, saves the OAuth authorization, and prints one JSON document to stdout.
--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: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:
--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: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
0700and each file is mode0600. 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
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 withUNAUTHENTICATED, 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.