CherryINCherryIN
New API 使用指南

VSCode 配置教程

在 VS Code Copilot Chat 中通过 Custom Endpoint(BYOK)使用 CherryIN API

关于 VS Code BYOK

VS Code 的 Copilot Chat 支持 Bring Your Own Key(BYOK):通过 Custom Endpoint 接入任何 OpenAI 兼容的模型服务。

CherryIN 提供 OpenAI 兼容接口,所以可以直接以 Custom Endpoint 方式接入。

前置条件

  • VS Code 版本需支持 Chat: Manage Language Models(近期 stable 版本均已支持,旧版请升级)
  • 安装并启用 GitHub Copilot Chat 扩展
  • BYOK 只作用于 Chat / Agent,不影响代码补全(completions)
  • Copilot Free / Pro / Pro+ 均可使用

开始之前

请先准备好:

  1. 已完成 快速上手,拿到 CherryIN API Key
  2. 已安装最新版 VS Code 与 GitHub Copilot Chat 扩展
  3. 准备一个模型 ID,例如 anthropic/claude-sonnet-4.5

配置步骤

打开 Language Models 面板

⌘ + Shift + P(macOS)/ Ctrl + Shift + P(Windows / Linux)打开命令面板,输入 manage,选择 Chat: Manage Language Models

也可以从 Chat 视图右上角点齿轮图标进入同一个面板。

命令面板里搜 manage,选择 Chat: Manage Language Models

添加 Custom Endpoint

在打开的 Language Models 面板里,点右上角的 Add Models... 按钮,从下拉列表中选择 Custom Endpoint

下拉里同时也会列出 Anthropic / Azure / Google / Ollama / OpenAI / OpenRouter / xAI 等内置 provider,CherryIN 走 Custom Endpoint

Language Models 面板中点 Add Models 选择 Custom Endpoint

填入 API Key

紧接着 VS Code 会弹出 Custom Endpoint: API Key 输入框,提示 Enter value for apiKey

把你的 CherryIN API Key 粘进去,回车确认。

Custom Endpoint: API Key 输入框

选择 API Type

接着会弹出 Custom Endpoint: API Type 选择框,三个选项:

选项说明
Chat CompletionsOpenAI 风格的 Chat Completions API
ResponsesOpenAI 新版 Responses API
MessagesAnthropic 风格的 Messages API

CherryIN 选 Chat Completions

为什么不是 Messages

即使你接的是 Claude 模型,这里也选 Chat Completions,因为 CherryIN 暴露的是 OpenAI 兼容接口(/v1/chat/completions),不是原生 Anthropic Messages 协议。

Custom Endpoint: API Type 选择 Chat Completions

在 chatLanguageModels.json 里填模型信息

确认 Key 之后,VS Code 会自动打开 chatLanguageModels.json(位于用户配置目录,例如 macOS 的 ~/Library/Application Support/Code/User/chatLanguageModels.json),里面已经预填好了一条骨架:

chatLanguageModels.json
[
  {
    "name": "Custom Endpoint",
    "vendor": "customendpoint",
    "apiKey": "${input:chat.lm.secret.xxxxxxxx}",
    "apiType": "chat-completions",
    "models": [
      {
        "id": "",
        "name": "",
        "url": "",
        "toolCalling": true,
        "vision": true,
        "maxInputTokens": 128000,
        "maxOutputTokens": 16000
      }
    ]
  }
]

chatLanguageModels.json 中需要填写的 id / name / url 字段

只需要填三个空字段id / name / url(截图里红框圈出的部分)。其它字段(vendor / apiKey / apiType / 默认 token 上限)保持 VS Code 生成的即可。

按 CherryIN 填好后的样子:

chatLanguageModels.json
[
  {
    "name": "Custom Endpoint",
    "vendor": "customendpoint",
    "apiKey": "${input:chat.lm.secret.xxxxxxxx}",
    "apiType": "chat-completions",
    "models": [
      {
        "id": "anthropic/claude-sonnet-4.5",
        "name": "CherryIN · Claude Sonnet 4.5",
        "url": "https://open.cherryin.net/v1/chat/completions",
        "toolCalling": true,
        "vision": true,
        "maxInputTokens": 200000,
        "maxOutputTokens": 8192
      }
    ]
  }
]

字段说明:

字段填写说明
idCherryIN 上的完整模型 ID,例如 anthropic/claude-sonnet-4.5
name显示在模型选择器里的名字,自由命名
url完整的 endpoint 路径https://open.cherryin.net/v1/chat/completions
toolCalling / vision模型是否支持工具调用 / 视觉,按实际模型勾选
maxInputTokens / maxOutputTokens按模型实际能力填,VS Code 默认值是 128000 / 16000

apiKey 是引用,不是明文

apiKey 字段里看到的 ${input:chat.lm.secret.xxxxxxxx} 是 VS Code 对 Secret Storage(钥匙串)的引用 —— 真实 Key 已经在上一步存进了系统钥匙串。不要把明文 Key 替换进去,否则会泄漏。

保存这个 JSON 后,新模型会出现在 Language Models 面板的 Custom Endpoint 分组下。

在 Chat 里切换并测试

打开 Chat 视图,点底部的模型选择器,把当前模型切到刚刚添加的 CherryIN · Claude Sonnet 4.5,发送一条简单消息:

请先阅读当前项目结构,并告诉我这个仓库是做什么的。

如果能正常返回结果,说明配置已经生效。


添加多个模型

models 是数组,可以在一份 chatLanguageModels.json 里同时挂多条 CherryIN 模型:

chatLanguageModels.json
[
  {
    "name": "Custom Endpoint",
    "vendor": "customendpoint",
    "apiKey": "${input:chat.lm.secret.xxxxxxxx}",
    "apiType": "chat-completions",
    "models": [
      {
        "id": "anthropic/claude-sonnet-4.5",
        "name": "CherryIN · Claude Sonnet 4.5",
        "url": "https://open.cherryin.net/v1/chat/completions",
        "toolCalling": true,
        "vision": true,
        "maxInputTokens": 200000,
        "maxOutputTokens": 8192
      },
      {
        "id": "anthropic/claude-opus-4",
        "name": "CherryIN · Claude Opus 4",
        "url": "https://open.cherryin.net/v1/chat/completions",
        "toolCalling": true,
        "vision": true,
        "maxInputTokens": 200000,
        "maxOutputTokens": 8192
      },
      {
        "id": "google/gemini-2.5-flash",
        "name": "CherryIN · Gemini 2.5 Flash",
        "url": "https://open.cherryin.net/v1/chat/completions",
        "toolCalling": true,
        "vision": true,
        "maxInputTokens": 1000000,
        "maxOutputTokens": 8192
      }
    ]
  }
]

推荐模型

模型 ID适合场景
anthropic/claude-sonnet-4.5日常编码、重构、代码解释
anthropic/claude-opus-4复杂分析、长上下文任务
google/gemini-2.5-flash成本敏感、响应速度优先

常见问题

Add Models... 里找不到 Custom Endpoint

请确认:

  1. VS Code 已升级到 stable 最新版(早期 Insiders 版本入口名称不同)
  2. GitHub Copilot Chat 扩展已安装并启用
  3. 通过命令面板的 Chat: Manage Language Models 进入面板

提示 404 或请求失败

Custom Endpoint 这里要的是完整 endpoint,不是 Base URL,注意带上 /chat/completions

https://open.cherryin.net/v1/chat/completions

漏掉 /v1/chat/completions 都会 404。

模型选择器里看不到我加的模型

  1. 保存 chatLanguageModels.json 后,回到 Language Models 面板看 Custom Endpoint 分组里是不是已经出现
  2. 在 Chat 视图底部点模型名 → 勾选刚才那条
  3. 如果还是没出现,关闭并重新打开 Chat 视图

API Key 填了还是认证失败

请检查:

  1. Key 是否来自 CherryIN 控制台
  2. Key 前后是否有空格
  3. 账户是否已充值并处于可用状态
  4. 如果之前填错过,可在命令面板运行 Chat: Manage Language Models,对 Custom Endpoint 重新输入 Key

BYOK 不影响补全(completion)

VS Code 官方明确说明:BYOK 只作用于 Chat / Agent,代码补全仍走 Copilot 内置模型,无法用 CherryIN 替换。

下一步