接入编程助手
Codex 接入
使用一键脚本,或手动配置 Codex、Modelflare API Key 和 Responses 兼容模型。
这篇文档只解决一件事:让 Codex 通过 Modelflare 成功发送第一条请求。想最快完成就用方式 A;想自己逐项创建配置,就按方式 B 的每一步分别执行当前操作系统的命令。
第一步:创建 API Key
Section titled “第一步:创建 API Key”登录 Modelflare 控制台,进入令牌 / API Keys 页面,创建一个可以访问 gpt-5.6-sol 的 Key。选择任意包含该模型的非 default 分组即可,不存在唯一指定或推荐分组。
先保留好这个 Key。你可以使用一键脚本,也可以手动创建同样的配置文件。
第二步:选择配置方式
Section titled “第二步:选择配置方式”方式 A:运行一键脚本
Section titled “方式 A:运行一键脚本”还不熟悉终端?先打开互动排练。这只是视觉演练,不会修改你的电脑。
普通电脑请使用当前用户直接执行,不要加 sudo:
curl -fsSL https://modelflare.dev/install/codex.sh | sh如果你本来就是用 root 登录 VPS、云服务器或容器,请使用:
curl -fsSL https://modelflare.dev/install/codex.sh | MODELFLARE_ALLOW_ROOT=1 sh脚本会安装或更新 Codex、备份现有配置、让你粘贴 Modelflare API Key,并把 provider 配置写入 ~/.codex。
用普通 Windows 用户打开 PowerShell,执行:
irm https://modelflare.dev/install/codex.ps1 | iex安装器会让你选择语言并粘贴 Modelflare API Key,随后验证 gpt-5.6-sol 是否可用;修改文件前会自动备份。运行结束后直接查看“验证连接”。
方式 B:逐项创建 Codex 配置
Section titled “方式 B:逐项创建 Codex 配置”不想运行 Modelflare 一键脚本时,就按下面的顺序操作。每一步都只执行自己操作系统对应的命令。
方式 B 会在用户级 .codex 目录中创建两个文件:config.toml 和 auth.json。
第 1 步:安装 Codex CLI
Section titled “第 1 步:安装 Codex CLI”irm https://chatgpt.com/codex/install.ps1 | iexcodex --versioncurl -fsSL https://chatgpt.com/codex/install.sh | shcodex --versioncurl -fsSL https://chatgpt.com/codex/install.sh | shcodex --version如果安装失败,请改用下面的命令:
npm install -g @openai/codex@latest --registry=https://registry.npmmirror.com第 2 步:创建并进入 .codex 文件夹
Section titled “第 2 步:创建并进入 .codex 文件夹”New-Item -ItemType Directory -Force "$HOME\.codex" | Out-NullSet-Location "$HOME\.codex"mkdir -p ~/.codexcd ~/.codexmkdir -p ~/.codexcd ~/.codex第 3 步:创建 config.toml
Section titled “第 3 步:创建 config.toml”$config = @'cli_auth_credentials_store = "file"model_provider = "modelflare"model = "gpt-5.6-sol"model_reasoning_effort = "xhigh"disable_response_storage = truemodel_supports_reasoning_summaries = true
[model_providers.modelflare]name = "Modelflare"base_url = "https://modelflare.dev/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)cat > config.toml << 'EOF'cli_auth_credentials_store = "file"model_provider = "modelflare"model = "gpt-5.6-sol"model_reasoning_effort = "xhigh"disable_response_storage = truemodel_supports_reasoning_summaries = true
[model_providers.modelflare]name = "Modelflare"base_url = "https://modelflare.dev/v1"wire_api = "responses"requires_openai_auth = trueEOFchmod 600 config.tomlcat > config.toml << 'EOF'cli_auth_credentials_store = "file"model_provider = "modelflare"model = "gpt-5.6-sol"model_reasoning_effort = "xhigh"disable_response_storage = truemodel_supports_reasoning_summaries = true
[model_providers.modelflare]name = "Modelflare"base_url = "https://modelflare.dev/v1"wire_api = "responses"requires_openai_auth = trueEOFchmod 600 config.toml第 4 步:创建 auth.json
Section titled “第 4 步:创建 auth.json”执行当前系统的命令前,必须把 JSON 对象中的 YOUR_MODELFLARE_API_KEY 替换成你在 Modelflare 控制台创建的完整 API Key。文件必须保持合法 JSON,并使用 OPENAI_API_KEY 字段;不要再添加 provider 的 auth 命令块。当前 Codex 版本的 API Key 配置必须保留 requires_openai_auth = true。
$authJson = @'{ "auth_mode": "apikey", "OPENAI_API_KEY": "YOUR_MODELFLARE_API_KEY"}'@$utf8NoBom = New-Object System.Text.UTF8Encoding -ArgumentList $false[System.IO.File]::WriteAllText( (Join-Path (Get-Location) "auth.json"), $authJson, $utf8NoBom)cat > auth.json << 'EOF'{ "auth_mode": "apikey", "OPENAI_API_KEY": "YOUR_MODELFLARE_API_KEY"}EOFchmod 600 auth.jsoncat > auth.json << 'EOF'{ "auth_mode": "apikey", "OPENAI_API_KEY": "YOUR_MODELFLARE_API_KEY"}EOFchmod 600 auth.json第 5 步:启动 Codex
Section titled “第 5 步:启动 Codex”Set-Location $HOMENew-Item -ItemType Directory -Force "my-codex-project" | Out-NullSet-Location "my-codex-project"codex --model gpt-5.6-solcd ~mkdir -p my-codex-projectcd my-codex-projectcodex --model gpt-5.6-solcd ~mkdir -p my-codex-projectcd my-codex-projectcodex --model gpt-5.6-sol第三步:验证连接
Section titled “第三步:验证连接”如果使用了一键脚本,请先完全退出已经打开的 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。 |