~/content/models

Models

Configuring an LLM provider and model.

last_updated: "2026-01-20"

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


##Providers

大多数流行的 providers 默认情况下已预加载。 如果您已通过 /connect 命令添加了 provider 的凭据,则在启动 OpenCode 时它们将可用。

了解更多关于 providers 的信息。


##选择模型

配置好您的 provider 后,您可以通过输入以下内容来选择您想要的模型:

bash
/models

##推荐模型

现在有很多模型,而且每周都有新模型出现。

Note

💡 提示

考虑使用我们推荐的模型之一。

然而,只有少数模型擅长生成代码和工具调用。

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

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

##设置默认值

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

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

这里的完整 ID 是 provider_id/model_id。 例如,如果您正在使用 OpenCode Zen,您将为 GPT 5.1 Codex 使用 opencode/gpt-5.1-codex

如果您配置了 custom provider,则 provider_id 是配置文件的 provider 部分中的键,而 model_idprovider.models 中的键。


##配置模型

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

bash
{
  "$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 provider 访问的 gpt-5,以及通过 anthropic provider 访问的 claude-sonnet-4-20250514。 内置 provider 和模型名称可以在 Models.dev 上找到。

您还可以为正在使用的任何 agents 配置这些选项。 agent 配置会覆盖此处的任何全局选项。了解更多

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

bash
{
  "$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",
            },
          },
        },
      },
    },
  },
}

##Variants

许多模型支持具有不同配置的多个 variants。 OpenCode 附带了流行的 providers 的内置默认 variants。

###内置 variants

OpenCode 附带了许多 providers 的默认 variants:

Anthropic:

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

OpenAI:

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

  • none - 无推理
  • minimal - 最小推理工作量
  • low - 低推理工作量
  • medium - 中等推理工作量
  • high - 高推理工作量
  • xhigh - 额外高推理工作量

Google:

  • low - 较低的工作量/token 预算
  • high - 较高的工作量/token 预算
Note

💡 提示

此列表并不全面。 许多其他 providers 也有内置的默认值。

###自定义 variants

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

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

###循环 variants

使用快捷键 variant_cycle 快速切换 variants。了解更多


##加载模型

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

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

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

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

    此处的格式为 provider/model

  3. 上次使用的模型。

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

Comments (Coming Soon)

Configure Giscus in environment variables to enable comments.