Models Hub
Agent Tools

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.

Edit this page

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 --version should 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.
Use caseModelPricingLive status
Everyday codingclaude-sonnet-4-6PriceAvailability and latency
Harder reasoning and long tasksgpt-5.6-lunaPriceAvailability and latency
Cheap and fast for small editsgpt-5.4-miniPriceAvailability 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"
VariablePurpose
COPILOT_PROVIDER_TYPEProtocol type: anthropic or openai
COPILOT_PROVIDER_BASE_URLThe base URL; the anthropic type doesn't take /v1, the openai type does (https://modelsok.com/v1)
COPILOT_PROVIDER_API_KEYYour Models Hub API key
COPILOT_MODELThe 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

SymptomCauseFix
400 Bad RequestUnder the openai type, a reasoning model's reasoning_content can't be passed backSwitch COPILOT_PROVIDER_TYPE to anthropic
Model not foundCOPILOT_MODEL is misspelled or doesn't match the pricing pageCheck the name on the pricing page
401 / invalid API keyWrong key, stray whitespace, or a disabled tokenRe-copy from the Tokens page
Environment variables not taking effectA new shell was opened, or they weren't saved to a config fileAdd them to ~/.bashrc / ~/.zshrc / your PowerShell profile and reopen the terminal
Output is truncatedThe default output token limit is too lowSet 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.

On this page