Codex 快速开始|ApiPorter
在 macOS、Linux 或 Windows 上将 Codex CLI 接入 ApiPorter,并验证第一条编程请求。
这篇文档只解决一件事:让 Codex 通过 ApiPorter 成功发送第一条请求。想尽快完成可以选择方式 A;希望自己检查配置时,请按方式 B 逐步执行对应系统的命令。
第一步:创建 API Key
登录 ApiPorter 控制台并打开“令牌 / API Keys”,创建一个能够访问 gpt-5.6-sol 的 Key。选择任意包含该模型的非 default 分组即可,不要求使用某个特定分组。
先保存好完整 Key。接下来既可以运行一键脚本,也可以手动创建相同的配置文件。
第二步:选择配置方式
方式 A:运行一键脚本
不熟悉终端?可以先查看互动排练。它只在当前页面演示操作,不会修改你的电脑。
macOS 或 Linux
普通电脑请使用当前用户直接执行,不要添加 sudo:
curl -fsSL https://www.apiporter.com/install/codex.sh | sh如果当前已经使用 root 登录 VPS、云服务器或容器,请执行:
curl -fsSL https://www.apiporter.com/install/codex.sh | APIPORTER_ALLOW_ROOT=1 sh脚本会让你选择语言,安装或更新 Codex,备份已有配置,安全输入 ApiPorter API Key,把 provider 设置写入 ~/.codex,并验证 gpt-5.6-sol。
Windows PowerShell
使用普通 Windows 用户打开 PowerShell,然后执行:
irm https://www.apiporter.com/install/codex.ps1 | iexWindows 安装器同样支持语言选择、安全输入 API Key、配置备份、provider 文件写入和 gpt-5.6-sol 验证。完成后可直接查看“验证连接”。
方式 B:逐项创建 Codex 配置
不想运行 ApiPorter 一键脚本时,请按下面的顺序操作;每一步只执行当前操作系统对应的命令。
方式 B 会在用户级 .codex 目录中创建 config.toml 和 auth.json。
第 1 步:安装 Codex CLI
Windows PowerShell
irm https://chatgpt.com/codex/install.ps1 | iex
codex --versionLinux
curl -fsSL https://chatgpt.com/codex/install.sh | sh
codex --versionmacOS
curl -fsSL https://chatgpt.com/codex/install.sh | sh
codex --version如果安装失败,请改用下面的命令:
npm install -g @openai/codex@latest --registry=https://registry.npmmirror.com第 2 步:创建并进入 .codex 文件夹
Windows PowerShell
New-Item -ItemType Directory -Force "$HOME\.codex" | Out-Null
Set-Location "$HOME\.codex"Linux
mkdir -p ~/.codex
cd ~/.codexmacOS
mkdir -p ~/.codex
cd ~/.codex第 3 步:创建 config.toml
Windows PowerShell
$config = @'
cli_auth_credentials_store = "file"
model_provider = "apiporter"
model = "gpt-5.6-sol"
model_reasoning_effort = "xhigh"
disable_response_storage = true
model_supports_reasoning_summaries = true
[model_providers.apiporter]
name = "ApiPorter"
base_url = "https://www.apiporter.com/v1"
wire_api = "responses"
requires_openai_auth = true
'@
$utf8NoBom = New-Object System.Text.UTF8Encoding -ArgumentList $false
[System.IO.File]::WriteAllText(
(Join-Path (Get-Location) "config.toml"),
$config,
$utf8NoBom
)Linux
cat > config.toml << 'EOF'
cli_auth_credentials_store = "file"
model_provider = "apiporter"
model = "gpt-5.6-sol"
model_reasoning_effort = "xhigh"
disable_response_storage = true
model_supports_reasoning_summaries = true
[model_providers.apiporter]
name = "ApiPorter"
base_url = "https://www.apiporter.com/v1"
wire_api = "responses"
requires_openai_auth = true
EOF
chmod 600 config.tomlmacOS
cat > config.toml << 'EOF'
cli_auth_credentials_store = "file"
model_provider = "apiporter"
model = "gpt-5.6-sol"
model_reasoning_effort = "xhigh"
disable_response_storage = true
model_supports_reasoning_summaries = true
[model_providers.apiporter]
name = "ApiPorter"
base_url = "https://www.apiporter.com/v1"
wire_api = "responses"
requires_openai_auth = true
EOF
chmod 600 config.toml第 4 步:创建 auth.json
执行当前系统的命令前,必须把 YOUR_APIPORTER_API_KEY 替换成在 ApiPorter 创建的完整 Key。文件必须保持合法 JSON,并使用 OPENAI_API_KEY 字段;不要添加 provider 的 auth 命令块。当前 Codex 的 API Key 配置必须保留 requires_openai_auth = true。
Windows PowerShell
$authJson = @'
{
"auth_mode": "apikey",
"OPENAI_API_KEY": "YOUR_APIPORTER_API_KEY"
}
'@
$utf8NoBom = New-Object System.Text.UTF8Encoding -ArgumentList $false
[System.IO.File]::WriteAllText(
(Join-Path (Get-Location) "auth.json"),
$authJson,
$utf8NoBom
)Linux
cat > auth.json << 'EOF'
{
"auth_mode": "apikey",
"OPENAI_API_KEY": "YOUR_APIPORTER_API_KEY"
}
EOF
chmod 600 auth.jsonmacOS
cat > auth.json << 'EOF'
{
"auth_mode": "apikey",
"OPENAI_API_KEY": "YOUR_APIPORTER_API_KEY"
}
EOF
chmod 600 auth.json第 5 步:启动 Codex
Windows PowerShell
Set-Location $HOME
New-Item -ItemType Directory -Force "my-codex-project" | Out-Null
Set-Location "my-codex-project"
codex --model gpt-5.6-solLinux
cd ~
mkdir -p my-codex-project
cd my-codex-project
codex --model gpt-5.6-solmacOS
cd ~
mkdir -p my-codex-project
cd my-codex-project
codex --model gpt-5.6-sol第三步:验证连接
如果使用了一键脚本,请先完全退出已经打开的 Codex CLI、IDE 或桌面应用,再打开新终端,进入项目目录并执行:
codex --model gpt-5.6-sol完成配置后也可以下载 Codex App 进行使用。
进入 Codex 后输入:
请用一句话确认当前使用的模型和 provider。能够正常回复,就说明配置完成。
常见问题
| 现象 | 处理方法 |
|---|---|
| 401 | 重新复制 API Key,并确认 Key 没有被删除或禁用。 |
| model_not_found | 编辑 API Key,选择一个可以访问 gpt-5.6-sol 的分组。 |
| 仍然出现 ChatGPT 登录 | 完全退出所有 Codex 进程后重新打开。 |
| 找不到 codex 命令 | 重新打开终端;Windows 可以尝试运行 codex.cmd。 |