Swap GitHub Copilot’s Built-in Model for Claude Opus 4.7: A Hands-On BYOK Guide
By default, GitHub Copilot routes through GitHub’s own model backend — meaning you don’t control which model version you’re running, and latency can be unpredictable depending on your region. Many developers want to run Claude Opus 4.7 directly for code generation and Agent tasks without paying for yet another subscription.
GitHub has officially opened up BYOK (Bring Your Own Key) support in Copilot CLI. With just four environment variables, you can point the model backend to any Anthropic-compatible endpoint — including ClaudeAPI.com. This guide covers two integration paths — Copilot CLI and VS Code’s built-in Chat view — with complete download, install, configuration, and verification steps. Follow along and you’ll be up and running in under 10 minutes.
Why the Default Copilot Setup Falls Short
Pain points you can’t avoid with the default Copilot experience:
- Unreliable access in some regions: Both Copilot CLI and the VS Code extension route through GitHub’s own proxy — 401 errors and timeouts are common.
- No model choice: The “Claude Sonnet” you see in Copilot? GitHub’s backend decides which version that actually is, and new model availability lags behind.
- Agent tasks burn through your quota: Subscription quota gets consumed heavily by automated Agent calls — once you hit the ceiling, there’s no instant way to scale up.
The fix: point the model backend directly to an Anthropic-compatible relay endpoint. The API protocol is identical — you only change one URL and one key.
Endpoint used in this guide:
https://gw.claudeapi.com
https://gw.claudeapi.com
Get your API Key at claudeapi.com — sign up and start using it immediately.
1. Sign Up & Prepare
- Visit claudeapi.com and register with your email
- Go to the console.claudeapi.com dashboard
- Add funds to your account
- Create an API Key (you must select a group) and copy the key starting with
sk-
Save the key in a local text editor — you’ll need it for every step below.
2. Download & Install Copilot CLI
Recent versions of GitHub CLI ship with copilot as a built-in subcommand — there’s no need to install the gh-copilot extension separately.
⚠️ Do not run
gh extension install github/gh-copilot— newer versions ofghwill return:copilot matches the name of a built-in command or alias
Official downloads:
- GitHub CLI homepage: https://cli.github.com/
- GitHub CLI Releases: https://github.com/cli/cli/releases
- Copilot CLI BYOK docs: https://docs.github.com/en/copilot/how-tos/copilot-cli/customize-copilot/use-byok-models
2.1 Install GitHub CLI
| Platform | Command |
|---|---|
| macOS | brew install gh |
| Windows | winget install --id GitHub.cli or scoop install gh |
| Ubuntu / Debian | sudo apt install gh (requires adding the GitHub CLI APT source first — see official docs) |
| Fedora / RHEL | sudo dnf install gh |
| Arch | sudo pacman -S github-cli |
Version requirement: gh ≥ 2.60 (minimum version with the built-in copilot subcommand). Verify with:
gh --version
gh --version
2.2 Verify the Copilot Subcommand Is Available
Call the built-in entry point directly — you do not need and should not run gh extension install:
gh copilot -- --help
gh copilot -- --help
You should see parameters like -p / --prompt, --stream, --no-color, --secret-env-vars in the output. If you get copilot matches the name of a built-in command or alias instead, you have a leftover legacy gh-copilot extension that needs to be removed first:
gh extension remove gh-copilot
gh extension remove gh-copilot
About subscriptions: In BYOK mode, model inference is handled by your configured custom provider (e.g., ClaudeAPI). Running
gh copilot help providersexplicitly states: GitHub authentication is not required when using a custom provider. In other words, your custom provider’s API Key is the prerequisite for model calls — a GitHub Copilot subscription is not strictly required. However, some advanced features (repo indexing, enterprise policies, etc.) still depend on GitHub authentication.
3. Configure Copilot CLI (Recommended Approach)
Switch to BYOK mode with four environment variables.
3.1 Field Reference
| Field | Value | Notes |
|---|---|---|
COPILOT_PROVIDER_TYPE |
anthropic |
Uses the native Anthropic protocol — do not set this to openai |
COPILOT_PROVIDER_BASE_URL |
https://gw.claudeapi.com |
Do not append /v1 — this is the Anthropic protocol root path |
COPILOT_PROVIDER_API_KEY |
sk-yourClaudeAPIkey |
The key you created on ClaudeAPI.com |
COPILOT_MODEL |
claude-opus-4-7 |
Must be set explicitly — the CLI cannot auto-discover models from the relay endpoint |
3.2 Full Environment Variable Configuration
macOS / Linux (add to ~/.zshrc or ~/.bashrc):
# === GitHub Copilot CLI BYOK: Connect to ClaudeAPI ===
export COPILOT_PROVIDER_TYPE="anthropic"
export COPILOT_PROVIDER_BASE_URL="https://gw.claudeapi.com"
export COPILOT_PROVIDER_API_KEY="sk-yourClaudeAPIkey"
export COPILOT_MODEL="claude-opus-4-7"
# === GitHub Copilot CLI BYOK: Connect to ClaudeAPI ===
export COPILOT_PROVIDER_TYPE="anthropic"
export COPILOT_PROVIDER_BASE_URL="https://gw.claudeapi.com"
export COPILOT_PROVIDER_API_KEY="sk-yourClaudeAPIkey"
export COPILOT_MODEL="claude-opus-4-7"
Apply the changes immediately:
source ~/.zshrc # or source ~/.bashrc
source ~/.zshrc # or source ~/.bashrc
Windows PowerShell (temporary — current session only):
$env:COPILOT_PROVIDER_TYPE = "anthropic"
$env:COPILOT_PROVIDER_BASE_URL = "https://gw.claudeapi.com"
$env:COPILOT_PROVIDER_API_KEY = "sk-yourClaudeAPIkey"
$env:COPILOT_MODEL = "claude-opus-4-7"
$env:COPILOT_PROVIDER_TYPE = "anthropic"
$env:COPILOT_PROVIDER_BASE_URL = "https://gw.claudeapi.com"
$env:COPILOT_PROVIDER_API_KEY = "sk-yourClaudeAPIkey"
$env:COPILOT_MODEL = "claude-opus-4-7"
Windows PowerShell (persistent — write to user environment variables):
[System.Environment]::SetEnvironmentVariable("COPILOT_PROVIDER_TYPE", "anthropic", "User")
[System.Environment]::SetEnvironmentVariable("COPILOT_PROVIDER_BASE_URL", "https://gw.claudeapi.com", "User")
[System.Environment]::SetEnvironmentVariable("COPILOT_PROVIDER_API_KEY", "sk-yourClaudeAPIkey", "User")
[System.Environment]::SetEnvironmentVariable("COPILOT_MODEL", "claude-opus-4-7", "User")
[System.Environment]::SetEnvironmentVariable("COPILOT_PROVIDER_TYPE", "anthropic", "User")
[System.Environment]::SetEnvironmentVariable("COPILOT_PROVIDER_BASE_URL", "https://gw.claudeapi.com", "User")
[System.Environment]::SetEnvironmentVariable("COPILOT_PROVIDER_API_KEY", "sk-yourClaudeAPIkey", "User")
[System.Environment]::SetEnvironmentVariable("COPILOT_MODEL", "claude-opus-4-7", "User")
Note: After writing to user-level environment variables, you must restart your terminal for changes to take effect.
Windows CMD (temporary):
set COPILOT_PROVIDER_TYPE=anthropic
set COPILOT_PROVIDER_BASE_URL=https://gw.claudeapi.com
set COPILOT_PROVIDER_API_KEY=sk-yourClaudeAPIkey
set COPILOT_MODEL=claude-opus-4-7
set COPILOT_PROVIDER_TYPE=anthropic
set COPILOT_PROVIDER_BASE_URL=https://gw.claudeapi.com
set COPILOT_PROVIDER_API_KEY=sk-yourClaudeAPIkey
set COPILOT_MODEL=claude-opus-4-7
3.3 Choose Your Model
Available model IDs for COPILOT_MODEL:
claude-opus-4-7
claude-opus-4-6
claude-sonnet-4-6
claude-haiku-4-5-20251001
claude-opus-4-7
claude-opus-4-6
claude-sonnet-4-6
claude-haiku-4-5-20251001
| Use Case | Recommendation |
|---|---|
| Complex code, architecture design, long context | claude-opus-4-7 |
| Everyday completions, single-file edits | claude-sonnet-4-6 (best price-performance ratio) |
| Bulk classification / comment generation | claude-haiku-4-5-20251001 |
Model requirements: Must support tool calling and streaming, with a context window ≥ 128k. All four IDs above meet these criteria.
3.4 Verify Connectivity (Required)
Step 1: Hit the base_url directly with HTTP to confirm Key + endpoint are working.
macOS / Linux using cURL:
curl https://gw.claudeapi.com/v1/messages \
-H "x-api-key: sk-yourClaudeAPIkey" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-opus-4-7",
"max_tokens": 256,
"messages": [{"role": "user", "content": "Reply with only pong"}]
}'
curl https://gw.claudeapi.com/v1/messages \
-H "x-api-key: sk-yourClaudeAPIkey" \
-H "anthropic-version: 2023-06-01" \
-H "content-type: application/json" \
-d '{
"model": "claude-opus-4-7",
"max_tokens": 256,
"messages": [{"role": "user", "content": "Reply with only pong"}]
}'
Windows PowerShell — use Invoke-RestMethod with a longer timeout (avoids Windows’ default 100s timeout cutting off longer responses):
$headers = @{
"x-api-key" = "sk-yourClaudeAPIkey"
"anthropic-version" = "2023-06-01"
"content-type" = "application/json"
}
$body = @{
model = "claude-opus-4-7"
max_tokens = 256
messages = @(@{ role = "user"; content = "Reply with only pong" })
} | ConvertTo-Json -Depth 5
Invoke-RestMethod -Method Post `
-Uri "https://gw.claudeapi.com/v1/messages" `
-Headers $headers `
-Body $body `
-TimeoutSec 120
$headers = @{
"x-api-key" = "sk-yourClaudeAPIkey"
"anthropic-version" = "2023-06-01"
"content-type" = "application/json"
}
$body = @{
model = "claude-opus-4-7"
max_tokens = 256
messages = @(@{ role = "user"; content = "Reply with only pong" })
} | ConvertTo-Json -Depth 5
Invoke-RestMethod -Method Post `
-Uri "https://gw.claudeapi.com/v1/messages" `
-Headers $headers `
-Body $body `
-TimeoutSec 120
Validation criteria (don’t hardcode the expected response body):
- HTTP status code 200
- The response JSON
contentarray contains at least one element withtype: "text"and a non-emptytextvalue - The
modelfield matches the model ID you requested
The model’s actual text response is natural language — it could be pong, Pong!, Sure, pong., or any other variation. As long as the three criteria above are met, the endpoint + key are working correctly. Don’t set max_tokens too low (128+ recommended) — otherwise normal output will be truncated.
Step 2: Run a Copilot command:
gh copilot -- -p "Give me a single PowerShell command: find all files larger than 100MB in the current directory. No explanation."
gh copilot -- -p "Give me a single PowerShell command: find all files larger than 100MB in the current directory. No explanation."
⚠️ The legacy syntax
gh copilot suggest "..."now returns Invalid command format — it has been replaced bygh copilot -- -p "...". Everything after--is passed directly to the copilot subprocess.
Example output:
Get-ChildItem -Recurse -File | Where-Object { $_.Length -gt 100MB }
Get-ChildItem -Recurse -File | Where-Object { $_.Length -gt 100MB }
If the response is an executable command and the exit code is 0, Copilot CLI is successfully running through ClaudeAPI.com.
For a minimal connectivity self-test (no streaming, no color codes in output, API key hidden from logs):
gh copilot -- -p "Reply with only pong" --no-color --stream off --secret-env-vars=COPILOT_PROVIDER_API_KEY
gh copilot -- -p "Reply with only pong" --no-color --stream off --secret-env-vars=COPILOT_PROVIDER_API_KEY
Again, just verify: exit code 0 + stdout contains non-empty text. Don’t assert that the output must exactly equal pong.
Offline mode: In BYOK mode, Copilot CLI still communicates with GitHub’s servers by default for embeddings, repo indexing, intent recognition, etc. — only model inference goes to your custom endpoint. If you need fully offline operation, refer to the offline mode configuration at https://docs.github.com/en/copilot/how-tos/copilot-cli/customize-copilot/use-byok-models (requires a local model).
4. VS Code Built-in Chat View (GUI Approach)
VS Code 1.94+ ships with a built-in Chat view that supports adding custom providers via Manage Models — more straightforward than the legacy Copilot Chat extension.
VS Code download: https://code.visualstudio.com/Download
Version requirement: VS Code ≥ 1.94. Check via Help → About.
4.1 Open the Configuration Panel
- Open VS Code
- Press
Ctrl + Shift + P(macOS:Cmd + Shift + P) to open the Command Palette - Type and select:
Chat: Manage Language Models - In the Language Models editor, click
Add Models - Select
Anthropicfrom the provider list
4.2 Fill In the Fields
| Field | Value |
|---|---|
| API Key | sk-yourClaudeAPIkey |
| Endpoint URL | https://gw.claudeapi.com |
| Model ID | claude-opus-4-7 (or any other supported ID) |
After saving, go back to the Chat view (the conversation icon in the sidebar). “Claude Opus 4.7” will appear in the model selector — just switch to it.
4.3 Enterprise Accounts: Enable the Policy First
Copilot Business / Enterprise accounts require a GitHub administrator to first enable the following in GitHub.com → Organization Settings → Copilot → Policies:
Bring Your Own Language Model Key in VS Code: Enabled
Otherwise the Add Models option will be grayed out.
4.4 Don’t Confuse: The Legacy Copilot Chat Extension Doesn’t Support BYOK
Avoid this common pitfall:
| Name | BYOK Support |
|---|---|
| VS Code Built-in Chat View (Manage Models) | ✅ Supported — the method in this section |
| GitHub Copilot Chat Extension (legacy) | ❌ Not supported — model is chosen server-side by GitHub |
If you only have the legacy Copilot Chat extension installed, uninstall it and use the VS Code built-in Chat view with BYOK instead.
5. Copilot SDK Integration (Advanced, Optional)
If you’re embedding Copilot Agent capabilities in your own tooling, configure the provider directly via the Copilot SDK:
SDK repository: https://github.com/github/copilot-sdk
import { CopilotAgent } from "@github/copilot-sdk";
const agent = new CopilotAgent({
provider: {
type: "anthropic",
baseUrl: "https://gw.claudeapi.com",
apiKey: process.env.COPILOT_PROVIDER_API_KEY!,
},
model: "claude-opus-4-7",
});
const session = await agent.createSession({
systemPrompt: "You are a senior TypeScript development assistant",
});
const response = await session.send({
message: "Convert this callback-style function to async/await: ...",
});
console.log(response.text);
import { CopilotAgent } from "@github/copilot-sdk";
const agent = new CopilotAgent({
provider: {
type: "anthropic",
baseUrl: "https://gw.claudeapi.com",
apiKey: process.env.COPILOT_PROVIDER_API_KEY!,
},
model: "claude-opus-4-7",
});
const session = await agent.createSession({
systemPrompt: "You are a senior TypeScript development assistant",
});
const response = await session.send({
message: "Convert this callback-style function to async/await: ...",
});
console.log(response.text);
The SDK also requires model support for tool calling + streaming + ≥128k context. All standard Claude 4.x models meet these requirements.
6. Troubleshooting
| Error | Cause | Fix |
|---|---|---|
| 401 Unauthorized | Wrong key / traffic routed through a system proxy | Verify your key; disable system proxy or add gw.claudeapi.com to the proxy bypass list |
| 403 Forbidden | Key was created without selecting a group | Recreate the key in the dashboard and select a group |
| 404 Not Found | COPILOT_PROVIDER_BASE_URL set to https://gw.claudeapi.com/v1 |
For the Anthropic protocol, the base_url should not include /v1 — that’s only for the OpenAI protocol |
| 429 Too Many Requests | Concurrency limit exceeded | Reduce concurrency; switch groups or upgrade your tier in the dashboard |
model does not support tool calling |
Used a model ID that doesn’t support function calling in COPILOT_MODEL |
Switch to one of the four recommended IDs above |
model context window too small |
Selected a model with ≤ 64k context window | Switch to claude-opus-4-7 / claude-sonnet-4-6 (both ≥ 200k) |
gh copilot suggest "..." returns Invalid command format |
Legacy syntax has been deprecated | Use the new syntax: gh copilot -- -p "your prompt" |
gh copilot -- -p hangs with no response |
Environment variables not loaded | Check: echo $COPILOT_PROVIDER_BASE_URL (PowerShell: echo $env:COPILOT_PROVIDER_BASE_URL) — if empty, restart your terminal |
gh extension install github/gh-copilot returns copilot matches the name of a built-in command or alias |
Newer gh versions include copilot as a built-in subcommand — no extension needed |
Skip the install step; verify directly with gh copilot -- --help |
| Streaming cuts off mid-response | Network instability / upstream overload | Retry; or temporarily switch to Sonnet 4.6 |
VS Code doesn’t show the Add Models option |
Enterprise policy not enabled / VS Code version too old | Upgrade to ≥ 1.94; for enterprise accounts, have your admin enable the BYOK policy |
7. Quick Reference
GitHub Copilot CLI BYOK
├── COPILOT_PROVIDER_TYPE: anthropic
├── COPILOT_PROVIDER_BASE_URL: https://gw.claudeapi.com (no /v1)
├── COPILOT_PROVIDER_API_KEY: sk-yourClaudeAPIkey
└── COPILOT_MODEL: claude-opus-4-7
VS Code Built-in Chat View
├── Provider: Anthropic
├── Endpoint: https://gw.claudeapi.com
├── API Key: sk-yourClaudeAPIkey
└── Model ID: claude-opus-4-7
GitHub Copilot CLI BYOK
├── COPILOT_PROVIDER_TYPE: anthropic
├── COPILOT_PROVIDER_BASE_URL: https://gw.claudeapi.com (no /v1)
├── COPILOT_PROVIDER_API_KEY: sk-yourClaudeAPIkey
└── COPILOT_MODEL: claude-opus-4-7
VS Code Built-in Chat View
├── Provider: Anthropic
├── Endpoint: https://gw.claudeapi.com
├── API Key: sk-yourClaudeAPIkey
└── Model ID: claude-opus-4-7
Download links:
| Resource | Link |
|---|---|
| GitHub CLI Homepage | https://cli.github.com/ |
| GitHub CLI Releases | https://github.com/cli/cli/releases |
| gh-copilot Extension | https://github.com/github/gh-copilot |
| Copilot SDK | https://github.com/github/copilot-sdk |
| VS Code Download | https://code.visualstudio.com/Download |
| Copilot CLI BYOK Docs | https://docs.github.com/en/copilot/how-tos/copilot-cli/customize-copilot/use-byok-models |
| Copilot Enterprise BYOK Policy | https://docs.github.com/en/copilot/how-tos/administer-copilot/manage-for-enterprise/use-your-own-api-keys |
| VS Code Language Models | https://code.visualstudio.com/docs/copilot/customization/language-models |
Summary
Copilot CLI’s BYOK is an official escape hatch from GitHub — four environment variables, one base_url, and Copilot runs on Claude Opus 4.7. VS Code’s built-in Chat view supports the same setup via Manage Models for a GUI-based workflow.
The end-to-end process: register for a ClaudeAPI key → install gh (newer versions include the copilot subcommand built-in — no gh-copilot extension needed) → set four environment variables → verify the endpoint with cURL / Invoke-RestMethod → confirm Copilot works with gh copilot -- -p "...".
To get started with the latest Claude models, sign up at claudeapi.com. Direct access from anywhere, no extra configuration needed.



