You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/copilot/how-tos/copilot-cli/customize-copilot/use-byok-models.md
+156-3Lines changed: 156 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,9 @@ shortTitle: Use your own model provider
4
4
intro: 'Use a model from an external provider of your choice in {% data variables.product.prodname_copilot_short %} by supplying your own API key.'
5
5
allowTitleToDifferFromFilename: true
6
6
versions:
7
-
feature: copilot
7
+
fpt: '*'
8
+
ghec: '*'
9
+
ghes: '>=3.22'
8
10
contentType: how-tos
9
11
category:
10
12
- Configure Copilot
@@ -16,7 +18,9 @@ docsTeamMetrics:
16
18
You can configure {% data variables.copilot.copilot_cli_short %} to use your own LLM provider, also called BYOK (Bring Your Own Key), instead of {% data variables.product.github %}-hosted models. This lets you connect to OpenAI-compatible endpoints, Azure OpenAI, or Anthropic, including locally running models such as Ollama.
17
19
18
20
> [!NOTE]
19
-
> This article is for users who want to configure their own LLM provider API key on their local machine. To set up custom models for users in an enterprise, see [AUTOTITLE](/copilot/how-tos/administer-copilot/manage-for-enterprise/use-your-own-api-keys).
21
+
> This article is for users who want to configure their own LLM provider API key on their local machine. To set up custom models for users in an enterprise, see [AUTOTITLE](/copilot/how-tos/administer-copilot/manage-for-enterprise/use-your-own-api-keys).{% ifversion ghes %}
22
+
>
23
+
> This article is also for administrators who want to configure their own LLM provider API key in GHES and for users who want to use those models in {% data variables.copilot.copilot_cli_short %}.{% endif %}
20
24
21
25
## Prerequisites
22
26
@@ -123,5 +127,154 @@ You can run {% data variables.copilot.copilot_cli_short %} in offline mode to pr
123
127
```shell
124
128
export COPILOT_OFFLINE=true
125
129
```
130
+
131
+
1. {% data reusables.copilot.copilot-cli.start-cli %}
126
132
127
-
{% data reusables.copilot.copilot-cli.start-cli %}
133
+
{% ifversion ghes %}
134
+
135
+
## Using Copilot CLI with GitHub Enterprise Server
136
+
137
+
> [!NOTE]
138
+
> This feature is in {% data variables.release-phases.technical_preview %} and subject to change. Additionally, GHES 3.22, the first version to support this functionality, is in the release candidate phase. We recommend waiting until GHES 3.22 reaches GA before validating and using this capability. We are publishing these docs early to provide visibility into what is coming.
139
+
140
+
{% data variables.copilot.copilot_cli_short %} can be configured to work with {% data variables.product.prodname_ghe_server %} for enterprises that operate in disconnected or air-gapped environments without connectivity to {% data variables.product.github %} Cloud. Your {% data variables.product.prodname_ghe_server %} administrator configures a model provider once, and users across the enterprise can use {% data variables.copilot.copilot_cli_short %} with their {% data variables.product.prodname_ghe_server %} credentials.
141
+
142
+
Setting up this feature involves two roles:
143
+
144
+
***Administrator**: Configures the model provider on the {% data variables.product.prodname_ghe_server %} instance using `ghe-config`. This is a one-time setup that requires administrative SSH access.
145
+
***End user**: Sets environment variables on their local machine to connect {% data variables.copilot.copilot_cli_short %} to the instance.
146
+
147
+
### Prerequisites
148
+
149
+
* Your {% data variables.product.prodname_ghe_server %} administrator has configured a model provider on the instance. See [Configuring your {% data variables.product.prodname_ghe_server %} instance](#configuring-your-github-enterprise-server-instance).
150
+
* {% data variables.copilot.copilot_cli_short %} is installed on client machines. See [AUTOTITLE](/copilot/how-tos/copilot-cli/set-up-copilot-cli/install-copilot-cli).
151
+
* {% data variables.product.company_short %} CLI (`gh`) is installed on client machines. See [Installing gh](https://cli.github.com/manual/installation).
152
+
153
+
The same [supported providers](#supported-providers) and [model requirements](#model-requirements) apply.
154
+
155
+
### Configuring your {% data variables.product.prodname_ghe_server %} instance
156
+
157
+
This step is for the operator or administrator of the {% data variables.product.prodname_ghe_server %} instance.
158
+
159
+
With administrative SSH access to the {% data variables.product.prodname_ghe_server %} instance, configure the model provider using the following `ghe-config` values. After configuring, run `ghe-config-apply` to apply the changes.
160
+
161
+
| Variable name | Required | Options | Description |
162
+
|---|---|---|---|
163
+
|`app.copilot-proxy.enabled`| Yes |`true`, `false`| Enables or disables the feature. |
164
+
|`app.copilot-proxy.endpoint-url`| Yes | URI | The full upstream base URL including any version prefix (for example, `https://api.openai.com/v1`). |
165
+
|`secrets.copilot-proxy.endpoint-key`| Yes | String | The API key for the upstream provider. |
166
+
|`app.copilot-proxy.provider-model-id`| Yes | String | The provider model ID that {% data variables.copilot.copilot_cli_short %} uses to look up the model internally. |
167
+
|`app.copilot-proxy.provider-type`| Yes |`openai`, `azure`, `anthropic`| The provider type. OpenAI includes OpenAI, Ollama, vLLM, Foundry Local, and any other OpenAI Chat Completions API-compatible endpoint. |
168
+
|`app.copilot-proxy.upstream-timeout`| No | Integer (seconds) | Read/send timeout in seconds for upstream requests. If not set, falls back to the default timeout. |
169
+
|`app.copilot-proxy.provider-wire-api`| No |`completions`, `responses`| The wire API format for the provider. |
170
+
|`app.copilot-proxy.provider-wire-model`| No | String | Overrides the model identifier sent to the upstream provider if it differs from the internal model ID. |
171
+
|`app.copilot-proxy.enable-upstream-probe`| No |`true`, `false`| Enables or disables the startup upstream probe. Defaults to enabled. When disabled, the startup probe is skipped. |
Replace `YOUR-API-KEY` with the real API key before applying.
188
+
189
+
### Configuring your {% data variables.copilot.copilot_cli_short %} client (end user)
190
+
191
+
Configure {% data variables.copilot.copilot_cli_short %} to connect to your {% data variables.product.prodname_ghe_server %} instance by setting the following environment variables before starting {% data variables.copilot.copilot_cli_short %}.
192
+
193
+
| Environment variable | Required | Description |
194
+
|---|---|---|
195
+
|`COPILOT_PROVIDER_GHES_HOST`| Yes | The hostname of your {% data variables.product.prodname_ghe_server %} instance. |
196
+
|`COPILOT_PROVIDER_GHES_TOKEN`| Yes | A {% data variables.product.pat_generic %} for the {% data variables.product.prodname_ghe_server %} instance. This token authenticates requests to the instance. |
197
+
|`COPILOT_OFFLINE=true`| Yes | Enables offline mode. The {% data variables.product.prodname_ghe_server %} provider is only active when offline mode is enabled. |
198
+
199
+
### Understanding client (end user) tokens
200
+
201
+
{% data variables.copilot.copilot_cli_short %} needs access to LLM inference, so `COPILOT_PROVIDER_GHES_TOKEN` is always required. You will also very likely want {% data variables.copilot.copilot_cli_short %} to perform {% data variables.product.github %} operations such as create issues, pull requests, and search repositories. Such operations can be done via the {% data variables.product.github %} CLI.
202
+
203
+
It is recommended and preferred that you run `gh auth login --hostname YOUR-GHES-HOSTNAME`. After it succeeds, next step is to set COPILOT_PROVIDER_GHES_TOKEN to the token generated in `gh auth login --hostname YOUR-GHES-HOSTNAME`. It is more secure to retrieve the token dynamically rather than copying it from `~/.config/gh/hosts.yml`. You can do so by using `COPILOT_PROVIDER_GHES_TOKEN="$(gh auth token --hostname YOUR-GHES-HOSTNAME)"`.
204
+
205
+
Alternatively, you can generate a {% data variables.product.pat_generic %} on your {% data variables.product.prodname_ghe_server %} instance, set that token as `COPILOT_PROVIDER_GHES_TOKEN`, and use the same token when running `gh auth login --hostname YOUR-GHES-HOSTNAME`.
206
+
207
+
The above approach works when you are using {% data variables.copilot.copilot_cli_short %} interactively. For automation, you need to do a few things differently:
208
+
* Set `GH_ENTERPRISE_TOKEN` (or `GITHUB_ENTERPRISE_TOKEN`) to the {% data variables.product.pat_generic %}.
209
+
* Set `GH_HOST` to your server's hostname.
210
+
* When both `GH_ENTERPRISE_TOKEN` and `gh auth login` credentials exist for the same host, the environment variable takes precedence.
211
+
212
+
### Recommended end user setup
213
+
214
+
1. Authenticate the {% data variables.product.company_short %} CLI.
If you are authenticated with `gh auth login` to multiple accounts, you can set `GH_HOST` to your server's hostname and set `GH_ENTERPRISE_TOKEN` (or `GITHUB_ENTERPRISE_TOKEN`) to `"$(gh auth token --hostname YOUR-GHES-HOSTNAME)"`. This ensures {% data variables.product.prodname_cli %} targets your {% data variables.product.prodname_ghe_server %} instance.
1. {% data reusables.copilot.copilot-cli.start-cli %}
236
+
237
+
You can run this entire set-up as a script.
238
+
239
+
### Examples
240
+
241
+
If both {% data variables.product.prodname_ghe_server %} and your {% data variables.copilot.copilot_cli_short %} configurations are correct, then you should see responses like the following in your {% data reusables.copilot.copilot-cli.start-cli %} session.
242
+
243
+
```shell
244
+
• fabric-core-mcp — disabled
245
+
• powerbi-mcp — disabled
246
+
• slack — connected
247
+
248
+
● Current model: gpt-5.5
249
+
250
+
❯ Hello 13:31
251
+
252
+
● Hello!
253
+
254
+
❯ what is going on in github/codeql-action repo? 13:33
255
+
256
+
● I’ll check recent repository activity on the GHES host: repo metadata, open
257
+
PRs/issues, and latest commits.
258
+
259
+
$ Shell Fetch repo metadata 2 lines… 5s
260
+
gh api --hostname "$GH_HOST" repos/github/codeql-action --jq '{name_with_own…
261
+
```
262
+
263
+
### Supported capabilities on {% data variables.product.prodname_ghe_server %}
264
+
265
+
For the most up-to-date information on {% data variables.copilot.copilot_cli_short %} features, refer to the [AUTOTITLE](/copilot/how-tos/copilot-cli) as the primary source of truth. In general, any capability that relies on connectivity to {% data variables.product.github %} cloud services is not available in the {% data variables.product.prodname_ghe_server %} offline configuration.
266
+
267
+
The following table provides a directional overview of what is available in {% data variables.product.prodname_ghe_server %} offering.
268
+
269
+
| Capability | {% data variables.product.prodname_dotcom %} / {% data variables.product.prodname_ghe_cloud %} | {% data variables.product.prodname_ghe_server %} |
0 commit comments