1. 配置文件结构
~/.config/opencode/opencode.json 示意:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["oh-my-opencode@3.1.2"],
"mcp": {
"feishu-mcp": {
"type": "remote",
"url": "https://www.feishu.com"
}
},
"provider": {
"Mify-OpenAI": {
"npm": "@ai-sdk/openai",
"options": {
"baseURL": "http://www.baidu.com",
"apiKey": "sk-..."
},
"models": {
"azure_openai/gpt-5.1-codex": {
"name": "GPT-5.1 Codex",
"attachment": true,
"reasoning": true,
"modalities": {
"input": ["text", "image"],
"output": ["text"]
},
"limit": {
"context": 1000000,
"output": 128000
}
}
}
}
}
}
2. 核心能力配置
| 配置项 | 作用 | 说明 |
|---|---|---|
modalities.input | 声明模型支持的输入类型 | 可选值:text / audio / image / video / pdf;需要手动声明,否则视为不支持 |
modalities.output | 声明模型输出类型 | 同上 |
attachment | 是否允许文件上传 | true 时可在对话中附加文件,常与 modalities 联动 |
reasoning | 推理模式 | true 时启用“思考过程”显示 |
limit.context / limit.output | Token 限制 | 设定最大上下文与输出长度 |
options.* | SDK 接入参数 | 例如 baseURL、apiKey、自定义 headers、timeout 等 |
只有配置了
modalities.input包含image的模型才能接收图片输入;没有就会提示 “this model does not support image input”。
3. 常见场景示例
3.1 启用图片/多模态
"modalities": {
"input": ["text", "image"],
"output": ["text"]
},
"attachment": true
3.2 开启推理
"reasoning": true
3.3 设置 Token 限制
"limit": {
"context": 1000000,
"output": 128000
}
4. 其他可配选项速览
plugin: 安装的插件列表mcp: MCP(如飞书)远程/本地服务描述provider: 多个模型供应商配置(含npm包名、默认options、模型清单)workspace: 针对特定目录的覆写配置env: 全局环境变量instructions: 额外的规则/指令文件tools: 控制可用工具(如禁用bash、write等)tui: 终端 UI 参数(滚动、diff 样式等)
5. 使用建议
- 逐级合并:Remote → Global → Custom → Project,后者可覆盖前者。
- 谨慎暴露密钥:推荐配合
{file:~/.secrets/...}引用。 - 明确定义模态:缺省值即“不支持”,尤其图像、音频等必须显式声明。
- 模型专能化:同一 provider 下可配置多个 model entry,每个 entry 单独定义能力。
4737

被折叠的 条评论
为什么被折叠?



