Skip to main content
This guide covers connecting the terminal copilot CLI to HaiToken through environment variables.
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.

Prerequisites

  • A HaiToken API key
  • At least one available model ID, such as gpt-5.4
  • HaiToken OpenAI-compatible base URL: https://api.haitoken.ai/v1
The model ID here means the model identifier shown on the HaiToken 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.

Setup Steps

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

Step 1: Set provider environment variables

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.
Windows PowerShell:
macOS / Linux:
If you explicitly want the Claude / Anthropic path, you can switch to this configuration instead: Windows PowerShell:
macOS / Linux:

Step 2: Start Copilot CLI

Launch it from the same terminal session:

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 HaiToken.

Notes

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 HaiToken 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:
macOS / Linux example:
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

Next