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

# Copilot

> Connect GitHub Copilot workflows to HaiRoute

This guide covers connecting the terminal `copilot` CLI to HaiRoute through environment variables.

<Note>
  This guide covers **Copilot CLI** (the terminal `copilot` command). VS Code Copilot Chat BYOK integration is not covered here — the setup varies significantly across VS Code versions and channels, and the official experience is still evolving.
</Note>

## Prerequisites

* A HaiRoute API key
* At least one available model ID, such as `gpt-5.4`
* HaiRoute OpenAI-compatible base URL: `https://api.hairoute.ai/v1`

<Tip>
  The model ID here means the **model identifier** shown on the HaiRoute homepage or model list, for example `gpt-5.4`. Do not paste the display name into `COPILOT_MODEL`, or you will likely get a model-not-found error.
</Tip>

## Setup Steps

<Note>
  Copilot CLI officially supports both `openai` and `anthropic` provider types. For HaiRoute, `openai` is the recommended default, but you can also use `anthropic` if you explicitly want the Claude / Anthropic ecosystem.
</Note>

### Step 1: Set provider environment variables

<Warning>
  If you use Windows Terminal, pay special attention to this: different tabs and panes do not share environment variables that you set temporarily inside one PowerShell session. In practice, you must set the `COPILOT_*` variables and launch `copilot` from the **same shell**, or Copilot CLI may keep using the default model or an older configuration.
</Warning>

Windows PowerShell:

```powershell theme={null}
$env:COPILOT_PROVIDER_BASE_URL = "https://api.hairoute.ai/v1"
$env:COPILOT_PROVIDER_TYPE = "openai"
$env:COPILOT_PROVIDER_API_KEY = "YOUR_API_KEY"
$env:COPILOT_MODEL = "gpt-5.4"
```

macOS / Linux:

```bash theme={null}
export COPILOT_PROVIDER_BASE_URL="https://api.hairoute.ai/v1"
export COPILOT_PROVIDER_TYPE="openai"
export COPILOT_PROVIDER_API_KEY="YOUR_API_KEY"
export COPILOT_MODEL="gpt-5.4"
```

If you explicitly want the Claude / Anthropic path, you can switch to this configuration instead:

Windows PowerShell:

```powershell theme={null}
$env:COPILOT_PROVIDER_BASE_URL = "https://api.hairoute.ai"
$env:COPILOT_PROVIDER_TYPE = "anthropic"
$env:COPILOT_PROVIDER_API_KEY = "YOUR_API_KEY"
$env:COPILOT_MODEL = "gpt-5.4"
```

macOS / Linux:

```bash theme={null}
export COPILOT_PROVIDER_BASE_URL="https://api.hairoute.ai"
export COPILOT_PROVIDER_TYPE="anthropic"
export COPILOT_PROVIDER_API_KEY="YOUR_API_KEY"
export COPILOT_MODEL="gpt-5.4"
```

### Step 2: Start Copilot CLI

Launch it from the same terminal session:

```bash theme={null}
copilot
```

### Step 3: Send a simple test request

Ask a simple question such as `hello` or ask it to explain the current file. If it responds normally, the CLI is working through HaiRoute.

### Notes

| Item               | Value                                                                                        |
| ------------------ | -------------------------------------------------------------------------------------------- |
| Provider type      | Prefer `openai`; `anthropic` is also supported                                               |
| Base URL           | Use `https://api.hairoute.ai/v1` for `openai`; use `https://api.hairoute.ai` for `anthropic` |
| Auth header        | `Authorization: Bearer YOUR_API_KEY`                                                         |
| Model requirements | The official docs say the model should support streaming and tool calling                    |

If you run Copilot CLI in an isolated environment, you can also set `COPILOT_OFFLINE=true` as documented by GitHub, but that does not change the HaiRoute integration pattern itself.

### How persistence differs by OS

* Windows: usually add the variables to your PowerShell profile or your own startup script
* macOS: if you use `zsh`, the common place is `~/.zshrc`
* Linux: if you use `bash`, the common place is `~/.bashrc`; if you use `zsh`, the common place is `~/.zshrc`

## Verification

1. Launch `copilot` from the same shell where you set the environment variables.
2. Send a simple prompt such as `hello`.
3. If it returns a normal response, the integration works.

## How to switch models

**Copilot CLI does not let you switch models inside the running session. It reads the model from environment variables before startup.**

That means the correct switching flow is:

1. Exit the current `copilot` session
2. Change `COPILOT_MODEL`
3. Restart `copilot` from the same shell

Windows PowerShell example:

```powershell theme={null}
# Exit the current copilot session first, then run:
$env:COPILOT_MODEL = "gpt-5.4"
copilot
```

macOS / Linux example:

```bash theme={null}
# Exit the current copilot session first, then run:
export COPILOT_MODEL="gpt-5.4"
copilot
```

If you also need to change the provider endpoint or API key, update those variables before restarting `copilot` as well.

### Important note for Windows Terminal users

If you use Windows Terminal, different tabs and panes do not share environment variables that were set temporarily inside one PowerShell session.

So the correct order is:

1. Set `COPILOT_MODEL` in the current PowerShell session
2. Do not switch to another tab or pane
3. Launch `copilot` directly from that same shell

### How to confirm the model switch worked

You can verify it in a few ways:

* Check the variables before launch with `Get-ChildItem Env:COPILOT*`
* Look at the model name shown in the bottom-right corner after `copilot` starts
* If the CLI prints `Model "xxx" is not in the built-in catalog`, that usually means it has already read your custom model name

## FAQ

| Question                                                            | Fix                                                                                                                                                                                                                                                                                                                 |
| ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| I changed `COPILOT_MODEL`, but the session still uses the old model | The `copilot` CLI reads environment variables before startup. Exit the current session, change `COPILOT_MODEL` in the same shell, and then start `copilot` again.                                                                                                                                                   |
| Copilot CLI returns `400 Bad Request`                               | Check whether `COPILOT_PROVIDER_TYPE` is set to `openai`, and whether `COPILOT_PROVIDER_BASE_URL` is `https://api.hairoute.ai/v1`.                                                                                                                                                                                  |
| I want to use the Claude / Anthropic mode                           | Change `COPILOT_PROVIDER_TYPE` to `anthropic` and change `COPILOT_PROVIDER_BASE_URL` to `https://api.hairoute.ai`. Do not keep using the OpenAI-style `/v1` address for this mode.                                                                                                                                  |
| Copilot CLI says the model does not exist                           | Make sure `COPILOT_MODEL` exactly matches a model ID exposed by HaiRoute.                                                                                                                                                                                                                                           |
| Environment variable changes do not take effect                     | Make sure `copilot` is launched from the **same shell** where you set the variables. If you use Windows Terminal, remember that different tabs and panes do not share environment variables that were set temporarily inside one PowerShell session. If needed, persist the variables in the correct shell profile. |

## Next

* See [Get API Key](/docs/en/quickstart/get-api-key)
* See [OpenAI format API](/docs/en/api-reference/chat/openai-format)
* See [List models](/docs/en/api-reference/models/list-models)
