GitHub Copilot 调用第三方模型API

一、说明

OAI Compatible Provider for Copilot 的作用是:把 Copilot/Copilot Chat 发出的"类似 OpenAI API 的请求",转发到指定的 OpenAI-Compatible 服务端(例如 ModelScope 推理网关、自建的兼容网关等)。

⚠️ Warning

登录 GitHub Copilot​ 的账号一定要是非组织方式开通 pro 会员的,不然无法管理模型。

推荐直接用免费的free账号登录即可。

二、插件安装

在 VS Code 扩展市场安装并启用:

  • GitHub Copilot
  • GitHub Copilot Chat
  • OAI Compatible Provider for Copilot(johnny-zhao.oai-compatible-copilot)

安装后:Developer: Reload Window​ 重载窗口一次。

确保已在 VS Code 中登录 GitHub,并且 Copilot 正常可用(不然你分不清是 Copilot 本身问题还是 provider 转发问题)。

三、配置示例

建议将配置放置在项目内的: .vscode/settings.json​

1、单模型示例

javascript 复制代码
{
    "oaicopilot.baseUrl": "https://api.soraharu.com/v1",
    "oaicopilot.delay": 0,
    "oaicopilot.readFileLines": 0,
    "oaicopilot.retry": {
        "enabled": true,
        "max_attempts": 3,
        "interval_ms": 1000,
        "status_codes": []
    },
    "oaicopilot.commitLanguage": "English",
    "oaicopilot.models": [
        {
            "id": "__provider__soraharu",
            "owned_by": "soraharu",
            "baseUrl": "https://api.api.soraharu.com/v1",
            "apiMode": "openai"
        },
        {
            "id": "google/gemini-3-pro-preview",
            "owned_by": "soraharu",
            "baseUrl": "https://api.soraharu.com/v1",
            "context_length": 128000,
            "max_tokens": 4096,
            "vision": true,
            "apiMode": "openai",
            "temperature": 0
        }
    ]
}

2、多模型示例

javascript 复制代码
{
    "oaicopilot.baseUrl": "https://api.soraharu.com/v1",
    "oaicopilot.delay": 0,
    "oaicopilot.readFileLines": 0,
    "oaicopilot.retry": {
        "enabled": true,
        "max_attempts": 3,
        "interval_ms": 1000,
        "status_codes": []
    },
    "oaicopilot.commitLanguage": "English",
    "oaicopilot.models": [
        {
            "id": "__provider__soraharu",
            "owned_by": "soraharu",
            "baseUrl": "https://api.soraharu.com/v1",
            "apiMode": "openai"
        },
        {
            "id": "google/gemini-3-pro-preview",
            "owned_by": "soraharu",
            "baseUrl": "https://api.soraharu.com/v1",
            "context_length": 128000,
            "max_tokens": 4096,
            "vision": true,
            "apiMode": "openai",
            "temperature": 0
        },
        {
            "id": "anthropic/claude-opus-4-5-thinking",
            "owned_by": "soraharu",
            "baseUrl": "https://api.soraharu.com/v1",
            "context_length": 128000,
            "max_tokens": 4096,
            "vision": true,
            "apiMode": "openai",
            "temperature": 0
        },
        {
            "id": "anthropic/claude-sonnet-4-thinking",
            "owned_by": "soraharu",
            "baseUrl": "https://api.soraharu.com/v1",
            "context_length": 128000,
            "max_tokens": 8192,
            "vision": true,
            "apiMode": "openai",
            "temperature": 0
        }
    ]
}

3、配置讲解

配置主要分为两块:

  • 顶层通用项(全局 API 地址、重试等)
  • oaicopilot.models数组(定义可选的大模型)
顶层通用项
字段 作用
​oaicopilot.baseUrl​ 通用 API 基地址,推荐全局只用一处。
​oaicopilot.delay​ 控制 Copilot 插件调用接口时的延迟,一般设 0(默认即可)
​oaicopilot.readFileLines​ 配合 Copilot 文件分段补全时用,设 0 即可
​oaicopilot.retry​ Copilot Chat请求失败时的自动重试策略。
​oaicopilot.commitLanguage​ Copilot建议生成commit的语言,通常填"English"即可
模型池 oaicopilot.models​
字段 作用
​id​ 必须和/v1/models​能获得的模型id​一致(如"google/gemini-3-pro-preview"​)
​owned_by​ 一般填"provider名"即可,描述归属或来源
​baseUrl​ 建议只在顶层写一处,模型对象里不强制(写也可以,冲突时顶层优先)
​apiMode​ 绝大多数 Soraharu/OneAPI都填"openai",如果是anthropic/olllama/自定义才需变
​context_length​ 最大上下文长度(token数,依照模型能力填)
​max_tokens​ 每次回应的最大输出(token数,官方建议4096/8192之类)
​vision​ 支持多模态(如Gemini/Claude/Sonnet等具备图文能力才设true)
​temperature​ 控制AI输出随机性,越低回答越稳定,代码任务建议设为0

4、配置KEY

在 VSCode​ 页面进行操作:

  • Windows/Linux 环境:Ctrl+Shift+P
  • Mac 环境:Cmd+Shift+P

输入下面的命令,然后将KEY输入进去:

​Set OAl Compatible Multi-Provider Apikey​

四、模型使用

  1. 点击进入 Copilot 聊天框
  2. 点击模型选择框
  3. 点击模型管理(Manage Modules....)
  1. 选择 OAI Compatible 将左侧的隐藏眼睛关闭,这样我们自己设定的模型就会出现在选择框了。

​

​

相关推荐
子兮曰3 天前
Jev 爆发一周:7 秒 Agent 背后的 System One 生态与三场争议
前端·后端·ai编程
1点东西3 天前
做了近两年的Agent开发,其实真正要学的就是这五件事
llm·agent·ai编程
七牛云行业应用3 天前
Qwen-Image-2.1 开源部署完整指南:Diffusers、ComfyUI 与推理服务
ai编程
感谢地心引力3 天前
我用 Doubao-Seed-2.1-pro 做了一个深度融入 AI 功能的本地知识库软件
ai·开源·seed·markdown·豆包
阿昌喜欢吃黄桃3 天前
提示词工程:User Prompt 与 System Prompt
ai·prompt·提示词·提示词工程
AI产品测评官3 天前
海内外AI招聘工具分赛道横向对比:五大品类的技术路线与选型参考
人工智能·ai·求职招聘
福如意如我心意3 天前
TencentDB Agent Memory和其他开源memory
ai编程
俊哥V3 天前
每日 AI 研究简报 · 2026-09-21
人工智能·ai
lpfasd1233 天前
2026年第38周GitHub趋势周报
python·科技·github
u1301303 天前
GitHub 热榜项目:日榜(2026-09-21)
人工智能·github