# Configuration

Bub resolves configuration in this order (highest priority first):

1. Environment variables (`BUB_` prefix);
2. `.env` in the current workspace;
3. `~/.bub/config.yml` (created by `bub onboard`).

Unset fields use their defaults. See the [Settings reference](/docs/reference/settings/) for all options.

:::note[Before you start]
- [Install the Bub CLI](/docs/getting-started/install/#app-install).
- Prepare an API key from a model provider, or sign in with `bub login codex` (OpenAI only).
:::

## 1. Run the setup wizard {#initial-setup}

Run the following command in your terminal to start the interactive setup wizard and generate `~/.bub/config.yml`:

```bash
bub onboard
```

## 2. Inspect the config file {#check-the-config}

Now inspect `~/.bub/config.yml`. Here is an example of what it looks like:

```yaml title="~/.bub/config.yml"
model: openrouter:openrouter/free
api_key: sk-or-...
telegram:
  token: "123456789:your-telegram-bot-token"
  allow_users: "123456789,your_username"
```

:::danger
`bub onboard` writes API keys to `~/.bub/config.yml` in plain text by default. To avoid storing keys in the config file, leave the key blank during onboarding and pass it via environment variables instead.
:::

## 3. Use environment variables {#environment-variables}

Common environment variables:

| Variable | Description |
|---|---|
| `BUB_MODEL` | Model identifier in `provider:model` format (e.g. `openrouter:openrouter/free`, `codex:<model>`) |
| `BUB_API_KEY` | API key for the current provider (not needed with `bub login`) |
| `BUB_API_BASE` | Provider API base URL; leave blank for the default endpoint |
| `BUB_HOME` | Runtime data directory (default `~/.bub`) |
| `BUB_<PROVIDER>_API_KEY` | Provider-specific API key, e.g. `BUB_OPENROUTER_API_KEY` |
| `BUB_<PROVIDER>_API_BASE` | Provider-specific API base URL |

See the [Settings reference](/docs/reference/settings/) for the full table.

## 4. Configure fallback models {#configure-models}

Set `fallback_models` to try backup models in order when the primary model is unavailable:

```yaml title="~/.bub/config.yml" ins={2-3}
model: openai:gpt-5-mini
fallback_models:
  - openrouter:openrouter/free
```

Each candidate provider requires valid credentials. Fallbacks apply only when creating a client or opening the request stream fails; errors after streaming has started do not retry on another model to avoid duplicate tool side effects. See [Models and fallback](/docs/reference/settings/#model-routing).

## 5. Configure Telegram (optional) {#telegram-channel}

If you want to use Bub as a Telegram bot, configure the built-in Telegram channel in `.env`:

```bash title=".env"
BUB_TELEGRAM_TOKEN=123456789:your-telegram-bot-token
BUB_TELEGRAM_ALLOW_USERS=123456789,your_username
BUB_TELEGRAM_ALLOW_CHATS=-1001234567890
BUB_TELEGRAM_PROXY=http://127.0.0.1:7890   # optional
```

See [Telegram gateway](/docs/app/gateway/#telegram) for details.

## 6. Verify {#verify}

Now try talking to Bub with a one-off prompt to verify your setup:

```bash wrap
$ bub run "Can you introduce yourself?"

[cli:local]
I'm a virtual assistant designed to support a wide range of tasks...
```