OpenAI
OpenAI 是 GPT 系列模型的开发者,提供业界领先的大语言模型 API。OpenClaw 支持通过 API Key 或 Codex OAuth 两种方式接入 OpenAI。
认证方式
方式一:API Key(推荐)
- 前往 OpenAI Platform 创建 API Key
- 在 OpenClaw 中配置:
bash
openclaw models auth login --provider openai
# 按提示输入 API Key方式二:Codex OAuth
如果你已安装 OpenAI Codex CLI,可以复用其 OAuth 凭证:
bash
openclaw models auth login --provider openai-codex --set-default配置示例
jsonc
// ~/.openclaw/config.json
{
"models": {
"providers": {
"openai": {
"apiKey": "sk-xxxxxxxxxxxxxxxxxxxxxxxx",
// 可选:自定义 API 地址(用于代理或中转服务)
"baseUrl": "https://api.openai.com/v1"
}
}
}
}支持的模型
| 模型 ID | 说明 | 上下文窗口 |
|---|---|---|
gpt-4o | 最新旗舰多模态模型 | 128K |
gpt-4o-mini | 轻量快速版本,适合日常任务 | 128K |
o1 | 推理增强模型 | 200K |
o1-mini | 轻量推理模型 | 128K |
o1-pro | 专业推理模型(需 Pro 订阅) | 200K |
gpt-4-turbo | GPT-4 Turbo 版本 | 128K |
gpt-4 | 经典 GPT-4 | 8K |
gpt-3.5-turbo | 经济实惠,适合简单任务 | 16K |
使用示例:
bash
# 设置为默认模型
openclaw models default set openai/gpt-4o
# 临时使用特定模型
openclaw chat --model openai/o1 "请逐步分析这个算法的时间复杂度"环境变量
bash
# API Key
export OPENAI_API_KEY="sk-xxxxxxxxxxxxxxxxxxxxxxxx"
# 可选:自定义 API 地址
export OPENAI_BASE_URL="https://api.openai.com/v1"故障排查
API Key 无效
- 确认 API Key 以
sk-开头 - 检查 API Key 是否已过期或被撤销
- 确认账户中有足够的额度(credit)
请求超时
- 检查网络连接是否正常
- 如果在中国大陆,请配置代理(见下方中国用户须知)
- 尝试使用更小的模型(如
gpt-4o-mini)
速率限制(Rate Limit)
- 新账号默认速率较低,可在 OpenAI 后台申请提额
- 使用
gpt-4o-mini可获得更高的速率限制 - 考虑使用 OpenRouter 作为备用路由
🇨🇳 中国用户须知
- 网络代理:中国大陆无法直接访问 OpenAI API,需要配置 HTTP 代理或使用中转服务
- 代理配置方法:bash
# 设置代理 export HTTPS_PROXY="http://127.0.0.1:7890" export HTTP_PROXY="http://127.0.0.1:7890" - 中转服务:也可使用第三方 API 中转服务,修改
baseUrl指向中转地址jsonc{ "models": { "providers": { "openai": { "apiKey": "sk-xxxxxxxx", "baseUrl": "https://your-proxy-service.com/v1" } } } } - 替代方案:如无代理条件,建议使用 DeepSeek(兼容 OpenAI API 格式)或 通义千问 作为替代
