Copilot CLI
GitHub Copilot CLI tutorial โ Connect GitHub's official terminal AI coding assistant to EasyRouter via BYOK mode. Supports Agent mode, tool calling, and MCP.
Project Introduction
GitHub Copilot CLI is GitHub's official terminal AI coding assistant. It supports BYOK (Bring Your Own Key) mode for custom model endpoints, letting you point it at EasyRouter via a few environment variables. Agent mode, tool calling, and MCP are all supported.
This tutorial shows how to point Copilot CLI at EasyRouter using BYOK mode.
๐ฆ Prerequisites
What you'll need
- Node.js 22 or later
- An EasyRouter endpoint (must end with
/v1) - An EasyRouter API key (generated in the console)
- A model ID exactly matching one exposed by your EasyRouter console (e.g.
claude-sonnet-4-6,gemini-2.5-flash)
๐ Step 1: Install Copilot CLI
npm install -g @github/copilotVerify the install:
copilot --versionFull setup steps are in GitHub's getting started guide.
๐ง Step 2: Point it at EasyRouter
Copilot CLI reads provider config from environment variables. Use anthropic as the provider type for the best compatibility.
Linux / macOS
export COPILOT_PROVIDER_TYPE=anthropic
export COPILOT_PROVIDER_BASE_URL=https://easyrouter.io/v1
export COPILOT_PROVIDER_API_KEY=your-easyrouter-api-key
export COPILOT_MODEL=claude-sonnet-4-6Windows (PowerShell)
$env:COPILOT_PROVIDER_TYPE="anthropic"
$env:COPILOT_PROVIDER_BASE_URL="https://easyrouter.io/v1"
$env:COPILOT_PROVIDER_API_KEY="your-easyrouter-api-key"
$env:COPILOT_MODEL="claude-sonnet-4-6"Why anthropic type is recommended
Some models (especially reasoning models) require reasoning_content to be echoed back verbatim in the next turn. Copilot CLI's OpenAI integration doesn't support that mechanism, which can trigger 400 errors. Using the Anthropic Messages API compatible endpoint avoids this.
If you only use non-reasoning models (e.g. gemini-2.5-flash), you may set COPILOT_PROVIDER_TYPE=openai instead.
Optional: context / output token limits
export COPILOT_PROVIDER_MAX_PROMPT_TOKENS=840000
export COPILOT_PROVIDER_MAX_OUTPUT_TOKENS=128000โ Step 3: Launch & verify
copilotAsk any coding question (e.g. "Write a Python function that reads a JSON file"). A normal response means you're set.
copilot help providerslists every provider-related environment variable.
๐ Switching models
Change COPILOT_MODEL and restart:
export COPILOT_MODEL=gemini-2.5-flash
copilotThe model name must exactly match the model ID exposed by your EasyRouter console.
โ Troubleshooting
| Issue | Fix |
|---|---|
400 Bad Request | Switch COPILOT_PROVIDER_TYPE to anthropic |
| Model not found | Confirm COPILOT_MODEL exactly matches the EasyRouter model ID |
| Invalid API key | Regenerate a key in the EasyRouter console and update the env var |
| Variables don't take effect | New shell needed, or persist them in ~/.bashrc / ~/.zshrc / PowerShell profile |
| Output truncated | Raise COPILOT_PROVIDER_MAX_OUTPUT_TOKENS |