「unexpected status 401 Unauthorized: {"detail":"Unauthorized"}, url: https://chatgpt.com/backend-api/codex/responses」
更新于
「unexpected status 401 Unauthorized…」不是额度提示:Codex 的请求没有带有效凭据,OpenAI 错误码页称为「Invalid Authentication」。等窗口、重置卡、全员重置都没用,解决办法是退出后重新 codex login。最近一次 Codex 官方重置:2026年9月12日 08:09 UTC。
- 上次重置
- 09-12 08:09Z
- 状态
- 已超期
距上次重置已超过近期中位间隔的 1.5 倍。
- 预计下次
- 随时
- 距今天数
- 5.6
天
「unexpected status 401 Unauthorized: {"detail":"Unauthorized"}, url: https://chatgpt.com/backend-api/codex/responses」是什么意思?
401 是认证错误,不是额度。OpenAI 的 API 错误码页把「401 - Invalid Authentication」的解决办法写为「Ensure the correct API key and requesting organization are being used」;限流是另一个码,「429 - Rate limit reached for requests」。Codex 打印这一行时,发往 chatgpt.com/backend-api/codex/responses 的请求在计入任何用量之前就被拒绝了。
问题出在你缓存的登录信息。Codex「caches login details locally in a plaintext file at ~/.codex/auth.json or in your OS-specific credential store」,并且「refreshes tokens automatically during use before they expire」。本页背后的报告展示了它会怎么坏:refresh token 被吊销(issue #41973:「Your access token could not be refreshed because your refresh token was revoked. Please log out and sign in again.」)、缓存的 token 缺少 scope(issue #33664:「Missing scopes: api.responses.write」,重命名 auth.json 重新登录后解决)、桌面 App 卡在没有 bearer token 的状态(issue #30039:「401 Unauthorized: Missing bearer authentication」)。
因为根本没有计量,限额相关的工具都不适用:/status 甚至可能显示进度条满格,重置卡没有东西可刷新,全员 Codex 重置也不碰凭据。把「You've hit your usage limit」和「401 Unauthorized」当作两条互不相干的信息。
满的是哪个窗口?
| 窗口 | 何时刷新 | 在哪里看 |
|---|---|---|
| 无:401 是认证,不是用量窗口 | 它不会「重置」。等 5 小时窗口或周限额、兑换重置卡、等全员 Codex 重置都清不掉 401,只有有效凭据才行。 | codex login status(「Logged in using ChatGPT」或 API key 状态);/status 里的 Account 行 |
看到它该怎么办
- 先看 Codex 认为你是谁
运行 codex login status;文档说它显示「the active authentication method」,有凭据时退出码为 0。注意 issue #41973 里它仍报告「Logged in using ChatGPT」,但每个请求都 401,所以状态正常不代表 token 没被吊销。
- 退出登录,再登录
运行 codex logout(「Remove saved credentials for both API key and ChatGPT authentication」)或在会话里输入 /logout,再 codex login 完成浏览器授权;浏览器回跳失败时用 codex login --device-auth。桌面 App 或 IDE 里在个人菜单点 Log out 后重新登录。
- 还不行就清掉缓存的凭据文件
Codex 把凭据存在 ~/.codex/auth.json(或按 cli_auth_credentials_store 存在系统凭据库)。issue #33664 里重装 App 都没用,重命名 auth.json 重新登录后 401 才消失。同时确认没有 OPENAI_API_KEY 环境变量或 ~/.codex/.env 覆盖了你的 ChatGPT 登录,因为 API key 登录是另一条路径。
- 不要等重置
这个错误和时间无关。重新登录后仍然 401,就带文案后面打印的 request id 和 cf-ray 去 github.com/openai/codex 提 issue(标签 auth),或联系 OpenAI Support。
什么时候重置?
你自己的窗口:不相关。401 在 Codex 把任何东西计入 5 小时窗口或周限额之前就返回了,所以 /status 可以显示有余量而每个请求都失败。重新认证是唯一的办法;窗口倒计时和限额提示里的重置时间对它没有意义。
全员重置:同样不相关。宣布的 Codex 重置「is applied directly to the usage limits covered by the announcement」,不会重新签发 token 或 scope。上方板面行只是顺带展示。如果你同时看到 401 和「You've hit your usage limit」,先修登录,再看限额页。
相关报错
- 「You've hit your usage limit. Upgrade your plan or add credits to continue, or try again at {Mon D, YYYY, H:MM AM}.」Codex
- 「You've hit your usage limit. Upgrade to Plus to continue using Codex (https://chatgpt.com/explore/plus), or try again at {Mon Dth, YYYY H:MM AM}.」Codex
- 「5h limit: [████████████████░░░░] 82% left (resets 22:41) Weekly limit: [███████████████████░] 97% left (resets 17:41 on 1 Jul)」Codex
- 「Please run /login · API Error: 401 Invalid authentication credentials」Claude Code
常见问题
401 Unauthorized 是限流吗?
不是。OpenAI 错误码页里 401 是「Invalid Authentication」,限流是 429(「Rate limit reached for requests」)。401 表示请求没有带有效凭据;没有消耗任何用量,也不涉及任何窗口。
等窗口刷新或等 Codex 重置能修好吗?
不能。用量窗口和全员重置改变的是额度,不是凭据。本页背后的报告都是靠退出再登录、或替换缓存的 auth.json 解决的,没有一例是等好的。
codex login status 显示已登录,为什么还是 401?
缓存的凭据可以存在但不再被接受。issue #41973 里「Logged in using ChatGPT」和 401 同时出现,App 还提示 refresh token 已被吊销;issue #33664 的 token 缺少 api.responses.write scope。退出再登录,或者重命名 ~/.codex/auth.json 后重新登录。
它和「You've hit your usage limit」有什么区别?
那条是限额提示,带重置时间和加 credits、用重置、升级或等待的选项。401 一样都没有:它在计量之前就被拒绝。OpenAI 帮助中心让被限额的用户看「any reset time shown」;401 不显示重置时间,因为没有什么可等。
来源
- openai/codex issue #26497 (2026-06-05): Codex CLI 0.137.0: "unexpected status 401 Unauthorized: {"detail":"Unauthorized"}, url: https://chatgpt.com/backend-api/codex/responses"核实于 2026-09-18
- openai/codex issue #41973 (2026-09-01): Codex CLI 0.152.0 and Desktop on macOS: same 401 after a successful ChatGPT login; "Your access token could not be refreshed because your refresh token was revoked. Please log out and sign in again."核实于 2026-09-18
- openai/codex issue #30039 (2026-06-25): Codex Desktop 26.616.81150: "401 Unauthorized: Missing bearer authentication", then 429 after retries, no sign-in prompt核实于 2026-09-18
- openai/codex issue #33664 (2026-07-16): Codex Desktop on Windows: "401 Unauthorized / Missing scopes: api.responses.write"; fixed by renaming ~/.codex/auth.json and signing in again核实于 2026-09-18
- ChatGPT Learn: Authentication (codex login, codex login status, codex logout, login caching)核实于 2026-09-18
- OpenAI Developers: API error codes (401 Invalid Authentication, 429 Rate limit reached)核实于 2026-09-18
- ChatGPT Learn: Codex CLI slash commands (/status, /usage, /logout)核实于 2026-09-18
- OpenAI Help Center: Using Codex with your ChatGPT plan (article 11369540)核实于 2026-09-18