跳转到主要内容
OpenCode 是一款用于终端的 AI 编码 agent。Venice 通过 OpenCode 的自定义提供商配置工作,使用 OpenAI 兼容的适配器和自定义的 base URL。

自定义提供商

opencode.json 中将 Venice 添加为提供商

OpenAI 兼容

使用 Venice 的 /chat/completions 端点

环境变量密钥

VENICE_API_KEY 读取您的 API 密钥

前置条件

  • 来自 venice.ai/settings/api 的 Venice API 密钥
  • 已在您的机器上安装并可正常使用的 OpenCode

设置

1

设置您的 Venice API 密钥

在运行 OpenCode 的 shell 中导出您的 Venice API 密钥:
export VENICE_API_KEY="your-api-key"
2

创建 OpenCode 配置文件

对于项目专属设置,在项目根目录创建 opencode.json对于全局设置,改用 ~/.config/opencode/opencode.json
3

添加 Venice 提供商

将以下配置粘贴到 opencode.json
{
  "$schema": "https://opencode.ai/config.json",
  "model": "venice/zai-org-glm-5-1",
  "small_model": "venice/zai-org-glm-5-1",
  "provider": {
    "venice": {
      "npm": "@ai-sdk/openai-compatible",
      "name": "Venice AI",
      "options": {
        "baseURL": "https://api.venice.ai/api/v1",
        "apiKey": "{env:VENICE_API_KEY}"
      },
      "models": {
        "zai-org-glm-5-1": {
          "name": "GLM 5.1"
        },
        "kimi-k2-5": {
          "name": "Kimi K2.5"
        },
        "minimax-m25": {
          "name": "MiniMax M2.5"
        }
      }
    }
  }
}
4

运行 OpenCode

从同一项目目录启动 OpenCode:
opencode
OpenCode 将加载 opencode.json,使用 VENICE_API_KEY,并通过 https://api.venice.ai/api/v1 路由所选的 Venice 模型。

验证设置

在 OpenCode 中运行:
/models
您应该会看到配置中的 Venice 模型。选择一个,然后发送一个小的测试 prompt。 如果您像上面那样设置 "model": "venice/zai-org-glm-5-1",OpenCode 应默认使用该 Venice 模型。您可以将 zai-org-glm-5-1 替换为文本模型目录中任意模型 ID,并将其添加到 models 映射中,以更改默认模型。

配置说明

  • baseURL 保持为 https://api.venice.ai/api/v1。OpenCode 的 OpenAI 兼容适配器将此 base URL 用于 chat completions。
  • npm 保持为 @ai-sdk/openai-compatible,用于 Venice 的 OpenAI 兼容聊天端点。
  • 提供商 ID 是 venice,因此模型引用使用 venice/<model-id> 格式。
  • 如果您更倾向于使用 OpenCode 的 /connect 流程,选择 Other,使用 venice 作为提供商 ID,粘贴您的 Venice API 密钥,并从配置中删除 options.apiKey
OpenCode 已通过 @ai-sdk/openai-compatible 支持自定义提供商 baseURL 值和 OpenAI 兼容提供商。Venice 无需对 OpenCode 核心提供商进行任何更改。

资源

Venice 文本模型

可用的 Venice 模型 ID

OpenCode 提供商文档

自定义提供商和 base URL 参考