Codex CLI Errors — Missing OPENAI_API_KEY, config.toml, stream error
Codex CLI reads ~/.codex/config.toml, resolves a model provider, then streams over the Responses API. Each stage fails differently: a missing env var, a malformed profile, a stale login, or an HTTP error mid-stream. The pages below take them in that order.
| Error | Meaning |
|---|---|
Missing OPENAI_API_KEY | Codex refuses to start when the environment variable its provider expects is unset. How env_key works in config.toml, why exports vanish between shells, and a working profile. |
codex config.toml error | Codex fails to load a malformed ~/.codex/config.toml: unknown provider names, wrong wire_api, missing sections. The exact structure a custom provider needs. |
codex auth.json error | Codex login state lives in ~/.codex/auth.json, and a stale or missing file produces login prompts and auth failures. When to re-login and when a custom provider skips it entirely. |
stream error: unexpected status 401 Unauthorized | Mid-stream HTTP failures in Codex print as stream error: unexpected status. What 401, 404 and 429 mean there, and how to reproduce them with curl to find the broken half. |
Codex CLI: Missing OPENAI_API_KEY — Custom Provider Setup
Codex refuses to start when the environment variable its provider expects is unset. How env_key works in config.toml, why exports vanish between shells, and a working profile.
Codex config.toml Errors — model_providers Setup That Works
Codex fails to load a malformed ~/.codex/config.toml: unknown provider names, wrong wire_api, missing sections. The exact structure a custom provider needs.
Codex auth.json / Login Errors — API Key Auth Instead
Codex login state lives in ~/.codex/auth.json, and a stale or missing file produces login prompts and auth failures. When to re-login and when a custom provider skips it entirely.
Codex: stream error: unexpected status 401/404 — Fix
Mid-stream HTTP failures in Codex print as stream error: unexpected status. What 401, 404 and 429 mean there, and how to reproduce them with curl to find the broken half.