Use Copilot CLI with Models Hub: BYOK Environment Variables
Point GitHub Copilot CLI at Models Hub using BYOK environment variables; use the anthropic protocol type to avoid reasoning-model errors, with verification and error troubleshooting.
GitHub Copilot CLI is GitHub's official terminal AI coding assistant, and it supports BYOK (Bring Your Own Key) mode for connecting to a custom model endpoint. Point its provider environment variables at Models Hub and every chat and code edit inside copilot uses your Models Hub balance for the model you choose. This page covers the connection only, not how to use Copilot CLI itself.
Three things you need
A Models Hub API key, a base URL, and a model name, set once through environment variables. There's no one-click setup — Copilot CLI isn't one of the targets the Models Hub CLI supports.
Prerequisites
- Copilot CLI installed. Run
npm install -g @github/copilot(Node.js 22 or later required);copilot --versionshould print a version afterward. See the official getting started guide for details. - A Models Hub API key, created on the Tokens page. The token's group must have access to the models you plan to use.
Recommended models
| Use case | Model | Pricing | Live status |
|---|---|---|---|
| Everyday coding | claude-sonnet-4-6 | Price | Availability and latency |
| Harder reasoning and long tasks | gpt-5.6-luna | Price | Availability and latency |
| Cheap and fast for small edits | gpt-5.4-mini | Price | Availability and latency |
Model names are authoritative on the pricing page.
Setup
Copilot CLI reads custom provider configuration from environment variables, and supports two protocol types: anthropic and openai.
Use the anthropic type
Some reasoning models require reasoning_content to be passed back verbatim on the next turn. Copilot CLI's OpenAI integration doesn't support this and can trigger a 400 error. The anthropic type avoids it — use it regardless of whether you pick a Claude or GPT model. Only consider openai if you're exclusively running lightweight, non-reasoning models.
Linux / macOS
export COPILOT_PROVIDER_TYPE="anthropic"
export COPILOT_PROVIDER_BASE_URL="https://modelsok.com"
export COPILOT_PROVIDER_API_KEY="your-models-hub-api-key"
export COPILOT_MODEL="claude-sonnet-4-6"Windows (PowerShell)
$env:COPILOT_PROVIDER_TYPE="anthropic"
$env:COPILOT_PROVIDER_BASE_URL="https://modelsok.com"
$env:COPILOT_PROVIDER_API_KEY="your-models-hub-api-key"
$env:COPILOT_MODEL="claude-sonnet-4-6"| Variable | Purpose |
|---|---|
COPILOT_PROVIDER_TYPE | Protocol type: anthropic or openai |
COPILOT_PROVIDER_BASE_URL | The base URL; the anthropic type doesn't take /v1, the openai type does (https://modelsok.com/v1) |
COPILOT_PROVIDER_API_KEY | Your Models Hub API key |
COPILOT_MODEL | The default model name; must exactly match the name on the pricing page |
For non-reasoning models only, you can switch COPILOT_PROVIDER_TYPE to openai and change COPILOT_PROVIDER_BASE_URL to https://modelsok.com/v1. Add these lines to ~/.bashrc / ~/.zshrc or your PowerShell profile to make them persistent — otherwise they only last for the current terminal session.
Verify
Launch copilot and ask any coding question, for example "write me a Python function that reads a JSON file". A normal reply means you're connected. Run copilot help providers to see the currently active provider environment variables. Then open Usage logs in the Models Hub console; a request under your configured model name appears within seconds.
Common errors
| Symptom | Cause | Fix |
|---|---|---|
400 Bad Request | Under the openai type, a reasoning model's reasoning_content can't be passed back | Switch COPILOT_PROVIDER_TYPE to anthropic |
| Model not found | COPILOT_MODEL is misspelled or doesn't match the pricing page | Check the name on the pricing page |
401 / invalid API key | Wrong key, stray whitespace, or a disabled token | Re-copy from the Tokens page |
| Environment variables not taking effect | A new shell was opened, or they weren't saved to a config file | Add them to ~/.bashrc / ~/.zshrc / your PowerShell profile and reopen the terminal |
| Output is truncated | The default output token limit is too low | Set COPILOT_PROVIDER_MAX_OUTPUT_TOKENS to a higher value |
More in Troubleshooting.
FAQ
How is it billed? Per input and output token actually consumed, at the price on each model's pricing page; every request is itemized in usage logs.
How is this different from using my GitHub Copilot subscription directly? Once BYOK is configured, model calls go through Models Hub instead of your Copilot subscription's model quota. Agent mode, tool calling, and MCP still work, but features tightly bound to GitHub-hosted infrastructure — /delegate, the GitHub MCP server, and GitHub code search — still require GitHub sign-in.
How do I switch models? Change the COPILOT_MODEL environment variable and restart copilot. The model name must exactly match the one on the pricing page.
Related
- CLI one-command setup: Claude Code, Codex, Gemini CLI and OpenClaw support one-click configuration
- Model pricing and model status
- Claude Code setup, Codex CLI setup
Use Gemini CLI with Models Hub: One-Click and Manual Setup
Configure Gemini CLI for Models Hub with one Models Hub CLI command, or edit settings.json and .env manually to reach Google Gemini models, with verification and error troubleshooting.
Use Cursor with Models Hub: Custom Base URL for Claude and GPT
Connect Cursor to Models Hub via Override OpenAI Base URL and call Claude, GPT and other models with one API key. Includes model names, verification and fixes for 'does not work with your current plan'.