# CLI Auth > Sign the QwryAI CLI in with your browser or an API key, check which credential it uses, and sign out Use the auth commands to store a browser login for interactive use. For CI and other unattended jobs, set the `QWRYAI_API_KEY` environment variable instead. See [QwryAI CLI](/docs/cli/overview). Whichever way you sign in, you choose what the credential may do, and it never gets more than your workspace role allows. If your role changes, you leave the workspace or the plan lapses, the credential loses that access too. ## Log in with the browser For interactive use, sign in through your browser: ```bash qwryai-cli auth:login ``` The CLI opens the **Connect qwryai-cli to QwryAI** page and prints a device code such as `7KQ2-M9XD`. Sign in if you're asked to. **1. Check the device code** Make sure the **Device code** on the page matches the one in your terminal. The page also shows the **Workspace** and its plan, and the **Agents** the CLI will reach: access covers every agent in the workspace, including ones you add later. ![The Connect qwryai-cli to QwryAI page with the Device code field showing 7KQ2-M9XD, the QWRY AI workspace on the Growth Plan, the Agents section listing QwryAI, and the Permissions heading.](annotated/01-device-code.webp "Check that the Device code matches the code in your terminal.") **2. Choose the permissions** Under **Permissions**, every permission your role holds is on. Turn off any the CLI shouldn't have, such as **Change agent settings** for a read-only script. ![The Permissions section of the approval page, with switches for Chat with agents, Manage conversations and helpdesk, Read agent settings and Change agent settings.](annotated/02-permissions.webp "Turn off any permission the CLI shouldn't have.") **3. Approve** Select **Approve qwryai-cli**. The terminal confirms the login and the CLI stores the credential in `~/.qwryai/credentials.json`, readable by your user alone. `auth:login` prints one JSON line when it starts and one when you've approved, so a script can read the approval link before the login finishes: ```json {"success":true,"action":"open_verification_url","verification_uri":"https://www.qwryai.com/oauth/device/verify","verification_uri_complete":"https://www.qwryai.com/oauth/device/verify?user_code=7KQ2-M9XD","user_code":"7KQ2-M9XD","browserOpened":true} {"success":true,"message":"QwryAI CLI authenticated","apiUrl":"https://api.qwryai.com/public/v1"} ``` On a server, over SSH or in any terminal that can't open a browser, add `--no-open` and open `verification_uri_complete` on another device: ```bash qwryai-cli auth:login --no-open ``` The code is valid for 15 minutes. If nobody approves it in time, the CLI stops with `Device login expired`; run `auth:login` again. > [!NOTE] > > A browser login stays valid for 90 days from approval. The CLI refreshes its hourly access token by itself, so you only sign in again when the 90 days are up or after `auth:logout`. ## Log in with an API key For scripts and CI, create an API key and pass it in the environment. The CLI doesn't store keys. **1. Create the key** In QwryAI, open **Workspace settings › API keys** and select **Create API key**. Choose what the key can do in **Create New API Key**, then select **Confirm**. Only members who can manage API keys see the button, and the page asks you to subscribe if your plan has no API access. ![The Create New API Key dialog with permission switches such as Chat with agents and Read agent settings, and the Cancel and Confirm buttons.](annotated/03-create-key.webp "On Workspace settings › API keys, select Create API key, choose what the key can do, then select Confirm.") **2. Set the variable** ```bash export QWRYAI_API_KEY= qwryai-cli auth:status --verify ``` > [!WARNING] > > A stored browser login takes priority over `QWRYAI_API_KEY`. On a machine where someone ran `auth:login`, run `auth:logout` first if you want the CLI to use the key. ## Check status ```bash qwryai-cli auth:status ``` Shows whether a credential is set up and where it comes from (`oauth` for a browser login, `api_key` for `QWRYAI_API_KEY`, or `none`). It doesn't contact QwryAI: ```json {"success":true,"data":{"apiUrl":"https://api.qwryai.com/public/v1","authenticated":true,"source":"oauth"}} ``` Add `--verify` to ask QwryAI what the credential can do right now: the workspace's plan, your role, the permissions it holds and the tools they allow. ```bash qwryai-cli auth:status --verify ``` ```json { "success": true, "data": { "apiUrl": "https://api.qwryai.com/public/v1", "authenticated": true, "source": "oauth", "account": { "success": true, "data": { "tenantId": "", "plan": "growth", "authType": "oauth", "creatorRole": "Admin", "granted": ["USE_CHAT", "MANAGE_CHAT", "READ_AGENT_CONFIGURATION"], "permissions": [ { "permission": "USE_CHAT", "label": "Chat with agents" }, { "permission": "MANAGE_CHAT", "label": "Manage conversations and helpdesk" }, { "permission": "READ_AGENT_CONFIGURATION", "label": "Read agent settings" } ], "tools": ["get_account_context", "list_agents", "search_knowledge", "create_conversation", "send_message", "query_conversations", "agent_configuration"] } } } } ``` The CLI prints this on one line; it's spread out here for reading. ## Log out ```bash qwryai-cli auth:logout ``` Revokes the browser login on QwryAI and deletes `~/.qwryai/credentials.json`: ```json {"success":true,"message":"QwryAI OAuth credentials revoked and removed"} ``` `auth:logout` doesn't touch `QWRYAI_API_KEY`. To stop a key working, delete it in **Workspace settings › API keys**. ## Commands | Command | Purpose | | - | - | | `qwryai-cli auth:login` | Sign in through the browser approval page | | `qwryai-cli auth:login --no-open` | Print the approval link without opening a browser | | `qwryai-cli auth:status` | Show whether a credential is set up and its source | | `qwryai-cli auth:status --verify` | Ask QwryAI for the plan, role, permissions and tools the credential has now | | `qwryai-cli auth:logout` | Revoke the browser login and delete the stored credential | > [!NOTE] > > Run `qwryai-cli help` to see every command and environment variable.