基于 OpenCode 最新版本,使用 智创聚合 API( https://n.lconai.com)作为统一中转站,支持 Claude、Gemini、GPT、GLM 等主流模型。
https://n.lconai.com执行 opencode onboard后,会在用户目录生成.opencode或.config/opencode配置文件夹。
安全提示:所有 API Key 均从智创聚合 API 官网( https://n.lconai.com)获取,一个 Key 可通用于所有模型。
opencode.json| 平台 | 路径 |
|---|---|
| Windows | C:\Users\<用户名>\.config\opencode\opencode.json 或 ~/.opencode/opencode.json |
| macOS/Linux | ~/.config/opencode/opencode.json 或 ~/.opencode/opencode.json |
| 项目级 | ./opencode.json(优先级最高) |
{
"$schema": "https://opencode.ai/config.json",
"disabled_providers": [
"test2",
"test1"
],
"provider": {
"anthropic": {
"name": "Anthropic Claude",
"npm": "@ai-sdk/anthropic",
"models": {
"claude-opus-4-6": {
"name": "Claude Opus 4.6",
"limit": {
"context": 200000,
"output": 8192
}
},
"claude-sonnet-4-5-20250929": {
"name": "Claude Sonnet 4.5",
"limit": {
"context": 200000,
"output": 8192
}
}
},
"options": {
"baseURL": "https://n.lconai.com/v1",
"apiKey": "{env:ANTHROPIC_API_KEY}",
"timeout": 600000
}
},
"google": {
"name": "Google Gemini",
"npm": "@ai-sdk/google",
"models": {
"gemini-3.1-pro-preview": {
"name": "Gemini 3.1 Pro Preview",
"limit": {
"context": 2000000,
"output": 8192
}
},
"gemini-3-flash": {
"name": "Gemini 3 Flash",
"limit": {
"context": 1000000,
"output": 8192
}
}
},
"options": {
"baseURL": "https://n.lconai.com/v1beta",
"apiKey": "{env:GOOGLE_API_KEY}"
}
},
"openai": {
"name": "OpenAI Compatible",
"npm": "@ai-sdk/openai-compatible",
"models": {
"gpt-5.4": {
"name": "GPT-5.4",
"limit": {
"context": 128000,
"output": 8192
}
},
"gpt-5.3-codex": {
"name": "GPT-5.3 Codex",
"limit": {
"context": 128000,
"output": 8192
}
},
"glm-5": {
"name": "GLM-5",
"limit": {
"context": 128000,
"output": 8192
}
}
},
"options": {
"baseURL": "https://n.lconai.com/v1",
"apiKey": "{env:OPENAI_API_KEY}"
}
}
}
}| Provider | SDK 包 | baseURL 格式 | 路径后缀说明 |
|---|---|---|---|
| Anthropic/Claude | @ai-sdk/anthropic | https://n.lconai.com | 根域名,加 /v1 |
| Google/Gemini | @ai-sdk/google | https://n.lconai.com/v1beta | Gemini 官方 API 路径为 /v1beta |
| OpenAI 兼容 | @ai-sdk/openai-compatible | https://n.lconai.com/v1 | OpenAI 标准路径,必须加 /v1 |
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
npm | string | 是 | AI SDK 包名,决定 API 协议格式 |
name | string | 是 | Provider 显示名称 |
baseURL | string | 是 | 中转站基础地址 |
apiKey | string | 否 | {env:VAR_NAME} 替换智创聚合API平台令牌 |
timeout | number | 否 | 请求超时时间(毫秒),建议 600000(10分钟) |
limit.context | number | 否 | 上下文窗口大小(token) |
limit.output | number | 否 | 单次最大输出 token 数 |
provider/model-id。{
"provider": {
"deepseek": {
"name": "DeepSeek",
"npm": "@ai-sdk/openai-compatible",
"models": {
"deepseek-v3.2": {
"name": "DeepSeek V3.2",
"limit": {
"context": 2000000,
"output": 8192
}
}
},
"options": {
"baseURL": "https://n.lconai.com/v1",
"apiKey": "{env:DEEPSEEK_API_KEY}"
}
}
}
}{
"provider": {
"anthropic": {
"models": {
"claude-opus-4-6": {
"name": "Claude Opus 4.6",
"options": {
"thinking": {
"type": "enabled",
"budgetTokens": 16000
}
}
}
}
}
}
}{
"options": {
"baseURL": "https://n.lconai.com/v1",
"headers": {
"X-Custom-Header": "value"
}
}
}| 问题现象 | 可能原因 | 解决方案 |
|---|---|---|
Connection timeout | 网络不通或代理地址错误 | ping n.lconai.com 确认网络,检查 baseURL 路径后缀 |
401 Unauthorized | API Key 无效 | 检查 auth.json 或环境变量中的 Key 是否正确 |
404 Not Found | 路径后缀错误 | Claude 不加 /v1,OpenAI 兼容必须加 /v1 |
Model not found | 模型 ID 与中转站不匹配 | 确认模型 ID 与智创聚合 API 提供的完全一致 |
--log-level debug 查看详细请求日志:./opencode.jsonANTHROPIC_API_KEY 等~/.config/opencode/opencode.jsonhttps://n.lconai.com,通过不同 SDK 包区分协议格式@ai-sdk/anthropic): /v1@ai-sdk/google): /v1beta@ai-sdk/openai-compatible): /v1{env:VAR_NAME} 语法,避免在配置文件中硬编码 API Keynpm 字段支持任何 AI SDK 兼容的 Provider,轻松添加新模型