> ## Documentation Index
> Fetch the complete documentation index at: https://ctpf.q-uestionable.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Environment Variables

> Environment variables recognized by qai

qai recognizes a small number of environment variables. Most configuration is handled through the CLI, Settings UI, or config file — environment variables are primarily for credentials and CI/CD overrides.

## LLM Provider Credentials

Provider API keys follow the convention `{PROVIDER}_API_KEY`. These are checked before the OS keyring when resolving credentials.

| Variable             | Provider                  |
| -------------------- | ------------------------- |
| `ANTHROPIC_API_KEY`  | Anthropic (Claude models) |
| `OPENAI_API_KEY`     | OpenAI (GPT models)       |
| `GROQ_API_KEY`       | Groq                      |
| `OPENROUTER_API_KEY` | OpenRouter                |
| `COHERE_API_KEY`     | Cohere                    |
| `MISTRAL_API_KEY`    | Mistral                   |

Any provider name mapped through `{PROVIDER_NAME.upper()}_API_KEY` is recognized. For example, a provider named `azure` would check `AZURE_API_KEY`.

<CodeGroup>
  ```bash Linux / macOS theme={null}
  export ANTHROPIC_API_KEY="sk-ant-..."
  export OPENAI_API_KEY="sk-..."
  ```

  ```powershell Windows PowerShell theme={null}
  $env:ANTHROPIC_API_KEY = "sk-ant-..."
  $env:OPENAI_API_KEY = "sk-..."
  ```
</CodeGroup>

<Note>
  For persistent credential storage, use the OS keyring via `qai config set-credential` instead of environment variables. Environment variables are useful for CI/CD pipelines and ephemeral environments where a keyring is unavailable.
</Note>

## Model Selection

### QAI\_MODEL

Default model for inject campaigns and chain execution. Used when the `--model` CLI flag is not provided.

**Format:** `provider/model` (e.g., `anthropic/claude-sonnet-4-20250514`, `openai/gpt-4o`, `ollama/llama3`)

```bash theme={null}
export QAI_MODEL=anthropic/claude-sonnet-4-20250514
```

Bare model names without a provider prefix are treated as Anthropic.

## IPI Probe

### QAI\_PROBE\_API\_KEY

Bearer token for the `qai ipi probe` command. Used when probing OpenAI-compatible endpoints that require authentication (e.g., vLLM on RunPod with `VLLM_API_KEY` set).

```bash theme={null}
export QAI_PROBE_API_KEY=sk-your-endpoint-key
```

Can also be passed directly via `--api-key` on the CLI. The CLI flag takes precedence over the environment variable.

## Credential Resolution Order

qai resolves credentials in this order:

1. **Environment variable** — `{PROVIDER}_API_KEY` (checked first)
2. **OS keyring** — stored via `qai config set-credential` (checked second)
3. **Error** — raises if neither is found

This allows environment-based overrides for CI/CD while maintaining secure keyring storage for interactive use.

## Configuration Resolution Order

For non-credential settings, `qai config resolve` uses this precedence:

1. **CLI flag** (highest priority)
2. **Environment variable** (if mapped)
3. **Database setting** (stored via Settings UI or `qai config set`)
4. **Config file** (`~/.qai/config.yaml`)
5. **Default value** (lowest priority)

<Tip>
  Use `qai config get <key>` to see the current resolved value and its source.
</Tip>
