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
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
Windows PowerShell:Step 2: Start Copilot CLI
Launch it from the same terminal session:Step 3: Send a simple test request
Ask a simple question such ashello 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 usezsh, the common place is~/.zshrc
Verification
- Launch
copilotfrom the same shell where you set the environment variables. - Send a simple prompt such as
hello. - 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:- Exit the current
copilotsession - Change
COPILOT_MODEL - Restart
copilotfrom the same shell
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:- Set
COPILOT_MODELin the current PowerShell session - Do not switch to another tab or pane
- Launch
copilotdirectly 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
copilotstarts - 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
- See Get API Key
- See OpenAI format API
- See List models