Skip to main content
Copilot needs to be split into two integration paths because they do not use the same configuration flow:
  1. VS Code / Copilot Chat BYOK: connect a custom model through VS Code language model management
  2. Copilot CLI BYOK: point the terminal copilot CLI to an external model provider through environment variables
Both can work with HaiToken, but the entry points and capability boundaries are different.

What you need

  • A HaiToken API key
  • At least one available model ID, such as deepseek-v4-flash
  • HaiToken OpenAI-compatible base URL: https://api.haitoken.ai/v1

Mode 1: VS Code / Copilot Chat

Use this path if you want to use HaiToken-backed models inside VS Code Chat.
GitHub and VS Code already support BYOK, but the exact entry points can differ by plan, version, and channel. For OpenAI-compatible custom endpoints specifically, some versions may still expose that option only in preview or only in certain builds. Follow the UI that exists in your current version.

Step 1: Open language model management

In VS Code, open the chat model picker and go to Manage Language Models, or run Chat: Manage Language Models from the Command Palette.

Step 2: Add a custom model or provider

If your current version shows an OpenAI Compatible provider entry, use that first. If it does not, use the provider path your current version supports, such as:
  • a built-in BYOK provider
  • a language model provider extension

Step 3: Fill the HaiToken values

If the version supports an OpenAI-compatible provider, use the following values:
FieldRecommended value
API Typechat-completions or the current version’s OpenAI Chat Completions equivalent
Endpoint / Base URLhttps://api.haitoken.ai/v1
API KeyYour HaiToken API key
Model IDA real HaiToken model ID such as deepseek-v4-flash

Step 4: Switch to the model in chat

After saving, return to the Chat view and select the newly added HaiToken-backed model from the model picker.

Notes

This path mainly applies to VS Code Chat and related agent workflows. It should not be interpreted as “all Copilot features now use HaiToken.” In particular, standard code completions are explicitly outside the documented BYOK scope.

Mode 2: Copilot CLI

Use this path for the terminal copilot CLI. GitHub’s official BYOK documentation for this flow is much more explicit, which also makes HaiToken integration more predictable.
Copilot CLI officially supports both openai and anthropic provider types. For HaiToken, openai is still 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:
$env:COPILOT_PROVIDER_BASE_URL = "https://api.haitoken.ai/v1"
$env:COPILOT_PROVIDER_TYPE = "openai"
$env:COPILOT_PROVIDER_API_KEY = "YOUR_API_KEY"
$env:COPILOT_MODEL = "deepseek-v4-flash"
macOS / Linux:
export COPILOT_PROVIDER_BASE_URL="https://api.haitoken.ai/v1"
export COPILOT_PROVIDER_TYPE="openai"
export COPILOT_PROVIDER_API_KEY="YOUR_API_KEY"
export COPILOT_MODEL="deepseek-v4-flash"
If you explicitly want the Claude / Anthropic path, you can switch to this configuration instead: Windows PowerShell:
$env:COPILOT_PROVIDER_BASE_URL = "https://api.haitoken.ai"
$env:COPILOT_PROVIDER_TYPE = "anthropic"
$env:COPILOT_PROVIDER_API_KEY = "YOUR_API_KEY"
$env:COPILOT_MODEL = "deepseek-v4-flash"
macOS / Linux:
export COPILOT_PROVIDER_BASE_URL="https://api.haitoken.ai"
export COPILOT_PROVIDER_TYPE="anthropic"
export COPILOT_PROVIDER_API_KEY="YOUR_API_KEY"
export COPILOT_MODEL="deepseek-v4-flash"

Step 2: Start Copilot CLI

Launch it from the same terminal session:
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 HaiToken.

Notes

ItemValue
Provider typePrefer openai; anthropic is also supported
Base URLUse https://api.haitoken.ai/v1 for openai; use https://api.haitoken.ai for anthropic
Auth headerAuthorization: Bearer YOUR_API_KEY
Model requirementsThe 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 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. If you use the VS Code Chat path, switch to the HaiToken-backed model in the chat model picker and send a simple prompt.
  2. If you use the Copilot CLI path, launch copilot from the same shell and send a simple prompt.
  3. If it returns a normal response, the integration works.

How to switch models

VS Code / Copilot Chat

If you use the VS Code / Copilot Chat path, go back to the chat panel and switch to another model from the model picker. If your current version has already added the HaiToken-backed models to the language model list, you can switch between them there without changing environment variables.

Copilot CLI

If you use the copilot CLI, this is the key point: 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:
# Exit the current copilot session first, then run:
$env:COPILOT_MODEL = "deepseek-v4-pro"
copilot
macOS / Linux example:
# Exit the current copilot session first, then run:
export COPILOT_MODEL="deepseek-v4-pro"
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

QuestionFix
I cannot find an OpenAI-compatible entry in VS CodeFirst confirm whether your current VS Code / Copilot version exposes that BYOK or OpenAI Compatible entry. The visible entry points can differ by version and channel, so in some setups you may need to rely on a supported provider extension path instead.
Chat works but code completions do not changeThat is expected. The official BYOK docs focus on chat and related agent experiences, not standard code completions.
I changed COPILOT_MODEL, but the session still uses the old modelThe 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 RequestCheck whether COPILOT_PROVIDER_TYPE is set to openai, and whether COPILOT_PROVIDER_BASE_URL is https://api.haitoken.ai/v1.
I want to use the Claude / Anthropic modeChange COPILOT_PROVIDER_TYPE to anthropic and change COPILOT_PROVIDER_BASE_URL to https://api.haitoken.ai. Do not keep using the OpenAI-style /v1 address for this mode.
Copilot CLI says the model does not existMake sure COPILOT_MODEL exactly matches a model ID exposed by HaiToken.
Environment variable changes do not take effectMake 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