Source: https://wiki.niceai.dev/guide/clients/vscode-copilot

# VS Code Copilot Chat 接入自定义 API

VS Code 支持“自带密钥”（BYOK）：在 **Chat: Manage Language Models** 中添加 **Custom Endpoint**，API 类型选 Chat Completions（`https://api.niceai.dev/v1/chat/completions`）或 Messages（`https://api.niceai.dev/v1/messages`），填入 NiceAI 密钥，就能在 Chat 视图里选用这些模型。

## 准备工作

1. 使用较新版本的 VS Code。
2. 在 NiceAI 控制台「[API 密钥](https://niceai.dev/keys)」页面创建密钥：Messages 类型用 **Claude** 分组，Chat Completions 或 Responses 类型用对应模型的分组。

## 配置步骤

1. 在 Chat 视图的模型选择器中点击 **Manage Language Models**（齿轮图标），或在命令面板运行 `Chat: Manage Language Models`。
2. 点击 **Add Models**，选择 **Custom Endpoint**。
3. 输入分组名称（显示在模型选择器里），再输入显示名称和 NiceAI 密钥。
4. 选择 API 类型：Chat Completions、Responses 或 Messages。
5. VS Code 会打开 `chatLanguageModels.json`，按下方示例填写模型信息并保存。
6. 在 Chat 的模型选择器中选中新模型。没出现时重启 VS Code。

**-group**

```json [Messages（Claude）]
[
  {
    "name": "NiceAI Claude",
    "vendor": "customendpoint",
    "apiKey": "${input:niceaiKey}",
    "apiType": "messages",
    "models": [
      {
        "id": "<模型名，见模型广场>",
        "name": "<显示名称>",
        "url": "https://api.niceai.dev/v1/messages",
        "toolCalling": true,
        "vision": true
      }
    ]
  }
]
```

```json [Chat Completions]
[
  {
    "name": "NiceAI",
    "vendor": "customendpoint",
    "apiKey": "${input:niceaiKey}",
    "apiType": "chat-completions",
    "models": [
      {
        "id": "<模型名，见模型广场>",
        "name": "<显示名称>",
        "url": "https://api.niceai.dev/v1/chat/completions",
        "toolCalling": true
      }
    ]
  }
]
```



`${input:niceaiKey}` 表示用 VS Code 的输入变量保存密钥，避免把密钥明文写进文件。

## 地址怎么填

VS Code 的规则是：`url` 里已经包含 `/chat/completions`、`/responses` 或 `/messages` 时原样使用；否则会自动补路径，没有 `/v1` 时还会先补 `/v1`。为了避免歧义，建议像上面一样直接填完整地址。

## 适用范围

- 自带密钥的模型用于 Chat 和 Agent 对话。代码补全（inline suggestions）、语义搜索、embeddings 等功能仍依赖 GitHub Copilot 服务，不会走自定义模型。
- Copilot Business / Enterprise 用户需要管理员在 GitHub 的 Copilot 策略中允许 BYOK。
- 旧版的 OpenAI Compatible 供应商和 `github.copilot.chat.customOAIModels` 设置已被 Custom Endpoint 取代。

## 常见问题

### 返回 401？

Messages 类型会用 `x-api-key` 发送密钥，其他类型用 `Authorization: Bearer`。确认密钥分组和 API 类型对应。

### Agent 模式下不调用工具？

确认模型配置里写了 `"toolCalling": true`，并且所选模型本身支持工具调用。

## 下一步

- [Cline 接入](https://wiki.niceai.dev/guide/clients/cline)
- [Kilo Code 接入](https://wiki.niceai.dev/guide/clients/kilo-code)
