编程 Agent
OpenCode 接入思畅
已实测:2026-10-14 · OpenCode 1.18.4
配置
在项目根目录(或全局配置目录)的 opencode.json 里加一个服务商:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"sichang": {
"npm": "@ai-sdk/openai-compatible",
"name": "思畅 AI",
"options": {
"baseURL": "https://sichang.xyz/api/v1",
"apiKey": "{env:SICHANG_API_KEY}"
},
"models": {
"<模型 id>": {
"name": "<模型名>",
"tool_call": true,
"limit": { "context": <上下文长度>, "output": 32000 }
}
}
}
}
}然后把 Key 放进环境变量再启动:
export SICHANG_API_KEY=<你的 API Key>
opencode在 OpenCode 里用 /models 选「思畅 AI」下的模型,或启动时指定 opencode -m sichang/<模型 id>。
选模型
models里的键必须是思畅的模型 id,大小写、斜杠都要一致。可以同时写多个。- 编程要选支持工具调用的模型,当前有
gemma-4-uncensored、deepseek-v4-1-flash、olafangensan-glm-4.7-flash-heretic、z-ai/glm-5.3-uncensored,并设"tool_call": true。 limit.context填该模型的上下文长度(见对话模型),OpenCode 据此决定何时压缩上下文。
验证
opencode run -m sichang/<模型 id> "创建 hello.py,打印「你好」,然后用 python3 运行它并告诉我输出。"实测用 deepseek-v4-1-flash 完成「写文件 + 运行」共 3 轮,扣 2 积分。
OpenCode 会用同一个模型给会话起标题,这也是一次请求、按同样单价计费。