跳至内容

模型

配置大语言模型(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.ac.cn/config.json",
"model": "lmstudio/google/gemma-3n-e4b"
}

完整的 ID 格式是 provider_id/model_id。例如,如果您使用 OpenCode Zen,对于 GPT 5.1 Codex,您将使用 opencode/gpt-5.1-codex

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


配置模型

您可以通过配置全局设置模型的选项。

opencode.jsonc
{
"$schema": "https://opencode.ac.cn/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.ac.cn/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.ac.cn/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.ac.cn/config.json",
    "model": "anthropic/claude-sonnet-4-20250514"
    }

    这里的格式是 provider/model

  3. 上次使用的模型。

  4. 第一个使用内部优先级的模型。