Skip to main content
Copilot support is currently experimental.
OpenCode can use GitHub Copilot’s AI models through the Copilot API. This allows you to leverage your existing GitHub Copilot subscription with OpenCode.

Requirements

To use GitHub Copilot models with OpenCode, you need:
1

Enable Copilot Chat

Copilot chat in the IDE must be enabled in your GitHub settings.
2

Authentication

You need one of the following authentication methods:
  • VSCode GitHub Copilot chat extension (authenticated)
  • GitHub gh CLI (authenticated)
  • Neovim GitHub Copilot plugin (copilot.vim or copilot.lua)
  • GitHub token with copilot permissions

Authentication setup

Using IDE plugins or CLI tools

If you’re using VSCode, the GitHub CLI, or Neovim with Copilot plugins, make sure you authenticate the tool with your GitHub account. This creates a GitHub token at one of these locations:
~/.config/github-copilot/hosts.json
~/.config/github-copilot/apps.json
$XDG_CONFIG_HOME/github-copilot/hosts.json
$XDG_CONFIG_HOME/github-copilot/apps.json
OpenCode automatically detects and uses tokens from these locations.

Using an explicit GitHub token

You can also provide a GitHub token directly:
Set the GITHUB_TOKEN environment variable:
export GITHUB_TOKEN="ghp_your_token_here"

Available models

GitHub Copilot provides access to multiple AI models:
  • GPT-3.5 Turbo
  • GPT-4
  • GPT-4o
  • GPT-4o Mini
  • GPT-4.1
  • O1
  • O3 Mini
  • O4 Mini
  • Claude 3.5 Sonnet
  • Claude 3.7 Sonnet
  • Claude 3.7 Sonnet Thinking
  • Claude Sonnet 4
  • Gemini 2.0 Flash
  • Gemini 2.5 Pro

Configuration

Basic configuration

To use Copilot as your default provider, ensure it’s enabled in your configuration:
.opencode.json
{
  "providers": {
    "copilot": {
      "disabled": false
    }
  },
  "agents": {
    "coder": {
      "model": "copilot.gpt-4o",
      "maxTokens": 5000
    },
    "task": {
      "model": "copilot.gpt-4o",
      "maxTokens": 5000
    },
    "title": {
      "model": "copilot.gpt-4o",
      "maxTokens": 80
    }
  }
}

Disabling Copilot provider

If you have Copilot configured but want to use a different provider:
.opencode.json
{
  "providers": {
    "copilot": {
      "disabled": true
    }
  }
}

How it works

OpenCode uses the GitHub Copilot API through the following process:
1

Token detection

OpenCode looks for your GitHub token in standard locations:
  1. GITHUB_TOKEN environment variable
  2. Configuration file (providers.copilot.apiKey)
  3. GitHub CLI/Copilot plugin token files
2

Token exchange

Your GitHub token is exchanged for a Copilot bearer token using GitHub’s token exchange endpoint:
https://api.github.com/copilot_internal/v2/token
3

API requests

OpenCode communicates with the Copilot API at:
https://api.githubcopilot.com
All requests include required headers:
  • Editor-Version: OpenCode/1.0
  • Editor-Plugin-Version: OpenCode/1.0
  • Copilot-Integration-Id: vscode-chat
4

Token refresh

If the bearer token expires (401 Unauthorized), OpenCode automatically refreshes it by exchanging your GitHub token again.

Troubleshooting

Solution: Ensure you have authenticated with one of the supported methods:
  • Run gh auth login if using GitHub CLI
  • Sign in to GitHub Copilot in VSCode
  • Set the GITHUB_TOKEN environment variable
  • Add the token to your .opencode.json configuration
Possible causes:
  • Your GitHub token doesn’t have Copilot permissions
  • Copilot chat is not enabled in your GitHub settings
  • Your Copilot subscription is not active
Solution: Check your GitHub Copilot settings and ensure Copilot chat is enabled.
Solution: Your bearer token may have expired. OpenCode will automatically attempt to refresh it. If the problem persists:
  1. Verify your GitHub token is still valid
  2. Try re-authenticating with your IDE or GitHub CLI
  3. Check that your Copilot subscription is active
Some models may not be available depending on your Copilot subscription tier.Solution: Try a different model from the list above, or check your Copilot subscription details.

Reasoning models

For models that support reasoning (like O1, O3, O4), you can configure the reasoning effort:
.opencode.json
{
  "agents": {
    "coder": {
      "model": "copilot.o1",
      "maxTokens": 5000,
      "reasoningEffort": "high"
    }
  }
}
Valid reasoning effort values:
  • low - Faster responses with less reasoning
  • medium - Balanced reasoning and speed (default)
  • high - More thorough reasoning, slower responses
Reasoning effort only applies to models that support it. For other models, this setting is ignored.

Build docs developers (and LLMs) love