中文
文档
模型

模型

配置 LLM 提供商和模型。

OpenCode 使用 AI SDK (opens in a new tab)Models.dev (opens in a new tab) 支持 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 (opens in a new tab) 上找到。

你也可以为使用的任何代理配置这些选项。代理配置会覆盖这里的全局选项。了解更多

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

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 - 较低的力度/token 预算
  • high - 较高的力度/token 预算

提示:此列表并不全面。许多其他提供商也有内置默认值。

自定义变体

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

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. 使用内部优先级的第一个模型。