OpenCode 使用 AI SDK 和 Models.dev 来支持 75+ LLM providers,并且支持运行 local models(本地模型)。
Providers(提供商)
大多数主流 providers 默认已经预加载。如果你通过 /connect 命令添加了某个 provider 的凭证,那么在启动 OpenCode 时它们就会自动可用。
Select a model(选择模型)
当你配置好 provider 之后,可以通过输入以下命令来选择你想使用的 model:
/models
Recommended models(推荐模型)
目前市面上的 models 非常多,而且几乎每周都会有新模型发布。
不过,真正同时擅长 生成代码(code generation) 和 工具调用(tool calling) 的 models 其实并不多。
以下是一些在 OpenCode 中表现良好的 models(排名不分先后,列表也不保证完整或始终最新):
- GPT 5.2
- GPT 5.1 Codex
- Claude Opus 4.5
- Claude Sonnet 4.5
- Minimax M2.1
- Gemini 3 Pro
Set a default(设置默认模型)
如果你希望将其中一个 model 设置为默认模型,可以在 OpenCode config 中设置 model 字段:
{"$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是你在 config 中provider部分定义的 keymodel_id是provider.models中定义的 key
Configure models(配置模型)
你可以在 config 中对 model 的参数进行全局配置。
{"$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}}}}}}}
这里为两个内置 models 配置了全局参数:
- 通过
openaiprovider 访问的gpt-5 - 通过
anthropicprovider 访问的claude-sonnet-4-20250514
内置 provider 和 model 的名称可以在 Models.dev 中查询。
你也可以针对正在使用的 agents 单独配置这些参数。Agent 级别的配置会覆盖这里的全局配置。详情参考 agents 文档。
你还可以定义 custom variants(自定义变体) 来扩展内置 models。Variants 允许你在不创建重复 model 配置的情况下,为同一个 model 定义不同的参数组合。
{"$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(变体)
许多 models 都支持多个 variants,用于提供不同的配置组合。OpenCode 为主流 providers 内置了默认 variants。
Built-in variants(内置变体)
OpenCode 为多个 providers 提供了默认 variants:
Anthropic:
high- 高 thinking budget(默认)max- 最大 thinking budget
OpenAI(不同 model 略有差异,大致如下):
none- 不启用 reasoningminimal- 最小 reasoning effortlow- 低 reasoning effortmedium- 中等 reasoning efforthigh- 高 reasoning effortxhigh- 超高 reasoning effort
Google:
low- 较低 effort / token budgethigh- 较高 effort / token budget
Custom variants(自定义变体)
你可以覆盖已有 variants,或者添加自己的 variants:
{"$schema": "https://opencode.ai/config.json","provider": {"openai": {"models": {"gpt-5": {"variants": {"thinking": {"reasoningEffort": "high","textVerbosity": "low"},"fast": {"disabled": true}}}}}}}
Cycle variants(切换变体)
使用快捷键 variant_cycle 可以快速在不同 variants 之间切换。详情参考 keybinds 文档。
Loading models(模型加载顺序)
当 OpenCode 启动时,会按照以下优先级顺序加载 model:
命令行参数
--model或-m。格式与 config 中一致:provider_id/model_id。OpenCode config 中配置的 model:
{"$schema": "https://opencode.ai/config.json","model": "anthropic/claude-sonnet-4-20250514"}
这里的格式是
provider/model。上一次使用的 model。
按内部优先级排序后的第一个 model。
