The end result of what we’ll have at the end of this post in Copilot CLI and VS Code.
Overview
I recently found myself running out of my Copilot Max credits before the month end. I remembered I have some monthly Azure credits, and was curious if I could take advantage of those to use a Foundry-hosted model with Copilot’s BYOK mode. This post is the result of that!
This post will go over both how to deploy a model in Azure Foundry, as well as how to use that model in GitHub Copilot once it’s deployed. I also link to a repository with two helper scripts that make running the command easier and show Foundry spend from within the CLI.
Why use Azure-hosted models with GitHub Copilot?
I can think of a few reasons to use Azure-hosted models with GitHub Copilot:
- You have unused Azure credits. If, like me, you have a Visual Studio Enterprise subscription, you get $150 Azure credit per month with it. That’s some extra AI usage you can get for “free” out of your credits if you run out of AI credits for the month on your Copilot plan.
- Azure hosts many model families that GitHub Copilot does not have by default, such as Grok, Deepseek, Cohere, and more.
- Related to the above, some of these models have different capabilities that Copilot’s normal models don’t have, like audio generation (such as gpt-realtime) and video generation (such as sora).
Deploying a model in Azure Foundry
Navigate to ai.azure.com, which is the Azure Foundry portal (mind you, it’s still part of normal Azure and its resources will still appear on portal.azure.com). Click either the “New Foundry” toggle or “Start Building” button; they’ll both do the same thing, which is show a modal for creating a new Foundry project.
Name it whatever you like, ensure it’s in the subscription you want, and create it.
After it finishes, you’ll land at the Foundry home page for your project. Now that we have a project, we can create a model deployment. Click “Explore models” to see the options.
If you, like me, are NOT on a pay-as-you-go Azure subscription, but a credit-based one, you’ll notice that Anthropic models, among others, are not available to you. It’ll say you have “insufficient quota,” which I think is a bit confusing. In short, you only have quota available for the models available to you to use.
OpenAI models are among those available on my subscription, though, so I’m going to choose a modern model from those options (at the time of this writing, that’s the three GPT-5.6 models). I’m going to search for gpt-5.6 and use Terra.
Note that, whatever model you choose, for it to work with GitHub Copilot, it must support streaming and tool calling. You can filter for these features using the “Supported features” section to the left of the models.
Clicking the model will take you to that model’s page. From here, we can see some info about the model, as well as deploy it. We can just use the default settings for this. Feel free to poke around at the custom settings, but it’s nothing we need to change for this post.
You can see that we can do things like chat with the model from directly within Foundry, but we don’t care about any of that right now. The only thing we need here is the API key! Click the Details tab to get it.
As a note, this is the same API key that appears on your Foundry project’s Home page, so it’s not specific to this model deployment.
The next sections will cover using this API key in Copilot CLI and Copilot in VS Code, so go to whichever sections are relevant for you.
Using our Azure model with GitHub Copilot CLI
Now that we have our API key, we can use our Azure-hosted model with GitHub Copilot. To use external and local models, GitHub Copilot supports BYOK (bring your own key) mode, which is what we’ll be using. This docs page will serve as a useful reference for us. Specifically, we need to run copilot with these environment variables:
COPILOT_PROVIDER_BASE_URL=https://YOUR-RESOURCE-NAME.openai.azure.com/openai/deployments/YOUR-DEPLOYMENT-NAME
COPILOT_PROVIDER_TYPE=azure
COPILOT_PROVIDER_API_KEY=YOUR-AZURE-API-KEY
COPILOT_MODEL=YOUR-DEPLOYMENT-NAME
Note: do NOT use the project URL shown on the Details tab on Foundry. Instead, use the URL format shown above from the Copilot docs. When I tested with the Foundry URL, I found that even though I could successfully chat with the hosted model, Copilot CLI never loaded any of my MCP servers or skills. When I used the URL in the Copilot CLI docs, everything loaded as normal.
Rather than set the environment variables globally, we can run all this as a single command, which sets the environment variables for this command only. Fill in your own values and run this command. Here’s my version, with my API key removed:
COPILOT_PROVIDER_TYPE=azure COPILOT_PROVIDER_BASE_URL=https://dward-hosted-models-resource.openai.azure.com/openai/deployments/gpt-5.6-terra COPILOT_PROVIDER_API_KEY=MyApiKey COPILOT_MODEL=gpt-5.6-terra copilot
As a note, we’re giving this the model deployment name, not the model name. With the default deployment options, these are the same value, but if you gave your deployment a custom name, then make sure to use that instead of the model name.
Now, you should be able to run that and use your Foundry model with Copilot CLI!
You can also set the model reasoning level with BYOK (if the model supports it) with the --effort flag, eg copilot --effort high.
⭐CLI bonus 1 : Making a script to run the command easier
That command is pretty long and annoying to type every time, so I made a small bash script that lets me just run copilot-azure <deployment name> for the same result. You can still pass the copilot command its own arguments as normal, eg. copilot-azure gpt-5.6-terra --effort high.
To avoid storing the API key as plaintext, this fetches it from Azure. You can decide for yourself if that’s worth the hassle.
Rather than put the whole script here, I’ll link to its GitHub repo, which also has the below status line script: https://github.com/danielwarddev/copilot-cli-azure
⭐CLI bonus 2: Getting Azure spending usage in the status line
(Unfortunately, the equivalent of this for VS Code requires writing an extension, which I didn’t bother with.)
You might notice that our spending stays at 0 AIC (AI credits) in Copilot CLI while in BYOK mode. Since we’re using external models, Copilot CLI doesn’t have information on how we’re being charged. We can fix this with a custom status line script, though!
This script isn’t really the topic of this post, and is split out across several files, so I’m not going to go into detail about it here. Instead, I’ll just link you to my GitHub repo for it and show you what it looks like once you’re using it.
GitHub repo: https://github.com/danielwarddev/copilot-cli-azure
What it looks like:
Using our Azure model with GitHub Copilot in VS Code
Now that we have our API key, we can use our Azure-hosted model with GitHub Copilot. To use external and local models, GitHub Copilot supports BYOK (bring your own key) mode, which is what we’ll be using. This docs page shows essentially what we’ll be doing, but I’ll guide you through it for our specific Foundry use case.
Click your model name in VS Code and then click the gear next to “Other Models”.
From here, click “Add Models” and then choose “Azure”.
It’ll ask you what you want to name the group of models (I just kept “Azure”) and for your API key, so go ahead and paste it in.
You’ll then see it open up a JSON file, chatLanguageModels.json. We’ll need to change a few of the values to make it work. Change yours to look like mine, changing your url and id to your model deployment name as necessary.
Note: do NOT use the project URL shown on the Details tab on Foundry. Instead, use the URL format shown below (which I found from the VS Code docs link above). I tried with the Foundry URL at first, and it errored upon prompting.
{
"name": "Azure",
"vendor": "azure",
"apiKey": "${input:chat.lm.secret.13866028}",
"models": [
{
"id": "gpt-5.6-terra",
"name": "GPT-5.6 Terra",
"url": "https://dward-hosted-models-resource.openai.azure.com/openai/v1/responses?api-version=preview",
"toolCalling": true,
"vision": true,
"maxInputTokens": 128000,
"maxOutputTokens": 16000,
"thinking": true,
"supportsReasoningEffort": [
"none",
"low",
"medium",
"high"
]
}
]
}
The supportsReasoningEffort field isn’t required, but you’ll notice it allows you to pick the reasoning effort in VS Code’s UI next to the model name (if the model supports it).
As a note, we’re setting the id to the model deployment name, not the model name. With the default deployment options, these are the same value, but if you gave your deployment a custom name, then make sure to use that instead of the model name.
Now, you should be able to use your Foundry model with Copilot in VS Code!
GitHub repo
That’s it! This should be enough to get you started with Azure Foundry-hosted models in GitHub Copilot.
If you’re using the CLI, you can check out the following GitHub repo for an easier way to run the command with the environment variables set, as well as a custom status line script that shows your Azure spend: https://github.com/danielwarddev/copilot-cli-azure











