通过 Anthropic API 兼容接口在 OpenCode 中接入本产品。

前提条件

  • 已注册本产品
  • Node.js v18.0+
  • API Key(sk-xxxxx

配置步骤

1

安装 OpenCode

npm install -g opencode-ai
opencode --version
2

创建配置文件

编辑配置文件(macOS/Linux: ~/.config/opencode/opencode.json,Windows: C:\Users\你的用户名\.config\opencode\opencode.json):
{
    "$schema": "https://opencode.ai/config.json",
    "provider": {
        "ai-gateway": {
            "npm": "@ai-sdk/anthropic",
            "name": "AI Gateway",
            "options": {
                "baseURL": "https://coding.huaqing.online",
                "apiKey": "YOUR_API_KEY"
            },
            "models": {
                "qwen3.6-plus": {
                    "name": "Qwen3.6 Plus",
                    "modalities": { "input": ["text", "image"], "output": ["text"] },
                    "options": { "thinking": { "type": "enabled", "budgetTokens": 8192 } },
                    "limit": { "context": 1000000, "output": 65536 }
                },
                "qwen3-coder-next": {
                    "name": "Qwen3 Coder Next",
                    "modalities": { "input": ["text"], "output": ["text"] },
                    "limit": { "context": 262144, "output": 65536 }
                }
            }
        }
    }
}
Base URL 必须以 /v1 结尾。如需添加更多模型,在 models 中按相同格式添加即可。
3

验证连接

保存配置后重启 OpenCode:
opencode
输入 /models,搜索 AI Gateway,选择模型后开始使用。

常用命令

命令说明
/models查看和切换模型
/new新建对话
/compact压缩上下文