opencode中如何配置GLM5 模型,claude-sonnet 示例如下 "B4U": { ...
Created on: February 22, 2026
Answered using GPT-5.2 Thinking by Chat01
Created on: February 22, 2026
Answered using GPT-5.2 Thinking by Chat01
opencode中如何配置GLM5 模型,claude-sonnet 示例如下
"B4U": {
"npm": "@ai-sdk/openai-compatible",
"name": "B4U",
"options": {
"baseURL": "https://b4u.qzz.io/v1",
"apiKey": "KEY"
},
"models": {
"claude-4.5-sonnet": {
"name": "claude-4.5-sonnet",
"limit": {
"context": 200000,
"output": 64000
},
"modalities": {
"input": [
"text",
"image"
],
"output": [
"text"
]
},
"options": {
"thinking": {
"type": "enabled",
"budgetTokens": 32000
}
}
}
}
}
下面给你两种在 OpenCode 里配置 GLM-5 的方式(都按你贴的 provider -> models 结构来写),你直接把对应段落合并进 ~/.config/opencode/opencode.json 即可。OpenCode 里最终选择模型用的是 provider_id/model_id(比如 zhipu/glm-5)。 (OpenCode)
@ai-sdk/openai-compatible 直连智谱 OpenAI 兼容接口(最像你现有配置)GLM-5:文本输入/文本输出,上下文 200K,最大输出 128K。 (BigModel Documentation)
智谱 OpenAI 兼容接口的 baseURL 形如https://open.bigmodel.cn/api/paas/v4(注意不是/v1)。 (BigModel Documentation)
OpenCode 自定义 provider 支持options.baseURL / options.apiKey / models这种写法。 (OpenCode)
jsonc{ "$schema": "https://opencode.ai/config.json", "provider": { "zhipu": { "npm": "@ai-sdk/openai-compatible", "name": "ZhipuAI", "options": { "baseURL": "https://open.bigmodel.cn/api/paas/v4", "apiKey": "{env:ZAI_API_KEY}" }, "models": { "glm-5": { "name": "glm-5", "limit": { "context": 200000, "output": 128000 }, "modalities": { "input": ["text"], "output": ["text"] } } } } }, // 默认模型(可选) "model": "zhipu/glm-5" }
可选:用 Z.ai(海外)基础设施
把 baseURL 改成:
jsonc"baseURL": "https://api.z.ai/api/paas/v4"
zhipu-ai-provider(更适配 GLM 系列特性)这个包是 AI SDK 的 Zhipu 社区 provider,默认 baseURL 就是 https://open.bigmodel.cn/api/paas/v4,也支持切到 z.ai。 (AI SDK)
jsonc{ "$schema": "https://opencode.ai/config.json", "provider": { "zhipu": { "npm": "zhipu-ai-provider", "name": "ZhipuAI", "options": { "apiKey": "{env:ZAI_API_KEY}", "baseURL": "https://open.bigmodel.cn/api/paas/v4" }, "models": { "glm-5": { "name": "glm-5", "limit": { "context": 200000, "output": 128000 }, "modalities": { "input": ["text"], "output": ["text"] } } } } }, "model": "zhipu/glm-5" }
GLM-5 / GLM-4.7 默认开启 Thinking;如果你要关,可以在请求里传 thinking: { type: "disabled" }。 (BigModel Documentation)
但 OpenCode 配置是否能把非标准字段(如 thinking/clear_thinking)透传到 OpenAI-compatible 请求体,取决于你用的 provider/网关实现;如果你需要精确控制这些字段,更稳的是走 方案 B(zhipu-ai-provider) 或你自己的代理层来做透传。(GitHub)
如果你现在的 GLM-5 其实是挂在你这类聚合网关(像你示例的 https://b4u.qzz.io/v1)下面,只要把上面 models.glm-5 那段直接加到同一个 provider 的 models 里即可;关键是把 limit/context/output 和 modalities 按 GLM-5 的规格写对(200K/128K、text-only)。 (BigModel Documentation)