Copilot CLI
**Project Introduction**
Copilot CLI
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 AutoRouter via a few environment variables. Agent mode, tool calling, and MCP are all supported.
- Official docs: https://docs.github.com/copilot/how-tos/copilot-cli/cli-getting-started
- Package: https://www.npmjs.com/package/@github/copilot
This tutorial shows how to point Copilot CLI at AutoRouter using BYOK mode.
📦 Prerequisites
What you'll need
- Node.js 22 or later
- An AutoRouter endpoint (must end with
/v1) - An AutoRouter API key (generated in the console)
- A model ID exactly matching one exposed by your AutoRouter 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 AutoRouter
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://autorouter.top/v1
export COPILOT_PROVIDER_API_KEY=your-autorouter-api-key
export COPILOT_MODEL=claude-sonnet-4-6Windows (PowerShell)
$env:COPILOT_PROVIDER_TYPE="anthropic"
$env:COPILOT_PROVIDER_BASE_URL="https://autorouter.top/v1"
$env:COPILOT_PROVIDER_API_KEY="your-autorouter-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:
copilotThe model name must exactly match the model ID exposed by your AutoRouter console.
❓ Troubleshooting
| Issue | Fix |
|---|---|
400 Bad Request | Switch COPILOT_PROVIDER_TYPE to anthropic |
| Model not found | Confirm COPILOT_MODEL exactly matches the AutoRouter model ID |
| Invalid API key | Regenerate a key in the AutoRouter 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 |