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 将左侧的隐藏眼睛关闭,这样我们自己设定的模型就会出现在选择框了。

相关推荐
workflower4 小时前
用硬件换时间”与“用算法降成本”之间的博弈
人工智能·算法·安全·集成测试·无人机·ai编程
OPHKVPS5 小时前
Anthropic 为 Claude Code 推出“自动模式”:AI 编码工具迈向更高自主性
网络·人工智能·安全·ai
yyk的萌6 小时前
AI 应用开发工程师基础学习计划
开发语言·python·学习·ai·lua
2301_764441336 小时前
OpenClaw框架的多Agent协作系统
人工智能·机器学习·语言模型·自然语言处理·ai编程
财经资讯数据_灵砚智能10 小时前
全球财经资讯日报(日间)2026年4月2日
大数据·人工智能·python·语言模型·ai编程
程序员鱼皮10 小时前
鱼皮 AI 导航网站,突然起飞了!
人工智能·ai·程序员·编程·ai编程
俊哥V10 小时前
每日 AI 研究简报 · 2026-04-02
人工智能·ai
最贪吃的虎10 小时前
GitHub推送又超时了?试试SSH
运维·ssh·github
TechExplorer36510 小时前
Claude Code 最佳实践指南
ai·claude code