GitHub Copilot + OAI Plugin
A configuration guide for calling a third-party OpenAI-compatible relay API after installing an OAI plugin for GitHub Copilot. Applicable to programming tools such as VS Code and Cursor.
Compliance Reminder
This guide applies only to your own New API deployment or a third-party relay service that has been confirmed to possess legitimate upstream authorization and fulfill applicable compliance obligations. Do not use API endpoints or keys from unknown sources, and do not circumvent the terms of use of GitHub Copilot, model providers, or your organization.
Use Cases
When using GitHub Copilot in programming tools such as VS Code and Cursor, if your installed OAI plugin supports configuring an OpenAI-compatible endpoint, you can forward model requests to New API or another compliant third-party relay service.
This approach is suitable for the following scenarios:
| Scenario | Description |
|---|---|
| Unified model access | Connect multiple models through a single OpenAI-compatible API endpoint. |
| Centralized team management | Centrally manage quotas, groups, logs, and model permissions through the relay service. |
| Enhanced coding assistance | Use designated models within the editor for code explanation, generation, refactoring, and test creation. |
Prerequisites
Prepare the following before you begin:
- VS Code, Cursor, or another programming tool that supports extensions is installed.
- GitHub Copilot is installed, and you are signed in.
- An OAI plugin that supports custom OpenAI-compatible endpoints is installed.
- An API Key has been created in New API or a third-party relay service.
- The available API endpoint and model name have been confirmed.
Common configuration options are as follows:
| Configuration | Example | Description |
|---|---|---|
| API Base URL | https://api.example.com/v1 | The OpenAI-compatible API endpoint, which usually ends with /v1. |
| API Key | sk-xxxxxxxx | The Token created in the relay service console. |
| Model | gpt-4o-mini | The name of a model that is enabled and available in the relay service. |
Preparation Steps in New API
After opening the New API console, it is recommended that you first complete the following steps: create a Token, confirm which Groups the Token can access, verify that the target model is enabled, and use the logs page to check whether subsequent requests successfully reach the system.
Install the Plugins
1. Install GitHub Copilot
Open the Extensions Marketplace in VS Code, then search for and install GitHub Copilot. After installation, follow the prompts to sign in to your GitHub account and verify that Copilot is working properly.
If you use a programming tool such as Cursor, Trae, or Windsurf, confirm that Copilot functionality is enabled on the corresponding extension or plugin page.
2. Install the OAI Plugin
Search for OAI in the Extensions Marketplace and install the OAI plugin you intend to use. Configuration option names may vary slightly between plugins, but they typically include the following fields:
Base URLorAPI BaseAPI KeyModelProviderorEndpoint Type
If the plugin requires you to select an endpoint type, choose OpenAI, OpenAI Compatible, or a similar option.
Configure the Third-Party Relay API
1. Open the OAI Plugin Settings
In VS Code, you can open the settings as follows:
- Press
Ctrl + Shift + PorCommand + Shift + Pto open the Command Palette. - Search for the plugin name or
OAI. - Select the
Settings,Configure Provider, or similar command provided by the plugin.
Alternatively, open Settings, search for OAI, and locate the configuration options for the plugin.
2. Enter the API Endpoint
Set Base URL to the OpenAI-compatible endpoint of your relay service, for example:
https://api.example.com/v1If you use a self-hosted New API deployment, replace the domain with your own service address. HTTPS is recommended, and you should ensure that the trailing path matches the plugin's requirements.
3. Enter the API Key
Enter the Token created by the relay service in the API Key field, for example:
sk-xxxxxxxxxxxxxxxxDo not store the API Key in a public repository, screenshot, or shared configuration file. If the plugin supports the system keychain or Secret Storage, use it whenever possible.
4. Select a Model
Enter the name of a model actually supported by the relay service in the Model field, for example:
gpt-4o-miniThe model name must exactly match the relay service's model list. If the request fails, first check in the New API console whether the model is enabled, whether an available Channel exists, and whether the current Token has permission to access the model.
5. Save and Reload the Editor
After saving the settings, it is recommended that you reload the window:
- Open the Command Palette.
- Enter
Developer: Reload Window. - Reopen a project file and test whether the OAI plugin responds correctly.
Test the API Call
Open any code file in the editor and send a simple request to the OAI plugin, for example:
解释当前函数的作用,并给出一个更清晰的命名建议。Then check the New API or third-party relay service dashboard for the following:
- Whether a new request appears in the logs.
- Whether the correct model name was used.
- Whether the status code indicates success.
- Whether the Quota consumption matches expectations.
If the request appears in the dashboard logs, the plugin has successfully called the API through the relay service.
Troubleshooting
401 or Unauthorized
This usually means that the API Key is incorrect, the Token has been disabled, or extra spaces were introduced during copying. Generate a new Token and paste it into the plugin settings.
404 or model not found
This usually means that the model name is incorrect or the model is not enabled in the relay service. Copy the full model name from the model list and try again.
connection error
Check whether the API Base URL is reachable, starts with https://, requires the /v1 suffix, and whether your local network can connect to the relay service domain.
GitHub Copilot Itself Does Not Use the Relay Service
The built-in completion and chat services in the official GitHub Copilot extension typically use GitHub's official infrastructure. The OAI plugin only affects OpenAI-compatible requests initiated by the plugin itself and may not modify network requests made by the official Copilot extension.
The Plugin Does Not Have a Base URL Option
This indicates that the plugin may not support custom OpenAI-compatible endpoints. Use a plugin version that supports OpenAI Compatible, Custom Endpoint, or Base URL.
Recommended Configuration Checklist
| Item | Recommendation |
|---|---|
| API endpoint | Use HTTPS and confirm that the path matches the plugin's requirements. |
| API Key | Use a dedicated Token and configure its Quota and expiration as needed. |
| Model permissions | Enable only the coding models that are actually required. |
| Log troubleshooting | Check the relay service logs before reviewing errors reported by the editor plugin. |
| Security management | Do not expose keys in repositories, screenshots, or Issues. |
After completing the configuration above, you can use the OAI plugin in your programming tools to call a third-party relay API and combine it with GitHub Copilot for routine code generation, explanation, refactoring, and test creation.
How is this guide?
Last updated on