配置 OpenCode
本章节将指导您如何配置 OpenCode 连接 AwesomeAPI 服务。
获取 API Key
- 访问 AwesomeAPI 并登录账号
- 进入个人中心或 API 管理页面
- 创建新的 API Key 并复制保存
Warning: 请妥善保管您的 API Key,不要泄露给他人或提交到公开仓库。
配置文件
OpenCode 使用 JSON 格式的配置文件。配置文件位置:
| 系统 | 配置文件路径 |
|---|---|
| Windows | %USERPROFILE%\.config\opencode\opencode.json |
| Linux | ~/.config/opencode/opencode.json |
| macOS | ~/.config/opencode/opencode.json |
也可以在项目根目录创建 opencode.json 文件,作为项目级配置。
配置 AwesomeAPI
方法一:配置文件(推荐)
创建或编辑配置文件 opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"anthropic": {
"name": "Awesome Claude",
"models": {
"claude-sonnet-4-5": {
"name": "Claude Sonnet 4.5 (Awesome API)",
"limit": { "context": 200000, "output": 64000 }
},
"claude-opus-4-6": {
"name": "Claude Opus 4.6 (Awesome API)",
"limit": { "context": 200000, "output": 64000 },
"reasoning": true
}
},
"options": {
"baseURL": "http://8.130.53.188:3000/v1",
"apiKey": "sk-your-api-key"
}
},
"openai": {
"name": "Awesome Openai",
"models": {
"gpt-5.2": {
"name": "GPT 5.2 (Awesome API)",
"limit": { "context": 200000, "output": 128000 },
"reasoning": true
}
},
"options": {
"baseURL": "http://8.130.53.188:3000/v1",
"apiKey": "sk-your-api-key"
}
}
}
}
方法二:环境变量配置
如果你只使用 provider.anthropic,可以用环境变量快速配置(不同 OpenCode 版本/平台支持可能略有差异,优先以配置文件为准):
Windows PowerShell:
$env:ANTHROPIC_API_KEY = "your-api-key"
$env:ANTHROPIC_BASE_URL = "http://8.130.53.188:3000/v1"
Windows CMD:
set ANTHROPIC_API_KEY=your-api-key
set ANTHROPIC_BASE_URL=http://8.130.53.188:3000/v1
Linux / macOS:
export ANTHROPIC_API_KEY="your-api-key"
export ANTHROPIC_BASE_URL="http://8.130.53.188:3000/v1"
如果你使用 provider.openai,可参考设置:
export OPENAI_API_KEY="your-api-key"
export OPENAI_BASE_URL="http://8.130.53.188:3000/v1"
方法三:永久环境变量配置
Windows PowerShell(写入 Profile):
# 打开 PowerShell Profile 文件
notepad $PROFILE
# 添加以下内容后保存
$env:ANTHROPIC_API_KEY = "your-api-key"
$env:ANTHROPIC_BASE_URL = "http://8.130.53.188:3000/v1"
Linux / macOS(写入 .bashrc 或 .zshrc):
# 编辑配置文件
nano ~/.bashrc # 或 ~/.zshrc
# 添加以下内容
export ANTHROPIC_API_KEY="your-api-key"
export ANTHROPIC_BASE_URL="http://8.130.53.188:3000/v1"
# 使配置生效
source ~/.bashrc # 或 source ~/.zshrc
完整配置示例
以下是供参考的的完整配置,可直接复制使用:
{
"$schema": "https://opencode.ai/config.json",
"provider": {
"anthropic": {
"name": "Awesome Claude",
"models": {
"claude-sonnet-4-5": {
"name": "Claude Sonnet 4.5 (Awesome API)",
"limit": { "context": 200000, "output": 64000 }
},
"claude-sonnet-4-6": {
"name": "Claude Sonnet 4.6 (Awesome API)",
"limit": { "context": 200000, "output": 64000 },
"reasoning": true
},
"claude-opus-4-6": {
"name": "Claude Opus 4.6 (Awesome API)",
"limit": { "context": 200000, "output": 64000 },
"reasoning": true
}
},
"options": {
"baseURL": "http://8.130.53.188:3000/v1",
"apiKey": "sk-your-api-key"
}
},
"openai": {
"name": "Awesome Openai",
"models": {
"gpt-5.2": {
"name": "GPT 5.2 (Awesome API)",
"limit": { "context": 200000, "output": 128000 },
"reasoning": true
},
"gpt-5.2(medium)": {
"name": "GPT 5.2 medium (Awesome API)",
"limit": { "context": 200000, "output": 128000 },
"reasoning": true
},
"gpt-5.2(high)": {
"name": "GPT 5.2 high (Awesome API)",
"limit": { "context": 200000, "output": 128000 },
"reasoning": true
},
"gpt-5.2(xhigh)": {
"name": "GPT 5.2 extra high (Awesome API)",
"limit": { "context": 200000, "output": 128000 },
"reasoning": true
},
"gpt-5.3-codex": {
"name": "GPT 5.3 codex (Awesome API)",
"limit": { "context": 400000, "output": 128000 },
"reasoning": true
},
"gpt-5.3-codex(medium)": {
"name": "GPT 5.3 codex medium (Awesome API)",
"limit": { "context": 400000, "output": 128000 },
"reasoning": true
},
"gpt-5.3-codex(high)": {
"name": "GPT 5.3 codex high (Awesome API)",
"limit": { "context": 400000, "output": 128000 },
"reasoning": true
},
"gpt-5.3-codex(xhigh)": {
"name": "GPT 5.3 codex extra high (Awesome API)",
"limit": { "context": 400000, "output": 128000 },
"reasoning": true
}
},
"options": {
"baseURL": "http://8.130.53.188:3000/v1",
"apiKey": "sk-your-api-key"
}
}
}
}
验证配置
配置完成后,运行以下命令验证:
opencode
进入交互界面后,输入"你好"测试是否能正常收到回复。
配置选项说明
环境变量
| 环境变量 | 描述 | 示例值 |
|---|---|---|
ANTHROPIC_API_KEY |
API 认证密钥 | sk-xxx... |
ANTHROPIC_BASE_URL |
API 服务端点地址 | http://8.130.53.188:3000/v1 |
OPENAI_API_KEY |
API 认证密钥 | sk-xxx... |
OPENAI_BASE_URL |
API 服务端点地址 | http://8.130.53.188:3000/v1 |
配置文件选项
| 配置项 | 描述 | 示例值 |
|---|---|---|
$schema |
配置文件 Schema | https://opencode.ai/config.json |
provider.anthropic.name |
提供者显示名称 | Awesome Claude |
provider.anthropic.options.baseURL |
API 服务端点地址 | http://8.130.53.188:3000/v1 |
provider.openai.name |
提供者显示名称 | Awesome Openai |
provider.openai.options.baseURL |
API 服务端点地址 | http://8.130.53.188:3000/v1 |
models.<model>.name |
模型显示名称 | GPT 5.2 (Awesome API) |
models.<model>.limit.context |
上下文 token 限制 | 200000 |
models.<model>.limit.output |
输出 token 限制 | 64000 |
models.<model>.reasoning |
是否支持推理模式 | true |
可用模型
请到 AwesomeAPI 模型广场 查看最新可用模型列表。
Tip: 推荐使用
claude-opus-4-6或gpt-5.2,两者都支持推理模式(reasoning: true)。Tip: 如需使用 GPT 系列模型,请在
provider.openai.models中添加对应 Model ID(例如gpt-5.2、gpt-5.3-codex)。
常见问题
连接超时
如果遇到连接超时,请检查:
- 网络是否正常
- API 地址是否正确(注意结尾的
/v1) - 防火墙是否阻止了连接
API Key 无效
如果提示 API Key 无效:
- 确认 Key 是否正确复制(无多余空格)
- 确认账户是否有足够额度
- 尝试重新生成 API Key
配置文件未生效
- 检查配置文件路径是否正确
- 检查 JSON 语法是否正确(可使用在线 JSON 校验工具)
- 项目级配置优先于全局配置
模型不可用
如果提示模型不可用:
- 确认模型名称拼写正确
- 确认账户有权限访问该模型
- 检查
models配置中是否包含该模型