Skip to content

[bug] config agent --agent codex 写入 env_key="OPENAI_API_KEY",未设环境变量时 Codex 0.169 不读 auth.json,直接报 Missing environment variable #355

Backlog

Description

@W007order

CLI version

2.14.0

Skill version (optional)

2.14.0

Node version

v24.19.0

OS

Windows 10.0.26200 x64 (win32), PowerShell 7.7.0

Region

cn

Command to reproduce

# 1. 登录 Token Plan
bl auth login --config token-plan --api-key [REDACTED]

# 2. 按官方引导配置 Codex
bl config agent --agent codex --region cn-beijing --key [REDACTED] --model qwen3.8-max
# → Codex configured successfully.
#   Written: ~/.codex/config.toml
#   Written: ~/.codex/auth.json
#   Exit code: 0

# 3. 不设置 OPENAI_API_KEY 环境变量,直接运行
codex exec --skip-git-repo-check "hi"

Expected behavior

命令退出码 0 并提示 configured successfully 之后,Codex 应能直接使用:provider 走 requires_openai_auth = true + auth.json 里的 key。

Actual behavior

bl config agent 提示 configured successfully(Exit code: 0),但随后的 codex exec 直接失败(输出见 Full output)。其余观察:

  • codex login status 能读到 auth.json:API key configured - sk-sp-***
  • 显式设置 OPENAI_API_KEY 环境变量后,同一命令成功(退出码 0)

Full output

$ codex exec --skip-git-repo-check "hi"
model: qwen3.8-max
provider: bailian-cli
ERROR: Missing environment variable: `OPENAI_API_KEY`.
Exit code: 1

JSON error (optional)

Already tried

  • bl update and skill version aligned with CLI
  • bl auth status OK for this command
  • Different network / region — still reproduces

How often does this happen?

Always

How was bl invoked?

Agent (Cursor, Claude, etc.)

Notes (optional)

补充环境:Codex codex-cli 0.169.0;Windows 10.0.26200 x64(win32),PowerShell 7.7.0

命令写入的 provider 配置(~/.codex/config.toml):

model = "qwen3.8-max"
model_provider = "bailian-cli"

[model_providers.bailian-cli]
name = "bailian-cli"
base_url = "https://token-plan.cn-beijing.maas.aliyuncs.com/compatible-mode/v1"
env_key = "OPENAI_API_KEY"
wire_api = "responses"
requires_openai_auth = true

~/.codex/auth.json:{"OPENAI_API_KEY": "[REDACTED]"}

对照实验(都不设置环境变量)

配置 结果
命令写入的原配置(env_key + requires_openai_auth=true + auth.json) exit 1,Missing environment variable
保留 env_key,命令行显式覆盖 requires_openai_auth=true 仍 exit 1
删掉 env_key 行(保留 requires_openai_auth=true + auth.json) 成功:codex exec 与 codex debug app-server send-message-v2 都正常返回
删掉 env_key 且 requires_openai_auth=false HTTP 401 {"code":"InvalidApiKey","message":"No API-key provided."}

结论:在 Codex 0.169.0 上,只要 provider 写了 env_key,Codex 就强制要求该环境变量,不再回退到 auth.json。bl config agent --agent codex 写出的 env_key + requires_openai_auth + auth.json 组合,在没有 OPENAI_API_KEY 环境变量的机器上不可用,而命令的成功提示里没有提到需要设置环境变量。

建议

  • 写 Codex 配置时不要写 env_key = "OPENAI_API_KEY"(保留 requires_openai_auth = true,走 auth.json);或
  • 在成功提示里明确说明必须设置 OPENAI_API_KEY 环境变量。

其它

  • 只验证了 codex exec 与 app-server 通道,未在交互式 TUI 中验证
  • 临时规避:手动删除 ~/.codex/config.toml 里 [model_providers.bailian-cli] 下的 env_key 行

Activity

  1. added
    bug
    on Nov 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions