Skip to main content

一、产品简介

OpenCode 是一款开源 AI 编程助手,支持 75+ 模型与本地部署。通过 Mixroute Api,可在 OpenCode 中统一使用各类主流与最新模型(如 GPT、Claude、Gemini 等),并支持自定义提供商与模型配置。 下载地址https://opencode.ai/

二、快速配置(Mixroute Api)

1. 获取 API 密钥

Mixroute Api 控制台 创建并复制 API 密钥。

2. 在 OpenCode 中配置自定义提供商

1

打开设置

打开 OpenCode,进入 服务器 / 提供商 设置
OpenCode 提供商设置
2

添加提供商

添加 自定义提供商(Configure an OpenAI compatible provider)
添加自定义提供商
3

填写配置

填写以下信息:
  • 提供商 ID:如 mixroute(小写、数字、连字符或下划线)
  • 显示名称:如 Mixroute Api
  • 基础 URLhttps://console.mixroute.io/v1(必须以 /v1 结尾)
  • API 密钥:粘贴 Mixroute Api 密钥
4

添加模型

模型 中添加需要使用的模型(如 gpt-4oclaude-sonnet-4-20250514 等)
5

保存使用

保存后,在模型选择中使用 提供商ID/模型ID(如 mixroute/gpt-4o
具体配置信息
配置项
基础 URLhttps://console.mixroute.io/v1
API 密钥在控制台获取(格式如 sk-xxxxxxxxxxxxx
模型从模型列表选择并填入模型 ID

3. 切换模型

在对话或设置中选择已配置的提供商与模型(如 mixroute/gpt-4o)即可切换。
  • 若使用自建或备用服务,将 基础 URL 改为对应地址,例如 http://your-server:3003/v1
  • 默认模型可在项目或全局 opencode.json 中设置 "model": "mixroute/模型ID"

三、部分模型需使用 Responses API(重要)

部分模型的访问接口与常规 Chat Completions 不同,需使用 Responses API。若在 OpenCode 中选用这类模型时出现类似错误:
The chatCompletion operation does not work with the specified model, gpt-5.1-codex. Please choose different model and try again.
错误示例
说明当前请求走了 Chat Completions,而该模型在服务端只开放 Responses API,需通过配置改为使用正确接口。

3.1 需要走 Responses API 的模型(典型)

模型 ID / 系列说明
gpt-5.1-codexGPT 5.1 Codex,编程/代码场景,仅支持 Responses API
gpt-5.2-codexGPT 5.2 Codex,同上
o3 / o3-pro推理模型,部分部署仅提供 Responses API
o4-mini 等 o4 系列同上,以实际部署与官方文档为准
computer-use-preview与 Responses API 的 computer-use 工具配合使用的实验模型

3.2 在 OpenCode 中如何配置

通过在配置文件中为对应模型添加 apiCompatibility 参数,即可让 OpenCode 对该模型使用 Responses API 1. 找到配置文件
  • WindowsC:\Users\<用户名>\.config\opencode\opencode.jsonc
  • macOS / Linux~/.config/opencode/opencode.jsonc
配置文件位置
2. 在自定义提供商的模型配置中添加参数 对需要走 Responses API 的模型增加 "apiCompatibility": "responses"
{
  "$schema": "https://opencode.ai/config.json",
  "provider": {
    "mixroute": {
      "name": "mixroute",
      "npm": "@ai-sdk/openai-compatible",
      "models": {
        "gpt-5.2": {
          "name": "gpt-5.2"
        },
        "gpt-5.1-codex": {
          "name": "gpt-5.1-codex",
          "apiCompatibility": "responses"
        },
        "gpt-5.1-chat": {
          "name": "gpt-5.1-chat"
        }
      },
      "options": {
        "baseURL": "https://console.mixroute.io/v1"
      }
    }
  }
}
保存后,在 OpenCode 中选择该提供商下的 gpt-5.1-codex(如 mixroute/gpt-5.1-codex),请求会以 Responses API 格式发往该 baseURL。
配置成功示例

3.3 小结

场景做法
使用 gpt-5.1-codex / gpt-5.2-codex 等仅支持 Responses 的模型opencode.jsonc 中,于对应自定义提供商的 models 里为该模型添加 "apiCompatibility": "responses"
使用 gpt-4o、claude-sonnet 等常规模型无需添加 apiCompatibility,按上文「快速配置」使用即可

四、推荐模型

类型模型 ID 示例说明
编程 / Codexgpt-5.1-codex需确保走 Responses API(见第三节)
通用对话 / 编程gpt-5.2gpt-5.1-chat直接使用,无需 Responses 特殊配置
长文本 / 综合claude-sonnet-4-20250514claude-sonnet-4-5同上
性价比gpt-4.1-minigemini-2.5-flash同上

五、配置成功示例

下图为使用 Mixroute Api 在 OpenCode 中正常对话的示例:
OpenCode 对话示例

六、参考链接