OpenCode 配置 AI Code With
预计配置时间:2 分钟
OpenAI 兼容 API
支持多种 Coding 模型
按量使用
步骤 1
获取 API Key
还没有 AI Code With API Key? 注册并获取 API Key
步骤 2
选择模型
步骤 3
添加到 OpenCode
将 AI Code With 添加为 OpenAI 兼容的自定义 Provider,选择你偏好的 Key 保存方式。
通过环境变量保存 API Key,让它不进入配置文件:
bash
export AICODEWITH_API_KEY="sk-xxxxxxxx"opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["oh-my-opencode"],
"model": "aicodewith-anthropic/claude-sonnet-4-6",
"provider": {
"aicodewith-anthropic": {
"npm": "@ai-sdk/anthropic",
"name": "AICodeWith Anthropic",
"options": {
"baseURL": "https://api.aicodewith.ai/v1",
"apiKey": "{env:AICODEWITH_API_KEY}"
},
"models": {
"claude-sonnet-4-6": { "name": "Claude Sonnet 4.6" }
}
}
}
}Base URL
https://api.aicodewith.ai/v1Model ID
claude-sonnet-4-6步骤 4
将配置添加到 OpenCode
将配置放入对应平台的 OpenCode 配置文件:
~/.config/opencode/opencode.json实际路径以 OpenCode 官方最新文档为准。
步骤 5
启动并验证
重新打开终端或 IDE,运行 OpenCode(模型已在配置中指定):
bash
opencode在对话框中输入:您好!
如果能正常回复,并且在 AI Code With 平台看到调用记录,则说明配置成功。
配置完成
常见问题
准备好在 OpenCode 中使用 AI Code With 了吗?
获取 API Key 并粘贴上方配置即可开始。
获取 API Key