# How to Set Up Environment Variables for Custom Model Providers in Claudian

> Learn how to set up environment variables for custom model providers in Claudian. Configure AI endpoints and model selections easily using KEY=VALUE entries in the Claudian environment settings.

- Repository: [YishenTu/claudian](https://github.com/YishenTu/claudian)
- Tags: how-to-guide
- Published: 2026-03-17

---

**Claudian parses plain-text KEY=VALUE entries from the Settings → Environment panel to configure custom AI endpoints and model selections, applying these variables through `parseEnvironmentVariables` in [`src/utils/env.ts`](https://github.com/YishenTu/claudian/blob/main/src/utils/env.ts) and reconciling changes via `applyEnvironmentVariables` in [`src/main.ts`](https://github.com/YishenTu/claudian/blob/main/src/main.ts).**

Claudian, an Obsidian plugin maintained at `YishenTu/claudian`, allows users to override default Anthropic models and API endpoints using custom environment variables. Understanding how to set up environment variables for custom model providers enables integration with third-party AI services or self-hosted Claude-compatible APIs without modifying core plugin files.

## Understanding the Environment Variable Parser

The plugin processes raw environment text through **`parseEnvironmentVariables`** defined in [`src/utils/env.ts`](https://github.com/YishenTu/claudian/blob/main/src/utils/env.ts). This function accepts a string input and returns a `Record<string, string>` by splitting lines on `=`, trimming whitespace, ignoring comments, and stripping optional `export ` prefixes.

When you click **Apply** in the settings interface, the plugin invokes this parser to transform your custom variables into a runtime configuration object used by the Claude SDK.

## Supported Custom Model Configuration Keys

Claudian recognizes four specific environment variables for model selection, defined in the **`CUSTOM_MODEL_ENV_KEYS`** constant in [`src/utils/env.ts`](https://github.com/YishenTu/claudian/blob/main/src/utils/env.ts):

- **`ANTHROPIC_MODEL`** – Sets the default model across all tiers
- **`ANTHROPIC_DEFAULT_OPUS_MODEL`** – Configures the Opus tier specifically
- **`ANTHROPIC_DEFAULT_SONNET_MODEL`** – Configures the Sonnet tier specifically
- **`ANTHROPIC_DEFAULT_HAIKU_MODEL`** – Configures the Haiku tier specifically

The function **`getModelTypeFromEnvKey`** maps each key to its corresponding model type (`model`, `opus`, `sonnet`, `haiku`), while **`getModelsFromEnvironment`** builds a sorted list of available models from these values for the UI selector.

## Configuring Custom Variables in the UI

The environment input interface resides in **[`src/features/settings/ClaudianSettings.ts`](https://github.com/YishenTu/claudian/blob/main/src/features/settings/ClaudianSettings.ts)**. Navigate to **Settings → Environment → Custom variables** to access the textarea where you paste your configuration.

When you modify the text and click **Apply**, the plugin stores the raw string in `this.settings.environmentVariables` and triggers the application flow. This design allows immediate testing of different provider endpoints without restarting Obsidian.

## Runtime Application and Model Reconciliation

The core application logic lives in **`applyEnvironmentVariables`** within [`src/main.ts`](https://github.com/YishenTu/claudian/blob/main/src/main.ts). This method performs the following sequence:

1. **Parse**: Calls `parseEnvironmentVariables(envText)` to generate the env object
2. **Detect Changes**: Compares the new text against `this.runtimeEnvironmentVariables` using **`computeEnvHash`** (lines 38-56 in [`src/main.ts`](https://github.com/YishenTu/claudian/blob/main/src/main.ts)), which hashes relevant keys including `ANTHROPIC_MODEL`, the three `ANTHROPIC_DEFAULT_*_MODEL` variables, and `ANTHROPIC_BASE_URL`
3. **Reconcile**: Invokes **`reconcileModelWithEnvironment`**, which uses `getModelsFromEnvironment` to extract custom model IDs and `getCurrentModelFromEnvironment` to determine the active default
4. **Apply**: Updates `this.settings.model` and persists changes, restarting conversation tabs if the model configuration changed

## Pointing to Custom Provider Endpoints

To route requests to a non-Anthropic API, define **`ANTHROPIC_BASE_URL`** in your environment variables:

```text
ANTHROPIC_BASE_URL=https://my-custom-api.example.com

```

The plugin reads this value during the hash computation phase and passes it to **[`src/utils/claudeCli.ts`](https://github.com/YishenTu/claudian/blob/main/src/utils/claudeCli.ts)**, which constructs the Claude SDK client using your custom endpoint. This enables compatibility with proxy services, local LLM servers, or third-party Claude API providers.

## Practical Implementation Examples

### Minimal Custom Provider Setup

Paste this block into **Settings → Environment → Custom variables** and click **Apply**:

```text

# Custom provider configuration

ANTHROPIC_MODEL=anthropic/claude-3-opus
ANTHROPIC_BASE_URL=https://api.my-provider.com

```

This configuration routes all requests to `api.my-provider.com` while selecting the Opus model variant.

### Programmatic Environment Parsing

For plugin extensions or vault scripts, import the utility functions directly:

```typescript
import { parseEnvironmentVariables, getModelsFromEnvironment } from '@/utils/env';

// Read environment from a vault file
const envText = await app.vault.read('.env.custom');
const env = parseEnvironmentVariables(envText);

// Extract available models
const customModels = getModelsFromEnvironment(env);
console.log('Detected models:', customModels.map(m => m.label));

```

This approach leverages the same parsing logic the core plugin uses, ensuring consistency with the UI behavior.

### Runtime Model Override

To dynamically select models based on current environment variables:

```typescript
import { parseEnvironmentVariables, getCurrentModelFromEnvironment } from '@/utils/env';

const envText = plugin.settings.environmentVariables;
const env = parseEnvironmentVariables(envText);
const preferredModel = getCurrentModelFromEnvironment(env);

if (preferredModel) {
  plugin.settings.model = preferredModel;
}

```

The **`getCurrentModelFromEnvironment`** function returns the first non-empty value, preferring `ANTHROPIC_MODEL` over tier-specific variables when multiple are defined.

## Summary

- **Configuration Location**: Set variables in **Settings → Environment** within the Claudian plugin interface, stored in [`src/features/settings/ClaudianSettings.ts`](https://github.com/YishenTu/claudian/blob/main/src/features/settings/ClaudianSettings.ts)
- **Core Parsing**: `parseEnvironmentVariables` in [`src/utils/env.ts`](https://github.com/YishenTu/claudian/blob/main/src/utils/env.ts) handles the KEY=VALUE syntax, supporting comments and optional `export` prefixes
- **Model Variables**: Use `ANTHROPIC_MODEL`, `ANTHROPIC_DEFAULT_OPUS_MODEL`, `ANTHROPIC_DEFAULT_SONNET_MODEL`, or `ANTHROPIC_DEFAULT_HAIKU_MODEL` to define custom model IDs
- **Custom Endpoints**: Set `ANTHROPIC_BASE_URL` to redirect the Claude SDK to alternative API providers, processed in [`src/utils/claudeCli.ts`](https://github.com/YishenTu/claudian/blob/main/src/utils/claudeCli.ts)
- **Application Flow**: `applyEnvironmentVariables` in [`src/main.ts`](https://github.com/YishenTu/claudian/blob/main/src/main.ts) orchestrates parsing, change detection via `computeEnvHash`, and model reconciliation without requiring an Obsidian restart

## Frequently Asked Questions

### What environment variables does Claudian support for custom model providers?

Claudian recognizes four model-specific variables—`ANTHROPIC_MODEL`, `ANTHROPIC_DEFAULT_OPUS_MODEL`, `ANTHROPIC_DEFAULT_SONNET_MODEL`, and `ANTHROPIC_DEFAULT_HAIKU_MODEL`—plus `ANTHROPIC_BASE_URL` for custom endpoints. These are defined in the `CUSTOM_MODEL_ENV_KEYS` constant in [`src/utils/env.ts`](https://github.com/YishenTu/claudian/blob/main/src/utils/env.ts) and processed by `getModelsFromEnvironment` to populate the model selector.

### How do I point Claudian to a custom API endpoint instead of Anthropic's servers?

Define `ANTHROPIC_BASE_URL=https://your-endpoint.com` in the **Custom variables** text area under Settings → Environment, then click **Apply**. The plugin stores this value and passes it to the Claude SDK constructor in [`src/utils/claudeCli.ts`](https://github.com/YishenTu/claudian/blob/main/src/utils/claudeCli.ts), redirecting all API traffic to your specified URL while maintaining the same request format.

### Why isn't my custom model appearing in the model selector dropdown?

Verify that your environment variable uses one of the four supported keys (`ANTHROPIC_MODEL` or the tier-specific variants) and that the value contains no whitespace or comment characters on the same line. The `getModelsFromEnvironment` function in [`src/utils/env.ts`](https://github.com/YishenTu/claudian/blob/main/src/utils/env.ts) only includes non-empty values from these specific keys in the dropdown list.

### Do I need to restart Obsidian after changing environment variables?

No. The `applyEnvironmentVariables` method in [`src/main.ts`](https://github.com/YishenTu/claudian/blob/main/src/main.ts) immediately applies changes when you click **Apply**, computes a hash of the relevant variables via `computeEnvHash` to detect modifications, and reconciles the active model. Conversation tabs restart automatically if the model configuration changed, but the application itself continues running.