> ## Documentation Index
> Fetch the complete documentation index at: https://clawdbot.openclaw-doc-zh.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# OpenAI

# OpenAI

OpenAI 为 GPT 模型提供开发者 API。Codex 支持 **ChatGPT 登录**用于订阅访问，或 **API 密钥**登录用于按量访问。Codex cloud 需要 ChatGPT 登录。

## 选项 A: OpenAI API 密钥 (OpenAI Platform)

**最适合：** 直接 API 访问和按量计费。
从 OpenAI 仪表板获取你的 API 密钥。

### CLI 设置

```bash theme={null}
openclaw onboard --auth-choice openai-api-key
# 或非交互式
openclaw onboard --openai-api-key "$OPENAI_API_KEY"
```

### 配置片段

```json5 theme={null}
{
  env: { OPENAI_API_KEY: "sk-..." },
  agents: { defaults: { model: { primary: "openai/gpt-5.2" } } },
}
```

## 选项 B: OpenAI Code (Codex) 订阅

**最适合：** 使用 ChatGPT/Codex 订阅访问而非 API 密钥。
Codex cloud 需要 ChatGPT 登录，而 Codex CLI 支持 ChatGPT 或 API 密钥登录。

### CLI 设置

```bash theme={null}
# 在向导中运行 Codex OAuth
openclaw onboard --auth-choice openai-codex

# 或直接运行 OAuth
openclaw models auth login --provider openai-codex
```

### 配置片段

```json5 theme={null}
{
  agents: { defaults: { model: { primary: "openai-codex/gpt-5.2" } } },
}
```

## 注意事项

* 模型引用始终使用 `provider/model` 格式（参见 [/concepts/models](/docs/concepts/models)）。
* 认证详情 + 重用规则参见 [/concepts/oauth](/docs/concepts/oauth)。
