在 OpenCode 中接入 Agnes-2.0-Flash 模型
概述
本教程介绍如何在 OpenCode 中接入 Agnes-2.0-Flash 模型。
配置完成后,你可以在 OpenCode 中直接使用 Agnes 模型进行:
- 多轮开发对话
教程版本本教程基于 OpenCode 1.15.13 版本整理
准备工作
开始配置前,请确保已经完成以下准备工作:
- 当前网络环境可以访问 Agnes API Gateway
配置参数
| 配置项 | 值 |
|---|---|
| Provider | Agnes |
| Base URL | https://apihub.agnes-ai.com/v1 |
| Model | agnes-2.0-flash |
| API Key | 使用你在 Agnes Platform 创建的 API Key |
注意API Key 只填写密钥本身,不需要填写 Bearer
OpenCode CLI 配置
适用场景
适用于通过终端(CLI)使用 OpenCode 的用户。
如果你已经存在 OpenCode 配置文件,只需要:
- 将默认模型修改为:
"model": "agnes/agnes-2.0-flash"
配置文件示例
打开 OpenCode 配置文件,加入以下配置:
{
"$schema": "https://opencode.ai/config.json", "model": "agnes/agnes-2.0-flash",
"provider": {
"agnes": {
"npm": "@ai-sdk/openai-compatible",
"name": "Agnes",
"options": {
"baseURL": "https://apihub.agnes-ai.com/v1",
"apiKey": "{env:AGNES_API_KEY}"
},
"models": {
"agnes-2.0-flash": {
"name": "agnes-2.0-flash"
}
}
}
}
}
提示如果你已经配置了其他 Provider,请不要直接覆盖整个配置文件。只需要:在 provider 下新增 agnes将 model 修改为:agnes/agnes-2.0-flas
配置环境变量
在终端中配置 Agnes API Key:
export AGNES_API_KEY="你的 Agnes API Key"
Linux(bash)
如果希望长期生效,可写入:
echo 'export AGNES_API_KEY="你的 Agnes API Key"' >> ~/.bashrc
source ~/.bashrc
macOS(zsh)
如果使用 zsh,可写入:
echo 'export AGNES_API_KEY="你的 Agnes API Key"' >> ~/.zshrc
source ~/.zshrc
验证 CLI 配置
启动 OpenCode 后输入:
/models如果配置成功,可以看到:
Agnes
agnes-2.0-flash选择:
Agnes / agnes-2.0-flash即可开始使用 Agnes 模型。
OpenCode Desktop 配置
适用场景
适用于使用 OpenCode Desktop 图形界面的用户。
配置步骤
第一步:打开设置
启动 OpenCode Desktop。
点击左下角 设置(Settings) 按钮。
第二步:选择自定义提供商
在 Provider 列表中找到:
自定义提供商(Custom Provider)
点击右侧:
连接(Connect
第三步:填写 Provider 信息
按照下面内容填写 Agnes Provider。
Provider 配置
| 字段 | 填写内容 |
| Provider ID | agnes |
| 显示名称 | Agnes |
| Base URL | https://apihub.agnes-ai.com/v1 |
| API Key | 你的 Agnes API Key |
| Model ID | agnes-2.0-flash |
| 模型显示名称 | Agnes 2.0 Flash |
配置示例:
Provider ID:agnes显示名称:Agnes
基础 URL:https://apihub.agnes-ai.com/v1
API 密钥:sk-xxxxxxxx
模型 ID:agnes-2.0-flash
模型显示名称:Agnes 2.0 Flash
填写完成后点击:
提交(Submit
验证 Desktop 配置
返回 OpenCode Desktop 主界面。
模型列表中选择:
Agnes / agnes-2.0-flash然后发送测试消息:
你好,你是什么模型?如果模型能够正常回复,则说明配置完成。
常见问题
找不到 Agnes 模型
请依次检查以下配置:
- Provider ID 是否为:
agnes- Base URL 是否为:
https://apihub.agnes-ai.com/v1- Model ID 是否为:
agnes-2.0-flash- API Key 前是否误填写了:
Bearer
API Key 报错
请确认:
- 没有包含 Bearer
正确示例:
sk-xxxxxxxxxxxxxxxx错误示例:
Bearer sk-xxxxxxxxxxxxxxxx
请求失败或无法连接
请检查:
- 是否误填写成:
/v1/chat/completions- API Key 是否仍然有效
正确 Base URL:
https://apihub.agnes-ai.com/v1错误示例:
https://apihub.agnes-ai.com/v1/chat/completions
推荐配置
| 使用场景 | 推荐模型 |
| 日常代码生成 | agnes-2.0-flash |
| 项目分析 | agnes-2.0-flash |
| 代码修改 | agnes-2.0-flash |
| 多轮开发对话 | agnes-2.0-flash |
推荐 Base URL:
https://apihub.agnes-ai.com/v1
完整参数速查
| 参数 | 值 |
| Provider Name | Agnes |
| Provider ID | agnes |
| NPM Provider | @ai-sdk/openai-compatible |
| Base URL | https://apihub.agnes-ai.com/v1 |
| API Key 环境变量 | AGNES_API_KEY |
| Model ID | agnes-2.0-flash |
| OpenCode Model Path | agnes/agnes-2.0-flash |