Skip to content

模型

配置 LLM 提供商和模型。

OpenCode 使用 AI SDKModels.dev 来支持 75+ 个 LLM 提供商,并且支持运行本地模型。


提供商

默认情况下,最受欢迎的提供商已预加载。如果你通过 /connect 命令添加了某个提供商的凭证,那么当你启动 OpenCode 时,它们将可用。

了解更多关于提供商的信息。


选择模型

配置好提供商后,你可以通过输入以下命令来选择你想要的模型:

/models

推荐模型

市面上有很多模型,每周都有新模型推出。

然而,只有少数模型在生成代码和工具调用方面都表现出色。

以下是一些与 OpenCode 配合良好的模型,排名不分先后。(这不是一个详尽的列表,也不一定是最新的):

  • GPT 5.2
  • GPT 5.1 Codex
  • Claude Opus 4.5
  • Claude Sonnet 4.5
  • Minimax M2.1
  • Gemini 3 Pro

设置默认模型

要将其中一个模型设置为默认模型,你可以在 OpenCode 配置中设置 model 键。

opencode.json
{
"$schema": "https://opencode.ai/config.json",
"model": "lmstudio/google/gemma-3n-e4b"
}

这里的完整 ID 是 provider_id/model_id。例如,如果你使用 OpenCode Zen,你会使用 opencode/gpt-5.1-codex 来指定 GPT 5.1 Codex。

如果你配置了自定义提供商,那么 provider_id 是你配置中 provider 部分的键,而 model_idprovider.models 中的键。


配置模型

你可以通过配置文件全局配置模型的选项。

opencode.jsonc
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"openai": {
"models": {
"gpt-5": {
"options": {
"reasoningEffort": "high",
"textVerbosity": "low",
"reasoningSummary": "auto",
"include": ["reasoning.encrypted_content"],
},
},
},
},
"anthropic": {
"models": {
"claude-sonnet-4-5-20250929": {
"options": {
"thinking": {
"type": "enabled",
"budgetTokens": 16000,
},
},
},
},
},
},
}

这里我们为两个内置模型配置了全局设置:通过 openai 提供者访问的 gpt-5,以及通过 anthropic 提供者访问的 claude-sonnet-4-20250514。 内置的提供者和模型名称可以在 Models.dev 上找到。

你也可以为你正在使用的任何智能体配置这些选项。智能体配置会覆盖此处的任何全局选项。了解更多

你还可以定义扩展内置模型的自定义变体。变体允许你为同一模型配置不同的设置,而无需创建重复的条目:

opencode.jsonc
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"opencode": {
"models": {
"gpt-5": {
"variants": {
"high": {
"reasoningEffort": "high",
"textVerbosity": "low",
"reasoningSummary": "auto",
},
"low": {
"reasoningEffort": "low",
"textVerbosity": "low",
"reasoningSummary": "auto",
},
},
},
},
},
},
}

变体

许多模型支持具有不同配置的多种变体。OpenCode 为流行的提供商提供了内置的默认变体。

内置变体

OpenCode 为许多提供商提供了默认变体:

Anthropic

  • high - 高思维预算(默认)
  • max - 最大思维预算

OpenAI

因模型而异,但大致如下:

  • none - 无推理
  • minimal - 最小推理努力
  • low - 低推理努力
  • medium - 中等推理努力
  • high - 高推理努力
  • xhigh - 超高推理努力

Google

  • low - 较低努力/令牌预算
  • high - 较高努力/令牌预算

自定义变体

您可以覆盖现有变体或添加自己的变体:

opencode.jsonc
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"openai": {
"models": {
"gpt-5": {
"variants": {
"thinking": {
"reasoningEffort": "high",
"textVerbosity": "low",
},
"fast": {
"disabled": true,
},
},
},
},
},
},
}

循环切换变体

使用快捷键 variant_cycle 可以在变体之间快速切换。了解更多


加载模型

当 OpenCode 启动时,它会按以下优先级顺序检查模型:

  1. --model-m 命令行标志。格式与配置文件中的相同:provider_id/model_id

  2. OpenCode 配置中的模型列表。

    opencode.json
    {
    "$schema": "https://opencode.ai/config.json",
    "model": "anthropic/claude-sonnet-4-20250514"
    }

    此处的格式为 provider/model

  3. 上次使用的模型。

  4. 根据内部优先级选择的第一个模型。