一键配置 OpenCode 使用 DMXAPI 服务
| 平台 | 要求 |
|---|---|
| Windows | Windows 10 x64 及以上 |
| macOS | macOS 11 (Big Sur) 及以上,支持 Intel 与 Apple Silicon |
| Linux | glibc 2.17+,支持 x64 与 ARM64 |
注意:macOS 用户首次运行未签名二进制需执行
xattr -dr com.apple.quarantine <文件名>移除 Gatekeeper 隔离属性。
| 平台 | 文件名 | 架构 |
|---|---|---|
| Windows | opencode-dmxapi-<版本>-windows-amd64.exe | x64 |
| macOS (Intel) | opencode-dmxapi-<版本>-macos-amd64 | x64 |
| macOS (Apple Silicon) | opencode-dmxapi-<版本>-macos-arm64 | ARM64 |
| Linux (x64) | opencode-dmxapi-<版本>-linux-amd64 | x64 |
| Linux (ARM64) | opencode-dmxapi-<版本>-linux-arm64 | ARM64 |
# 下载后直接运行 .\opencode-dmxapi-<版本>-windows-amd64.exe
chmod +x opencode-dmxapi-<版本>-macos-amd64
# 移除 Gatekeeper 隔离属性(首次运行需要)
xattr -dr com.apple.quarantine opencode-dmxapi-<版本>-macos-amd64
./opencode-dmxapi-<版本>-macos-amd64
chmod +x opencode-dmxapi-<版本>-macos-arm64
# 移除 Gatekeeper 隔离属性(首次运行需要)
xattr -dr com.apple.quarantine opencode-dmxapi-<版本>-macos-arm64
./opencode-dmxapi-<版本>-macos-arm64
chmod +x opencode-dmxapi-<版本>-linux-amd64
./opencode-dmxapi-<版本>-linux-amd64
# ARM64 用户将 amd64 替换为 arm64
运行后按提示操作:
opencode 启动程序当检测到现有配置时,程序提供两种模式:
| 模式 | 说明 | 适用场景 |
|---|---|---|
| 完整配置 | 重新配置 URL、API Key 和模型 | 首次配置或需要更换账号 |
| 仅模型配置 | 保留现有 URL 和 API Key,只更新模型 | 快速切换或添加模型 |
程序根据模型名称前缀自动路由到最优 SDK:
| 模型前缀 | Provider | SDK | 示例 |
|---|---|---|---|
claude* | dmxapi-anthropic | @ai-sdk/anthropic | claude-opus-4-5-20251101, claude-sonnet-4-20250514 |
gemini* | dmxapi-google | @ai-sdk/google | gemini-2.5-pro, gemini-2.5-flash |
gpt-5* | dmxapi-openai-responses | @ai-sdk/openai | gpt-5, gpt-5.2, gpt-5-mini, gpt-5-turbo |
| 其他 | dmxapi-openai | @ai-sdk/openai-compatible | DeepSeek-V3, gpt-4o, o1 |
示例: 配置 claude-opus-4-5-20251101,gemini-2.5-pro,DeepSeek-V3 将自动创建 3 个 Provider。
| 文件 | Windows | macOS/Linux |
|---|---|---|
| opencode.json | C:\Users\<用户>\.config\opencode\opencode.json | ~/.config/opencode/opencode.json |
| auth.json | C:\Users\<用户>\.local\share\opencode\auth.json | ~/.local/share/opencode/auth.json |
多 Provider 配置格式(自动生成):
{
"provider": {
"dmxapi-anthropic": {
"npm": "@ai-sdk/anthropic",
"name": "DMXAPI Claude",
"options": {
"baseURL": "https://www.dmxapi.cn/v1",
"apiKey": "sk-xxx"
},
"models": {
"claude-opus-4-5-20251101": { "name": "claude-opus-4-5-20251101" }
}
},
"dmxapi-google": {
"npm": "@ai-sdk/google",
"name": "DMXAPI Gemini",
"options": {
"baseURL": "https://www.dmxapi.cn/v1",
"apiKey": "sk-xxx"
},
"models": {
"gemini-2.5-pro": { "name": "gemini-2.5-pro" }
}
},
"dmxapi-openai": {
"npm": "@ai-sdk/openai-compatible",
"name": "DMXAPI OpenAI",
"options": {
"baseURL": "https://www.dmxapi.cn/v1",
"apiKey": "sk-xxx"
},
"models": {
"DeepSeek-V3": { "name": "DeepSeek-V3" }
}
}
}
}
{
"dmxapi-anthropic": {
"type": "api",
"key": "sk-xxx"
},
"dmxapi-google": {
"type": "api",
"key": "sk-xxx"
},
"dmxapi-openai": {
"type": "api",
"key": "sk-xxx"
}
}
# 克隆项目
git clone https://cnb.cool/dmxapi/opencode_dmxapi.git
cd opencode_dmxapi
# 构建当前平台
go build -o dmxapi-config .
# 跨平台构建
# Windows
GOOS=windows GOARCH=amd64 go build -o dmxapi-config-windows.exe .
# macOS Intel
GOOS=darwin GOARCH=amd64 go build -o dmxapi-config-macos-amd64 .
# macOS Apple Silicon
GOOS=darwin GOARCH=arm64 go build -o dmxapi-config-macos-arm64 .
# Linux
GOOS=linux GOARCH=amd64 go build -o dmxapi-config-linux .
macOS Gatekeeper 会阻止运行未经 Apple 公证的二进制文件。解决方法:
# 方法一:命令行移除隔离属性(推荐)
xattr -dr com.apple.quarantine opencode-dmxapi-<版本>-macos-arm64
# 方法二:系统设置手动允许
# 前往"系统设置 > 隐私与安全性",找到被阻止的程序,点击"仍要打开"
sk- 开头,从 https://www.dmxapi.cn/token 获取| 文件 | Windows | macOS / Linux |
|---|---|---|
opencode.json | C:\Users\<用户>\.config\opencode\opencode.json | ~/.config/opencode/opencode.json |
auth.json | C:\Users\<用户>\.local\share\opencode\auth.json | ~/.local/share/opencode/auth.json |
备份文件保存在同目录下,后缀为 .bak.<时间戳>。
| 资源 | 链接 |
|---|---|
| DMXAPI 官网 | https://www.dmxapi.cn |
| 获取 API Key | https://www.dmxapi.cn/token |
| 可用模型列表 | https://www.dmxapi.cn/rmb |
| OpenCode 文档 | https://opencode.ai |