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

# GitHub Copilot

> Route GitHub Copilot requests through TrueFoundry AI Gateway for observability, governance, and custom model access.

This guide provides instructions for integrating [GitHub Copilot](https://github.com/features/copilot) with the TrueFoundry AI Gateway.

## What is GitHub Copilot?

GitHub Copilot is an AI-powered coding assistant that integrates directly into your editor. It provides intelligent code completions, chat-based coding help, and agent-driven workflows across VS Code, JetBrains IDEs, Visual Studio, Eclipse, and Xcode.

### Key Features

1. **Inline Code Suggestions**: Context-aware code completions and multi-line suggestions as you type
2. **Copilot Chat**: Conversational AI assistant for code explanation, generation, debugging, and refactoring
3. **Agent Mode**: Agentic workflows that can autonomously plan, edit files, and run terminal commands to complete complex tasks
4. **Bring Your Own Key (BYOK)**: Use custom models from any OpenAI-compatible provider — including TrueFoundry AI Gateway

<Note>
  Copilot routes through the gateway only via **BYOK** — you point Copilot at TrueFoundry as an OpenAI-compatible endpoint. Only **Chat, agent, and CLI** traffic can be routed this way. **Inline ghost-text completions always run on GitHub's hosted models** and cannot be routed through any gateway.
</Note>

## Prerequisites

Before integrating GitHub Copilot with TrueFoundry, ensure you have:

1. **TrueFoundry Account**: Create a [TrueFoundry account](https://www.truefoundry.com/register) with at least one model provider configured and generate a Personal Access Token by following the instructions in [Generating Tokens](/docs/ai-gateway/authentication). For a quick setup guide, see our [Gateway Quick Start](https://docs.truefoundry.com/gateway/quick-start)
2. **GitHub Copilot Subscription**: An active [GitHub Copilot](https://github.com/features/copilot) plan (Free, Pro, Business, or Enterprise)
3. **VS Code** or **Copilot CLI**: [Visual Studio Code](https://code.visualstudio.com/) (stable) with the GitHub Copilot extension, or the [GitHub Copilot CLI](https://github.com/github/copilot-cli)

<Note>
  The credential Copilot asks for is always your **TrueFoundry Personal Access Token (PAT)** — not an OpenAI/Anthropic provider key. Provider credentials stay in the gateway and are never seen by Copilot. The model must support **tool calling and streaming** (Copilot is agentic); ≥128k context is recommended.
</Note>

## Integration Guide (VS Code)

The **Custom Endpoint** provider is generally available in stable VS Code. There is no longer any need for VS Code Insiders or a community extension.

### 1. Get Configuration Details

Get the `base URL` and `model name` from your TrueFoundry AI Gateway playground using the unified code snippet:

<Frame caption="Get Base URL and Model Name from Unified Code Snippet">
  <img src="https://mintcdn.com/truefoundry/n3EuZuJ0K8wBFp1G/images/new-code-snippet.png?fit=max&auto=format&n=n3EuZuJ0K8wBFp1G&q=85&s=3634c2dc8c3565fd77ab896d3fd07ed9" alt="TrueFoundry playground showing unified code snippet with base URL and model name" width="2940" height="1664" data-path="images/new-code-snippet.png" />
</Frame>

### 2. Add TrueFoundry as a Custom Endpoint

<Steps>
  <Step title="Open Manage Language Models">
    Open the Command Palette (`Ctrl+Shift+P` / `Cmd+Shift+P`) and run **Chat: Manage Language Models**.
  </Step>

  <Step title="Add a Custom Endpoint provider">
    Click **Add Models** and select **Custom Endpoint** from the list of providers.
  </Step>

  <Step title="Enter provider details">
    When prompted, enter:

    * **Group / provider name**: A short identifier (e.g., `truefoundry`)
    * **Display name**: A friendly name shown in the picker
    * **API key**: Your TrueFoundry Personal Access Token (stored securely by VS Code, not in the config file)
    * **API type**: **Chat Completions**
  </Step>

  <Step title="Configure models in chatLanguageModels.json">
    VS Code opens `chatLanguageModels.json`. Add your gateway base URL and the models you want to expose, using the fully qualified `provider-name/model-name` format:

    ```jsonc theme={"dark"}
    {
      "truefoundry": {
        "url": "{GATEWAY_BASE_URL}",
        "models": [
          {
            "id": "openai-main/gpt-4o",
            "name": "GPT-4o (TrueFoundry)",
            "apiType": "Chat Completions",
            "toolCalling": true,
            "vision": true,
            "maxInputTokens": 200000,
            "maxOutputTokens": 8192,
            "requestHeaders": { "x-tfy-metadata": "{\"team\":\"platform\"}" }
          }
        ]
      }
    }
    ```

    Replace `{GATEWAY_BASE_URL}` with your TrueFoundry AI Gateway Base URL ([how to find it](/docs/ai-gateway/quick-start#gateway-base-url)) and update `id` to match your TrueFoundry model.
  </Step>

  <Step title="Enable Models">
    Check the models you want to make available in the Copilot Chat model picker, then click **OK**.
  </Step>
</Steps>

<Note>
  The **Custom Endpoint** provider supports custom HTTP headers via the `requestHeaders` field on each model. This lets you attach TrueFoundry headers such as `x-tfy-metadata` for per-request [metadata logging](/docs/ai-gateway/log-custom-metadata). Reserved, forwarding, and internal headers are stripped by VS Code.
</Note>

### 3. Use TrueFoundry Models in Copilot Chat

Your TrueFoundry models now appear in the model dropdown in Copilot Chat. Select any of them to route requests through the TrueFoundry AI Gateway.

```plain theme={"dark"}
# Ask about your code
> Explain this function and suggest improvements

# Generate code
> Write a REST API endpoint for user authentication

# Debug issues
> Why is this test failing? Suggest a fix
```

<Note>
  For a model to work in **Agent Mode**, it must support tool calling (set `"toolCalling": true`). Most large models (GPT-4o, Claude Sonnet, etc.) support this. If a model doesn't support tool calling, it will only be available in Ask and Edit modes.
</Note>

## Integration Guide (Copilot CLI)

The [GitHub Copilot CLI](https://github.com/github/copilot-cli) supports BYOK through three environment variables. It uses the OpenAI JS SDK and calls `{BASE_URL}/chat/completions`.

```bash theme={"dark"}
export COPILOT_PROVIDER_BASE_URL="{GATEWAY_BASE_URL}"        # TrueFoundry gateway base URL
export COPILOT_PROVIDER_API_KEY="<truefoundry-PAT>"         # TrueFoundry PAT (not a provider key)
export COPILOT_MODEL="openai-main/gpt-4o"                   # provider-name/model-name
copilot
```

* **No `settings.json` for BYOK.** `~/.copilot/settings.json` cannot set the provider base URL or API key. Persist the configuration via your shell profile, [direnv](https://direnv.net/), or MDM-pushed environment variables.
* **No custom headers.** The CLI sends only a single `Authorization: Bearer` header — it has no equivalent of the VS Code `requestHeaders` field. If you need to attach headers (e.g., `x-tfy-metadata`), bake the values into the PAT / virtual account on the gateway side, or run a local proxy that injects them.

<Note>
  In BYOK mode the CLI authenticates with **only** your `COPILOT_PROVIDER_API_KEY` (the TrueFoundry PAT). No GitHub OAuth token or Copilot session token is sent to the gateway, and no gateway traffic is visible to GitHub.
</Note>

## Enterprise / Organization BYOK

For GitHub Copilot Business and Enterprise users, organization and enterprise admins can register TrueFoundry as a **custom model provider** at the org or enterprise level. This pushes TrueFoundry-routed models to every team member's Copilot Chat model picker.

<Steps>
  <Step title="Navigate to Copilot Settings">
    Go to your GitHub organization or enterprise settings, then navigate to **Copilot** → **AI controls** → **Configure allowed models** → **Custom models** tab.
  </Step>

  <Step title="Add TrueFoundry API Key">
    Click **Add API key** and configure:

    * **Provider**: Select **OpenAI-compatible providers**
    * **Name**: Enter a descriptive name (e.g., "TrueFoundry AI Gateway")
    * **API Key**: Enter your TrueFoundry Personal Access Token
    * **Available models**: Add your desired models using the fully qualified `provider-name/model-name` format
  </Step>

  <Step title="Configure Access">
    Choose which organizations can access the models and save the configuration. The models will appear in the Copilot Chat model picker for all enabled users, listed under your enterprise or organization name. When set at the enterprise level, the configuration is non-overridable by member organizations.
  </Step>
</Steps>

<Note>
  With Enterprise BYOK, usage is billed directly through your TrueFoundry account and **does not count against GitHub Copilot's built-in premium request quotas**. This lets teams leverage existing contracts and credits.
</Note>

## Virtual Model Configuration (Optional)

If your models or Copilot setup requires standard model names (e.g., `gpt-4o` instead of `openai-main/gpt-4o`), create a Virtual Model in TrueFoundry to map standard names to fully qualified model names:

1. Navigate to **AI Gateway → Models → Virtual Model** in the TrueFoundry dashboard.

<Frame>
  <img src="https://mintcdn.com/truefoundry/9sjb7wvpsYV7RE1W/images/Screenshot2026-02-27at4.38.04PM-1.png?fit=max&auto=format&n=9sjb7wvpsYV7RE1W&q=85&s=5815438d18a9ecd74e2c183b7aa8d9a1" alt="TrueFoundry Virtual Models dashboard" className="block dark:hidden" width="3598" height="2008" data-path="images/Screenshot2026-02-27at4.38.04PM-1.png" />

  <img src="https://mintcdn.com/truefoundry/uL7y0Q9ywygbGxPN/images/Screenshot2026-02-27at4.38.04PM.png?fit=max&auto=format&n=uL7y0Q9ywygbGxPN&q=85&s=84550e1c21cc38734bfbabe680a189f1" alt="TrueFoundry Virtual Models dashboard" className="hidden dark:block" width="3598" height="2008" data-path="images/Screenshot2026-02-27at4.38.04PM.png" />
</Frame>

2. Create a new Virtual Model Provider Group with a name (e.g., `copilot-vm`) and configure collaborators for access control.

3. Add your target model (e.g., `openai-main/gpt-4o`) under the provider group. Set the Virtual Model name to the standard model name (e.g., `gpt-4o`), so requests for `gpt-4o` are automatically routed to `openai-main/gpt-4o` through the TrueFoundry Gateway.

For more details, see the [Virtual Models documentation](/docs/ai-gateway/virtual-model).
