Skip to content

OpenCode

添加 OpenAI 兼容供应商并选择模型。

This content is not available in your language yet.

先安装 OpenCode 并创建 API Key。

将 sk-your-api-key 替换为你的密钥:

终端窗口
export ROIBEST_API_KEY="sk-your-api-key"

在项目根目录的 opencode.json 中合并以下配置,将所有 your-model 替换为同一个可用模型 ID:

{
"$schema": "https://opencode.ai/config.json",
"model": "roibest/your-model",
"provider": {
"roibest": {
"npm": "@ai-sdk/openai-compatible",
"name": "ROIBest AI",
"options": {
"baseURL": "https://ai-new.roibest.com/v1",
"apiKey": "{env:ROIBEST_API_KEY}"
},
"models": {
"your-model": {
"name": "your-model"
}
}
}
}
}

{env:ROIBEST_API_KEY} 从环境变量读取密钥,无需改写。添加其他模型时,在 models 中增加对应条目。

在同一终端的项目目录中运行:

终端窗口
opencode run "Hello"

收到回复后,在使用日志确认本次请求。

ROIBest AI 文档