跳转到内容

模型 Models

配置 LLM 提供商和模型。

OpenCode 使用 AI SDK 和 Models.dev 支持 75+ LLM 提供商,并支持运行本地模型。


提供商 Providers

大多数流行的提供商默认已预加载。如果你已通过 /connect 命令添加了提供商的凭据,它们将在你启动 OpenCode 时可用。

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


选择模型 Select a model

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

/models

市面上有大量模型,每周都有新模型推出。

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

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

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

设置默认值 Set a default

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

opencode.json
{
"$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。

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


配置模型 Configure 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",
},
},
},
},
},
},
}

变体 Variants

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

内置变体 Built-in variants

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

Anthropic:

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

OpenAI:

因模型而异,但大致为:

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

Google:

  • low - 较低的努力/代币预算
  • high - 较高的努力/代币预算

自定义变体 Custom variants

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

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

循环切换变体 Cycle variants

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


加载模型 Loading models

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