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

相关推荐
康康的AI博客3 小时前
什么是API中转服务商?如何低成本高稳定调用海量AI大模型?
人工智能·ai
FIT2CLOUD飞致云3 小时前
赛道第一!1Panel成功入选Gitee 2025年度开源项目
服务器·ai·开源·1panel
chunmiao30324 小时前
了解github上,watch,fork,star代表啥
github
XSKY星辰天合4 小时前
XSKY 赋能高端半导体制造:12 寸晶圆产线数据的高效管治实践
ai·分布式存储
CoderJia程序员甲4 小时前
GitHub 热榜项目 - 日榜(2026-01-30)
开源·大模型·llm·github·ai教程
DS随心转插件5 小时前
ChatGPT和Gemini排版指令
人工智能·ai·chatgpt·deepseek·ds随心转
数字游民95275 小时前
半年时间大概上了70个web站和小程序,累计提示词超过20w
人工智能·ai·小程序·vibecoding·数字游民9527
Testopia5 小时前
AI编程实例 - 爆款文章预测:K-Means聚类与分类算法的实践
人工智能·分类·kmeans·ai编程·聚类
ssxueyi5 小时前
AI编程之智谱+claude code详细安装使用教程
人工智能·ai编程·智谱·claude code
Aliex_git5 小时前
Claude Code 使用笔记(四)- GitHub Claude 审查助手
人工智能·笔记·学习·github·ai编程