A proxy server to expose OpenAI-compatible endpoints for GitHub Copilot API
- Fetches and refreshes GitHub Copilot API tokens using a GitHub OAuth token.
- Reads GitHub Copilot OAuth token automatically from
~/.config/github-copilot/apps.jsonif not passed on the command line. - Optional access token to restrict API usage.
- Valid Copilot-enabled GitHub OAuth token
- Github Copilot
oauth_tokenor a valid~/.config/github-copilot/apps.jsonfile
go build -o copilot-proxy main.go# binary
./copilot-proxy -oauth-token <GITHUB_OAUTH_TOKEN> -access-token <randome token> [flags...]
# docker
docker run -d \
--name copilot-proxy \
--restart always \
-v $HOME/.config/github-copilot:/.config/github-copilot \
-p 8080:8080 \
ghcr.io/xuyuanp/copilot-proxySupported flags:
-oauth-token— GitHub Copilot OAuth token (will try to read from file if omitted)-access-token— (optional) Access token for user authentication to the proxy itself-addr— Address to listen on (default::8080)-base-path— Base API path to match and remove from incoming requests (default:/api/v1)
curl -H "Authorization: Bearer <your-token>" \
http://localhost:8080/api/v1/chat/completions \
-XPOST \
-d '{"model": "gpt-4o", "messages": [{"role": "user", "content": "tell me a joke"}]}' | jq '.choices[0].message.content'export OPENAI_BASE_URL=http://localhost:8080/api/v1
export OPENAI_API_KEY='<your-token>'
openai api chat.completions.create -m gpt-4o --stream -g 'user' 'tell me a joke'In the file ~/.config/github-copilot/apps.json, you can find your GitHub Copilot OAuth token under the key oauth_token. An example of the file is:
{
"github.com:xxx": {
"user": "<your-user-name>",
"oauth_token": "<THIS IS YOUR OAUTH TOKEN>",
"githubAppId": "xxx"
}
}- If you have Zed installed, you can sing in to GitHub Copilot in Zed.
- If you are familiar with Neovim, you can either install copilot.vim or copilot.lua to sign in to GitHub Copilot.
- You still need to install Neovim (>=0.11.0) and copilot-language-server, run command
nvim -n --headless -u nvim/init.lua tmp.cand follow the instructions.