> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/opencode-ai/opencode/llms.txt
> Use this file to discover all available pages before exploring further.

# Using GitHub Copilot models

> Configure and use GitHub Copilot models with OpenCode

<Note>
  Copilot support is currently experimental.
</Note>

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:

<Steps>
  <Step title="Enable Copilot Chat">
    [Copilot chat in the IDE](https://github.com/settings/copilot) must be enabled in your GitHub settings.
  </Step>

  <Step title="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**
  </Step>
</Steps>

## 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:

```bash theme={null}
~/.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:

<Tabs>
  <Tab title="Environment variable">
    Set the `GITHUB_TOKEN` environment variable:

    ```bash theme={null}
    export GITHUB_TOKEN="ghp_your_token_here"
    ```
  </Tab>

  <Tab title="Configuration file">
    Add the token to your `.opencode.json` configuration file:

    ```json theme={null}
    {
      "providers": {
        "copilot": {
          "apiKey": "ghp_your_token_here",
          "disabled": false
        }
      }
    }
    ```
  </Tab>
</Tabs>

## Available models

GitHub Copilot provides access to multiple AI models:

<AccordionGroup>
  <Accordion title="OpenAI models">
    * GPT-3.5 Turbo
    * GPT-4
    * GPT-4o
    * GPT-4o Mini
    * GPT-4.1
    * O1
    * O3 Mini
    * O4 Mini
  </Accordion>

  <Accordion title="Anthropic models">
    * Claude 3.5 Sonnet
    * Claude 3.7 Sonnet
    * Claude 3.7 Sonnet Thinking
    * Claude Sonnet 4
  </Accordion>

  <Accordion title="Google models">
    * Gemini 2.0 Flash
    * Gemini 2.5 Pro
  </Accordion>
</AccordionGroup>

## Configuration

### Basic configuration

To use Copilot as your default provider, ensure it's enabled in your configuration:

```json .opencode.json theme={null}
{
  "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:

```json .opencode.json theme={null}
{
  "providers": {
    "copilot": {
      "disabled": true
    }
  }
}
```

## How it works

OpenCode uses the GitHub Copilot API through the following process:

<Steps>
  <Step title="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
  </Step>

  <Step title="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
    ```
  </Step>

  <Step title="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`
  </Step>

  <Step title="Token refresh">
    If the bearer token expires (401 Unauthorized), OpenCode automatically refreshes it by exchanging your GitHub token again.
  </Step>
</Steps>

## Troubleshooting

<AccordionGroup>
  <Accordion title="Error: GitHub token not found">
    **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
  </Accordion>

  <Accordion title="Error: Failed to exchange GitHub token">
    **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](https://github.com/settings/copilot) and ensure Copilot chat is enabled.
  </Accordion>

  <Accordion title="Error: Authentication failed (401)">
    **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
  </Accordion>

  <Accordion title="Model not available">
    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.
  </Accordion>
</AccordionGroup>

## Reasoning models

For models that support reasoning (like O1, O3, O4), you can configure the reasoning effort:

```json .opencode.json theme={null}
{
  "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

<Note>
  Reasoning effort only applies to models that support it. For other models, this setting is ignored.
</Note>
