- DR.Cat2026-08-225169
我昨天手欠升级codex到149版本之后,忽然所有的codex对话都显示401错误 ^-^
如下

具体报错是```
unexpected status 401 Unauthorized: {"code":"API_KEY_REQUIRED","message":"API key is
required in Authorization header (Bearer scheme), x-api-key header, or x-goog-api-key header"}
``发现原来是旧版本的教程/ codex的 model_providers配置中 少了``
requires_openai_auth = true
```这一项,现在走API key的都需要添加这一项,让API key能够在请求头中携带进行鉴权具体来说
这种是以前的配置```
model_provider = "xx"
model = "gpt-5-codex"
model_reasoning_effort = "high"
disable_response_storage = true
preferred_auth_method = "apikey"[model_providers.xx]
name = "xx"
base_url = "https://api.xx.com/v1"
wire_api = "responses"
``然后新版的配置需要变成``model_provider = "xx"
model = "gpt-5-codex"
model_reasoning_effort = "high"
disable_response_storage = true
preferred_auth_method = "apikey"[model_providers.xx]
name = "xx"
base_url = "https://api.xx.com/v1"
wire_api = "responses"
requires_openai_auth = true主楼 - 散漫星空2026-08-2239105
requires_openai_auth = true ```感谢佬 我说怎么突然就401了 上来一搜果然没让我失望 - 水母2026-08-2231952
直接把以下内容保存为xxx.sh,用source xxx.sh执行就行。
还加入了1M上下文设置,直接改APIKEY、URL可用~```
#!/bin/bashset -e
API_KEY="xxxxxxxxxxx"
if [ -z "$API_KEY" ] || [ "$API_KEY" = "__API_KEY__" ]; then
echo "ERROR: API Key not set"
exit 1
fiCODEX_DIR="$HOME/.codex"
mkdir -p "$CODEX_DIR"cat > "$CODEX_DIR/config.toml" << 'EOF'
model_provider = "gpt"
model = "gpt-5.6-sol"
model_reasoning_effort = "xhigh"
disable_response_storage = true
model_context_window = 1000000
model_auto_compact_token_limit = 900000
[model_providers.gpt]
name = "gpt"
base_url = "https://xxxxxx"
wire_api = "responses"
requires_openai_auth = true
web_search = "cached" # default; serves results from the web search cacheweb_search = "indexed" # gate external web access through the search index
web_search = "live" # fetch the most recent data from the web (same as --search)
web_search = "disabled"
EOF
cat > "$CODEX_DIR/auth.json" << EOF
{
"OPENAI_API_KEY": "$API_KEY"
}
EOFchmod 600 "$CODEX_DIR/config.toml" "$CODEX_DIR/auth.json" || true
echo "OK: Files written to $CODEX_DIR"
- surf2026-08-2217895
感谢佬,解决了,还以为自己的问题