B2BB2B LLM

GitHub Copilot

Connect GitHub Copilot Chat, VS Code agents, and Copilot CLI to Model Gate with BYOK and a custom OpenAI-compatible endpoint.

GitHub Copilot through Model Gate

GitHub Copilot and Visual Studio Code support Bring Your Own Key (BYOK) models. Model Gate can be used as an OpenAI-compatible custom endpoint for Copilot chat and agent workflows.

For VS Code, the recommended setup is the Custom Endpoint provider with the Responses API. Use Chat Completions only when a selected model or workflow specifically requires that API family.

Required values

API key: mg_live_...
Responses endpoint: https://api.model-gate.com/v1/responses
Chat Completions endpoint: https://api.model-gate.com/v1/chat/completions
Base URL for Copilot CLI: https://api.model-gate.com/v1

Create a dedicated API key in the Model Gate control panel. For a team or workstation integration, prefer a separate key instead of reusing an unrelated production key so limits, request history, rotation, and revocation remain easy to audit.

List currently enabled models before configuring Copilot:

curl https://api.model-gate.com/v1/models \
  -H "Authorization: Bearer mg_live_..."

Use an enabled canonical model ID or administrator-managed alias returned by this endpoint.

Current VS Code versions expose BYOK models in the Language Models editor.

1. Open the Command Palette. 2. Run Chat: Manage Language Models. 3. Select Add Models. 4. Select Custom Endpoint. 5. Use a group name such as Model Gate. 6. Enter the Model Gate API key when VS Code requests the provider credential. 7. Select Responses as the API type when the selected model supports the Responses API. 8. Configure the model with the explicit Model Gate endpoint and save the generated chatLanguageModels.json. 9. Select the Model Gate model from the Chat model picker.

Do not use the deprecated github.copilot.chat.customOAIModels setting for a new configuration. The current Custom Endpoint provider supports Responses, Chat Completions, and Messages-style endpoints and is the preferred VS Code configuration path.

The generated chatLanguageModels.json can use a configuration like this:

[
  {
    "name": "Model Gate",
    "vendor": "customendpoint",
    "apiKey": "${input:modelGateApiKey}",
    "apiType": "responses",
    "models": [
      {
        "id": "gpt-5.4",
        "name": "GPT-5.4 through Model Gate",
        "url": "https://api.model-gate.com/v1/responses",
        "toolCalling": true
      }
    ]
  }
]

Replace gpt-5.4 with an enabled Model Gate model or alias.

VS Code normally sends the API key as:

Authorization: Bearer mg_live_...

which is the correct authentication form for the Model Gate OpenAI-compatible API.

Chat Completions fallback

If the chosen workflow requires Chat Completions, configure the model as:

[
  {
    "name": "Model Gate",
    "vendor": "customendpoint",
    "apiKey": "${input:modelGateApiKey}",
    "apiType": "chat-completions",
    "models": [
      {
        "id": "MODEL_ID",
        "name": "MODEL_ID through Model Gate",
        "url": "https://api.model-gate.com/v1/chat/completions",
        "toolCalling": true
      }
    ]
  }
]

Prefer an explicit full endpoint URL. This avoids ambiguity if VS Code changes URL-path inference behavior.

Model capability recommendations

Copilot agent workflows require a model that can use tools. For reliable agent use through Model Gate:

- choose a model with verified tool/function calling support; - choose a model with streaming support; - for image attachments, use a model with verified vision/image input capability and set "vision": true for that model; - use a large context model for repository-scale agent work; GitHub currently recommends at least a 128k-token context window for Copilot CLI custom models; - do not advertise toolCalling, vision, reasoning, context, or output limits above the actual capability of the selected Model Gate model; - test the exact model in the Model Gate Playground before enabling it for a large team.

If you manually set contextWindow, maxInputTokens, or maxOutputTokens in VS Code, use the selected model's limits from the authenticated /models page or from GET /v1/models; do not guess them. Model Gate maps the fields as follows:

VS Code settingModel Gate field
contextWindowcontext_window (same value as context_length)
maxInputTokensmax_input_tokens
maxOutputTokensmax_output_tokens

The authenticated /models page shows these as Context, Max input, and Max output when the corresponding value is known. To inspect the API object directly:

curl -s https://api.model-gate.com/v1/models \
  -H "Authorization: Bearer mg_live_..." \
| jq '.data[] | select(.id=="MODEL_ID") | {context_window,max_input_tokens,max_output_tokens}'

A value of 0 means that Model Gate does not have a configured value for that limit. In that case, leave the corresponding manual VS Code setting unset rather than entering 0 or inventing a limit.

Utility models in VS Code

VS Code also uses smaller background models for tasks such as titles, summaries, commit messages, rename suggestions, and intent detection.

If you use Model Gate BYOK without a GitHub-hosted Copilot model, configure:

chat.utilityModel
chat.utilitySmallModel

Choose a fast and inexpensive Model Gate model for chat.utilitySmallModel. There is usually no benefit in paying for the largest reasoning model for commit-message generation or other lightweight utility work.

The chat.byokUtilityModelDefault setting can also control whether utility work follows the selected BYOK main-agent model, uses GitHub Copilot utility models, or has no default.

Copilot CLI

GitHub Copilot CLI supports OpenAI-compatible custom providers through environment variables.

Linux or macOS

export COPILOT_PROVIDER_TYPE="openai"
export COPILOT_PROVIDER_BASE_URL="https://api.model-gate.com/v1"
export COPILOT_PROVIDER_API_KEY="mg_live_..."
export COPILOT_MODEL="MODEL_ID"

copilot ```

Windows PowerShell

$env:COPILOT_PROVIDER_TYPE = "openai"
$env:COPILOT_PROVIDER_BASE_URL = "https://api.model-gate.com/v1"
$env:COPILOT_PROVIDER_API_KEY = "mg_live_..."
$env:COPILOT_MODEL = "MODEL_ID"

copilot ```

For Copilot CLI, the selected model must support tool calling and streaming. Use an enabled Model Gate model or alias and test it before making the configuration permanent.

Do not place the API key in shell history, a repository file, or a committed .env. Use your OS credential store, protected shell environment, or organization secret-management tooling where possible.

Copilot Business and Enterprise

GitHub also supports organization/enterprise custom models through BYOK. GitHub currently lists OpenAI-compatible providers as a supported custom-model provider category. This organization-level capability is managed by GitHub policy and may be in preview depending on the Copilot surface.

For a managed organization:

1. Enable the GitHub custom models / BYOK policy required for your Copilot plan. 2. Add a custom OpenAI-compatible provider/model in the organization or enterprise Copilot model settings. 3. Use a dedicated Model Gate API key with the minimum necessary Model Gate permissions and limits. 4. Use the Model Gate endpoint and a model ID that your account can access. 5. Validate the model in Copilot Chat/agent workflows before exposing it broadly in the organization model picker.

GitHub can change the organization custom-model UI while the feature evolves. Follow the current GitHub administrative UI for the exact field labels rather than relying on screenshots from an older release.

Security and cost recommendations

- Create a dedicated Model Gate key for Copilot instead of sharing a general-purpose key. - Apply an RPM limit, concurrency limit, spend limit, or Business group policy appropriate for developer-agent traffic. - Rotate the key immediately if it is pasted into source control, chat, logs, or an issue. - Never commit mg_live_... in chatLanguageModels.json; let VS Code store the credential or reference an input/secret. - Keep destructive tool approvals enabled unless your development environment is intentionally sandboxed. - Agent mode can generate many model/tool turns from one user instruction. Set Model Gate spend limits before enabling expensive reasoning models for large repositories. - Use a smaller utility model for background tasks and reserve larger reasoning models for planning, debugging, or complex refactors. - Check Model Gate Request History when investigating unexpected cost, latency, rate-limit, or provider errors.

What BYOK does and does not replace

A Model Gate BYOK model can power VS Code chat, agent workflows, tools, and utility tasks when the model supports the required capabilities.

It does not automatically replace every GitHub Copilot feature. Depending on the current VS Code/GitHub release, features such as standard inline code completions, semantic search, embeddings, or other GitHub-hosted services can still require GitHub authentication, a Copilot plan, or GitHub infrastructure.

Therefore, use Model Gate BYOK when your goal is to control the chat/agent model path and its billing, not as an assumption that all GitHub Copilot network traffic is routed through Model Gate.

Verify Model Gate before testing Copilot

Responses

curl https://api.model-gate.com/v1/responses \
  -H "Authorization: Bearer mg_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MODEL_ID",
    "input": "Reply with exactly: Model Gate OK"
  }'

Chat Completions

curl https://api.model-gate.com/v1/chat/completions \
  -H "Authorization: Bearer mg_live_..." \
  -H "Content-Type: application/json" \
  -d '{
    "model": "MODEL_ID",
    "messages": [{"role": "user", "content": "Reply with exactly: Model Gate OK"}]
  }'

If these requests fail, fix the API key/model/Model Gate policy before debugging Copilot.

Troubleshooting

ProblemResolution
Model does not appear in agent modeVerify the model is configured with tool calling and that the actual Model Gate model supports function/tool calls. Restart VS Code after changing the provider configuration.
401 invalid_api_keyRe-enter or rotate the dedicated Model Gate key. Confirm Copilot sends Authorization: Bearer ....
404 or wrong endpointFor Responses use the explicit https://api.model-gate.com/v1/responses; for Chat Completions use /v1/chat/completions.
Model is not foundQuery /v1/models and use an enabled canonical ID or alias.
Agent cannot use toolsSelect a model with verified tool/function calling. Copilot CLI also requires streaming.
Image attachment is ignored/rejectedUse a model with verified image-input/vision capability and configure vision: true only for that model.
Utility features do not work with BYOK-only setupConfigure chat.utilityModel and chat.utilitySmallModel to available BYOK models.
Inline completions still use GitHub or require sign-inExpected: BYOK primarily controls chat/agent/utility model traffic, not every Copilot feature.
Requests are unexpectedly expensiveUse a smaller model for utility work, lower reasoning where appropriate, and configure Model Gate spend/RPM/concurrency limits.

Current upstream references

GitHub and VS Code can change BYOK configuration between releases. For current upstream behavior, check:

- https://code.visualstudio.com/docs/agent-customization/language-models - https://docs.github.com/en/copilot/concepts/models/bring-your-own-key - https://docs.github.com/en/copilot/how-tos/copilot-cli/customize-copilot/use-byok-models - https://docs.github.com/en/copilot/how-tos/administer-copilot/manage-for-organization/enable-custom-models