Coding Tools
GitHub Copilot CLI
Connect GitHub Copilot CLI to TokenLab with BYOK
Overview
GitHub Copilot CLI can connect to any OpenAI Chat Completions-compatible endpoint. TokenLab works through Copilot CLI's BYOK environment variables.
Install
With Node.js 22 or later, install through npm:
npm install -g @github/copilot@1.0.85On macOS or Linux, you can alternatively use Homebrew:
brew install --cask copilot-cliVerify the installation:
copilot --versionConfigure TokenLab
Set the provider variables before starting Copilot CLI:
Use the Quickstart terminal instructions for macOS, Linux, WSL, or Windows PowerShell to set TOKENLAB_API_KEY without putting the key in command history. Launch Copilot CLI from that terminal. For persistent use, use your local secret manager; do not append a plaintext key to your shell profile.
These variables apply only to this launch; your saved account, default model and permission settings stay in place. Launch normally without the variables to use your previous setup. Do not persist them in your shell profile.
COPILOT_PROVIDER_TYPE=openai COPILOT_PROVIDER_BASE_URL=https://api.tokenlab.sh/v1 COPILOT_PROVIDER_API_KEY="${TOKENLAB_API_KEY:?Set TOKENLAB_API_KEY first}" copilot --model claude-sonnet-5-5| Variable | TokenLab value |
|---|---|
COPILOT_PROVIDER_TYPE | openai |
COPILOT_PROVIDER_BASE_URL | https://api.tokenlab.sh/v1 |
COPILOT_PROVIDER_API_KEY | Your TokenLab API key |
COPILOT_MODEL | A live model ID, for example claude-sonnet-5-5 |
GitHub requires the selected model to support both streaming and tool calling. claude-sonnet-5-5 supports tool calling and has a context window larger than GitHub's recommended 128K minimum.
Verify
Inside Copilot CLI, ask for a read-only action first, such as:
Inspect this repository and summarize its top-level structure. Do not modify files.Saving settings or listing models does not verify a key or a completed request. A prompt uses TokenLab balance. Check the reply and its matching request record before trying tools; auxiliary requests may also be billed.
To see the provider settings Copilot CLI documents, run:
copilot help providersGenerate images and video in the same agent
Copilot CLI can also create images and short videos with the TokenLab MCP server. Each generation is paid from the same TokenLab balance. Merge this entry into ~/.copilot/mcp-config.json. Copilot CLI passes only PATH to the server, so both variables go in env:
{
"mcpServers": {
"tokenlab": {
"type": "local",
"command": "npx",
"args": ["-y", "@tokenlabai/mcp-server@0.6.48"],
"env": {
"TOKENLAB_MCP_TOOL_PROFILE": "core",
"TOKENLAB_API_KEY": "<TOKENLAB_API_KEY>"
},
"tools": ["*"]
}
}
}Replace <TOKENLAB_API_KEY> with your key in this local file only. Start Copilot CLI and run /mcp show tokenlab to check the connection. Then try:
Call get_model_pricing for nano-banana-2, then use create_image with nano-banana-2 at 1k to make a photo of a matte black coffee mug on a white desk.create_video returns a task ID. The agent calls get_task_status until the video is ready. See Add MCP servers to Copilot CLI for other settings.
Troubleshooting
Do not commit API keys to shell scripts or dotfiles tracked by Git. Rotate any key that was exposed in terminal history, screenshots, or logs.