跳到主要内容

OpenCode

OpenCode 是开源 AI 编码智能体。 官方网站:opencode.ai

1.1 API 配置

方式一:交互式配置(推荐)

  1. 进入项目目录

  2. 启动 OpenCode

  3. 运行 /connect 命令

  4. 选择提供商类型

    • 选择 "Other""Custom Provider"

    • 或搜索提供商名称

  5. 输入 URL 和 API Key

  6. 选择模型

方式二:配置文件

步骤 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"
}
}

配置优先级

优先级配置路径描述
1OPENCODE_CONFIG 环境变量自定义配置文件路径
2OPENCODE_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"

1.2 参考