# Mux

<Callout type="info" title="Note">
  AI Gateway is part of [AI Governance](/beta-docs/ai-coder/ai-governance/), which is
  included with a Premium license.
</Callout>

Mux makes it easy to run parallel coding agents, each with its own isolated workspace, from your browser or desktop; it is open source and provider-agnostic.

Mux can be configured to route OpenAI- and Anthropic-compatible traffic through AI Gateway by setting a custom provider base URL and using a Coder-issued token for authentication.

## Prerequisites [#prerequisites]

* AI Gateway is enabled on your Coder deployment.
* A &#x2A;*[Coder API token](/beta-docs/admin/users/sessions-tokens/#generate-a-long-lived-api-token-on-behalf-of-yourself)**.

## Configuration [#configuration]

<Tabs items="[&#x22;OpenAI&#x22;, &#x22;Anthropic&#x22;]" groupId="coder-docs-tab:anthropic-openai" persist="true">
  <Tab value="OpenAI">
    1. Open Mux settings (`Cmd+,` / `Ctrl+,`).
    2. Go to **Providers** → **OpenAI**.
    3. Set **API Key** to your Coder API token.
    4. Set **Base URL** to `https://coder.example.com/api/v2/ai-gateway/openai/v1`.
  </Tab>

  <Tab value="Anthropic">
    1. Open Mux settings (`Cmd+,` / `Ctrl+,`).
    2. Go to **Providers** → **Anthropic**.
    3. Set **API Key** to your Coder API token.
    4. Set **Base URL** to `https://coder.example.com/api/v2/ai-gateway/anthropic`.
  </Tab>
</Tabs>

*Replace `coder.example.com` with your Coder deployment URL.*

## Environment variables [#environment-variables]

Mux reads provider configuration from its settings UI and also from environment variables.
Environment variables are useful in CI or when running Mux inside a Coder workspace.

<Callout type="info" title="Note">
  Mux treats environment variables as a fallback when a provider is not configured in settings.
  If you have already configured a provider in the UI, clear it (or update it) for env vars to take effect.
</Callout>

```sh
# OpenAI-compatible traffic (GPT, Codex, etc.)
export OPENAI_API_KEY="<your-coder-api-token>"
export OPENAI_BASE_URL="https://coder.example.com/api/v2/ai-gateway/openai/v1"

# Anthropic-compatible traffic (Claude, etc.)
export ANTHROPIC_API_KEY="<your-coder-api-token>"
export ANTHROPIC_BASE_URL="https://coder.example.com/api/v2/ai-gateway/anthropic"
```

## Run Mux in a Coder workspace [#run-mux-in-a-coder-workspace]

To run Mux inside a Coder workspace (for example, as a Coder app), you can install it with the [Mux module](https://registry.coder.com/modules/coder/mux) and pre-configure AI Gateway via environment variables on the agent:

```tf
data "coder_workspace" "me" {}

data "coder_workspace_owner" "me" {}

resource "coder_agent" "main" {
  # ... other agent configuration
  env = {
    OPENAI_API_KEY     = data.coder_workspace_owner.me.session_token
    OPENAI_BASE_URL    = "${data.coder_workspace.me.access_url}/api/v2/ai-gateway/openai/v1"
    ANTHROPIC_API_KEY  = data.coder_workspace_owner.me.session_token
    ANTHROPIC_BASE_URL = "${data.coder_workspace.me.access_url}/api/v2/ai-gateway/anthropic"
  }
}

module "mux" {
  source   = "registry.coder.com/coder/mux/coder"
  version  = "~> 1.5"
  agent_id = coder_agent.main.id
}
```

## Advanced: providers.jsonc [#advanced-providersjsonc]

If you prefer a file-based config, edit `~/.mux/providers.jsonc`:

```json
{
  "openai": {
    "apiKey": "<your-coder-api-token>",
    "baseUrl": "https://coder.example.com/api/v2/ai-gateway/openai/v1"
  },
  "anthropic": {
    "apiKey": "<your-coder-api-token>",
    "baseUrl": "https://coder.example.com/api/v2/ai-gateway/anthropic"
  }
}
```

**References:** [Mux provider environment variables](https://mux.coder.com/config/providers#environment-variables)
