Copilot CLI
Connect to a custom OpenAI-compatible model gateway via BYOK mode.
About the Project
GitHub Copilot CLI is GitHub's official terminal-based AI coding assistant. It supports BYOK (Bring Your Own Key) mode for connecting to custom model endpoints, and can integrate directly with Models Hub through environment variables. It supports Agent mode, tool calling, and MCP.
- Official docs: https://docs.github.com/copilot/how-tos/copilot-cli/cli-getting-started
- Package: https://www.npmjs.com/package/@github/copilot
This guide explains how to point Copilot CLI at Models Hub using BYOK mode, so you can use models distributed through the Models Hub gateway for everyday coding tasks.
📦 Before You Begin
What you'll need
- Node.js 22 or later
- A working Models Hub address (must end with
/v1) - A working Models Hub API Key (generated in the console)
- The name of the model you want to use (such as
claude-sonnet-4-6,gemini-2.5-flash, etc.), which must exactly match the model ID in the Models Hub console
🚀 Step 1: Install Copilot CLI
npm install -g @github/copilotAfter installation, verify the version:
copilot --versionFor detailed installation instructions, see the official getting started guide.
🔧 Step 2: Configure Models Hub (the core step)
Copilot CLI reads custom provider configuration from environment variables. Using the anthropic type is recommended for the best compatibility.
Linux / macOS
export MODELSOK_API_KEY="ms_live_your_key"Windows (PowerShell)
$env:COPILOT_PROVIDER_TYPE="anthropic"
$env:COPILOT_PROVIDER_BASE_URL="https://modelsok.com/v1"
$env:COPILOT_PROVIDER_API_KEY="your-modelsok-api-key"
$env:COPILOT_MODEL="claude-sonnet-4-6"Why the anthropic type is recommended
Some models (especially reasoning models with a chain of thought) require reasoning_content to be passed back verbatim in the next request. Copilot CLI's OpenAI integration does not support this mechanism and may trigger a 400 error. Switching to an Anthropic Messages API-compatible endpoint avoids this issue.
If you only use non-reasoning models (such as gemini-2.5-flash), you can also set COPILOT_PROVIDER_TYPE to openai.
Optional: Adjust context and output limits
export MODELSOK_API_KEY="ms_live_your_key"✅ Step 3: Launch and Verify
copilotEnter any programming question (for example, "Write me a Python function that reads a JSON file"). If the model responds normally, the configuration is successful.
copilot help providersThis lists all provider-related environment variables and their descriptions.
🔄 Switching Models
Just change the COPILOT_MODEL environment variable and restart copilot:
copilotThe model name must exactly match the model ID exposed in the Models Hub console.
❓ FAQ
| Problem | Solution |
|---|---|
400 Bad Request error | Switch COPILOT_PROVIDER_TYPE to anthropic |
| Model not found | Confirm that COPILOT_MODEL matches the model ID in the Models Hub console |
| Invalid API Key | Regenerate the Key in the Models Hub console and update the environment variable |
| Environment variables not taking effect | Check whether you opened a new shell, or write the variables into ~/.bashrc / ~/.zshrc / your PowerShell profile |
| Output is truncated | Increase the value of COPILOT_PROVIDER_MAX_OUTPUT_TOKENS |