OpenCode
OpenCode 是开源 AI 编码智能体。 官方网站:opencode.ai
1.1 API 配置
方式一:交互式配置(推荐)
-
进入项目目录
-
启动 OpenCode
-
运行
/connect命令 -
选择提供商类型
-
选择 "Other" 或 "Custom Provider"
-
或搜索提供商名称
-
-
输入 URL 和 API Key
-
选择模型
方式二:配置文件
步骤 1:创建配置
创建或编辑 ~/.config/opencode/config.json:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"luchentech": {
"npm": "@ai-sdk/openai-compatible",
"name": "Luchentech Tech",
"options": {
"baseURL": "https://api.luchentech.com/inference/v1",
"apiKey": "{env:HPC_AI_API_KEY}"
},
"models": {
"minimax/minimax-m2.5": {
"name": "Luchentech Tech"
}
}
}
},
"model": "minimax/minimax-m2.5"
}
步骤 2:添加 API 密钥
创建或编辑 ~/.local/share/opencode/auth.json:
{
"luchentech": {
"type": "api",
"key": "sk-your-luchentech-key"
}
}
配置优先级
| 优先级 | 配置路径 | 描述 |
|---|---|---|
| 1 | OPENCODE_CONFIG 环境变量 | 自定义配置文件路径 |
| 2 | OPENCODE_CONFIG_DIR 环境变量 | 自定义配置目录 |
| 3 | <project>/opencode.json | 项目级配置 |
| 4 | ~/.config/opencode/opencode.json | 全局配置 |
方式三:环境变量
export HPC_AI_API_KEY="sk-your-luchentech-key"
export OPENAI_API_BASE="https://api.luchentech.com/inference/v1"