# Login with AnyRouter

> Sign in to the AnyRouter CLI with browser login, device code on SSH, or a key, and see where credentials are stored.


# Login with AnyRouter

The CLI signs you in once, stores a key locally and reuses it on every run. `anyr login` is an alias of `anyr auth login`.

```bash
curl -fsSL https://anyrouter.dev/setup.sh | bash
anyr auth login      # or just run a launcher: anyr claude, anyr chat
```

1. **Browser** (default): the CLI opens anyrouter.dev, you sign in and approve, and the key returns over a local callback. Only a masked `sk-ar-v1-…` hint is shown, never the full secret.
2. **Device code** (SSH, CI, display-less Linux, or a failed browser): the CLI prints a code and URL. Open the URL on any signed-in device, enter the code and approve. Codes are single-use and expire after a few minutes.
3. The key is saved to `~/.anyrouter/config.yaml` (mode `600`) and reused by every launcher. An older `~/.config/anyrouter/config.yaml` is migrated on first run.

After an interactive login, a selector session can set connected providers (merged with stored ones), a default model (`auto` keeps smart routing), reasoning effort, public alias and identity, and a default coding agent. Values go to `config.yaml`; pass `--yes` to skip the prompts. Provider keys are not collected here; use `anyr byok add`.

## Flags

| Flag | When to use |
|---|---|
| `--key sk-ar-v1-...` | Non-interactive, or you already have a key. Also `ANYROUTER_API_KEY`. |
| `--device` / `--device-code` | Force the device code flow. |
| `--paste` | Paste an `sk-ar-` key from [Dashboard → Keys](https://anyrouter.dev/dashboard/keys). |
| `--plaintext` | Accepted for compatibility. Keys are always stored in `config.yaml`. |
| `--yes` | Skip the selector session and coding-agent prompts. |

```bash
anyr auth login --device
ANYROUTER_API_KEY=sk-ar-v1-your-key anyr claude --yes   # CI, no TTY
```

Without a TTY the CLI never prompts: pass `--key`, set `ANYROUTER_API_KEY`, or use `--device`.

## What the key can do

The login key has the same capabilities as a dashboard key, including Key Management and Credits endpoints (unrestricted `allowed_endpoints`). It appears under [API Keys](https://anyrouter.dev/dashboard/keys) and can be revoked there at any time; the CLI then asks you to sign in again. `anyr keys` uses this same key, with no separate management credential. A pasted dashboard key with Key Management off gets 403 from `anyr keys` until you re-run `anyr auth login` or enable it.

`anyr usage` prints remaining credits, today's spend and lifetime used, with the last cached snapshot if refresh fails ([details](/cli/usage)).

## Troubleshooting

| Symptom | Fix |
|---|---|
| Browser did not open or timed out | Over SSH or without a display the CLI falls back to device code. Force it with `anyr auth login --device`. |
| Key rejected (HTTP 401) | Use the full `sk-ar-v1-…` key. Create a new one in [Dashboard → Keys](https://anyrouter.dev/dashboard/keys), then `anyr auth login --key sk-ar-v1-...` or `--paste`. A 403 from credits (such as a WAF challenge) is not a rejected key. |
| Re-run the selector session | Run `anyr auth login` again, or edit `provider_connections`, `default_model`, `default_effort`, `default_tool` in `config.yaml`. |


## Related

- [Configuration](/docs/cli/configuration.md)
- [Accounts and keys in the CLI](/docs/cli/accounts-and-keys.md)
- [Managing API Keys](/docs/features/api-keys.md)
