Github Copilot Support
Setting up as Open AI work, but Antrophic models doesn't shows up.
https://aider.chat/docs/llms/github.html
@davioliveira-dev how are you getting gh copilot to work? did you do a custom opencode.json? If so, how did you populate it to get it to work? Thanks!
attempted configuring an opencode.json with no luck, would love to see github copilot as a provider option as it is free for students. @davioliveira-dev if you don't mind could you share how you achieved this configuration with opencode? Thanks!
An example would be awesome I was just saying to someone at work that I want to try this exact setup.
This is what worked for me:
- generate a token with a jetbrains IDE (https://aider.chat/docs/llms/github.html#where-do-i-get-the-token) I got api warnings when using the token that was generated with neovims copilot.lua plugin You can use a EAP version like https://www.jetbrains.com/webstorm/nextversion/, install the copilot plugin and login
- Add copilot to the auth.json file
- find the models you want to use https://aider.chat/docs/llms/github.html#discover-available-models
- add the models to an opencode.json file in your project folder
2: Add copilot to the auth.json file
~/.local/share/opencode/auth.json
{
"copilot": {
"type": "api",
"key": "{{ paste oauth token from ~/.config/github-copilot/apps.json here }}"
}
}
4: Add the models to an opencode.json file in your project folder
Add the models to the opencode.json file in your project folder
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"copilot": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "https://api.githubcopilot.com"
},
"models": {
"gpt-4o": {
"name": "gpt-4o"
},
"claude-3.7-sonnet": {
"name": "claude-3.7-sonnet"
}
}
}
}
}
tried to attempt this with the new config.json format and was unsuccessful, this is what i attempted
{
"$schema": "http://opencode.ai/config.json"
"theme": "opencode",
"model": "copilot/openai/gpt-4o",
"autoshare": false,
"autoupdate": true,
"provider": {
"copilot": {
"npm": "@ai-sdk/openai-compatible",
"options": {
"baseURL": "https://api.githubcopilot.com"
},
"models": {
"openai/gpt-4o": {
"name": "gpt-4o"
},
"anthropic/claude-3.7-sonnet": {
"name": "claude-3.7-sonnet"
}
}
}
}
}
used copilot as the "Other" provider on opencode auth login. and it seems opencode only registers openai as my provider and doesn't recognize copilot anymore
i tried the above config and it worked for me - in the modal selector are you using left/right arrow keys to go through different providers?
I did at the time and there was no option when using /models to hit the left/right arrow keys to see the 2 copilot models listed, only showed OpenAI provider models list. I will clear my config and try a fresh install. Looking back now I also see a syntax error in the config I posted, so high likelihood it's that assuming.
can confirm it is working, was an error in my config transitioning from the .toml format
@timotah @thijsvdanker for copilot provider are you only adding the baseurl option? I am getting a "Forbidden" api response which in my past history typically is due to not passing certain headers required by copilot api such as editor-version etc. How are you getting around this? Where is your copilot apps.json oauth_token coming from(neovim copilot.lua, an IDE, etc.)? Thanks!
@GitMurf I used the GitHub token found via ~/.config/github-copilot/apps.json. This is generated from IntelliJ CE. I used the link to aider documentation in the initial comment to start this issue by @davioliveira-dev. I have not tried any other way due to cautioning against using neovim's generated token. Only adding the baseURL option in config as well.
This is generated from IntelliJ CE.
ahh ok, yeah so it seems jetbrains IDEs have an auth token that works without the different vscode spoofed headers etc. I will warn you though based on my past testing that you will have half the context window (64k instead of 128k). It seems to be a limitation that github puts on non vscode based api calls.
Thanks for the quick response!!
attempted configuring an opencode.json with no luck, would love to see github copilot as a provider option as it is free for students. @davioliveira-dev if you don't mind could you share how you achieved this configuration with opencode? Thanks!
Sorry for the late response! I just set as openai compatible and worked. But the @thijsvdanker version using config file is better.
Now, i'm getting the forbidden error like @GitMurf :(
Now, i'm getting the forbidden error like @GitMurf :(
What auth key are you using. It HAS to be from a jetbrains IDE and can NOT be one from like neovim copilot.lua etc. Where are you getting your auth token?
I will warn you though based on my past testing that you will have half the context window (64k instead of 128k). It seems to be a limitation that github puts on non vscode based api calls.
Bummer! I was hoping I was wrong on this and/or something had changed since the last time I ran into this issue, but I just confirmed that indeed copilot tokens coming from Jetbrains IDEs have half the context window (64k). See screenshot below.
@thdxr do we need an oauth setup like we do for anthropic here?
@thdxr do we need an oauth setup like we do for anthropic here?
If you were thinking about adding "officially" GitHub copilot as a provider for opencode, the Block Goose handles refreshing the copilot token, auth etc so could be good to get a code example from. See here: https://github.com/block/goose/blob/main/crates/goose/src/providers/githubcopilot.rs
Also @adamdotdevin for a quick and dirty of how to refresh the token for copilot chat api (expires every 30 min) I put together both a powershell and shell script version in a Aider gh issue a while back: https://github.com/Aider-AI/aider/issues/2227#issuecomment-2881098223
You can also look at copilot.lua, CopilotChat.nvim, and CodeCompanion neovim plugins who all do variations of initial auth and refreshing tokens.
Hope this helps!
In order to use GitHub Copilot with the configuration outlined here I only had to change the names from
...
"anthropic/claude-3.7-sonnet": {
"name": "claude-3.7-sonnet"
}
to something like:
"claude-3.7-sonnet": {
"name": "claude-3.7-sonnet"
}
Then it worked.
In any case, I think @adamdotdevin is right and a OAuth authentication flow is needed, to not relay on a third party applications token.
I implemented such authentication flow and opened a PR - Of course with help of 🤖 opencode.
Let me know what you think.
released in 0.1.120