GitHub Copilot
Aider 可以连接到 GitHub Copilot 的 LLM 模型,因为 Copilot 提供了一个标准的 OpenAI 风格 接口端点:
https://api.githubcopilot.com
首先,安装 aider:
python -m pip install aider-install
aider-install
配置环境
# macOS/Linux
export OPENAI_API_BASE=https://api.githubcopilot.com
export OPENAI_API_KEY=<oauth_token>
# Windows (PowerShell)
setx OPENAI_API_BASE https://api.githubcopilot.com
setx OPENAI_API_KEY <oauth_token>
# 执行 setx 命令后需要重启 shell
如何获取 token?
最简单的方法是通过任意 JetBrains IDE(PyCharm、GoLand 等)登录 Copilot。 认证成功后会出现一个配置文件:
~/.config/github-copilot/apps.json
在 Windows 系统中,配置文件位于:
~\AppData\Local\github-copilot\apps.json
复制 oauth_token
的值 —— 这个字符串就是你的 OPENAI_API_KEY
。
注意: 由 Neovim copilot.lua 插件生成的 token(旧的 hosts.json
)有时会缺少必要的权限范围。如果遇到”access to this endpoint is forbidden”错误,请使用 JetBrains IDE 重新生成 token。
发现可用模型
Copilot 托管了多种模型(OpenAI、Anthropic、Google 等)。
列出你的订阅可用的模型:
curl -s https://api.githubcopilot.com/models \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-H "Copilot-Integration-Id: vscode-chat" | jq -r '.data[].id'
每个返回的模型 ID 都可以与 aider 一起使用,只需在前面加上 openai/
前缀:
aider --model openai/gpt-4o
# 或者
aider --model openai/claude-3.7-sonnet-thought
快速开始
# 切换到你的项目目录
cd /to/your/project
# 与 Copilot 对话
aider --model openai/gpt-4o
可选配置文件 (~/.aider.conf.yml
)
openai-api-base: https://api.githubcopilot.com
openai-api-key: "<oauth_token>"
model: openai/gpt-4o
weak-model: openai/gpt-4o-mini
show-model-warnings: false
常见问题
- 通过 aider 进行的调用会通过您的 Copilot 订阅计费
(aider 仍会显示预估费用)。 - Copilot 文档明确允许访问此 API 的第三方”代理”——aider 完全遵守规则。
- Aider 直接与 REST 端点通信,不涉及网页界面抓取或浏览器自动化。