Troubleshooting

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.

ErrorMeaning
Missing OPENAI_API_KEYCodex 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 errorCodex 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 errorCodex 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 UnauthorizedMid-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.

Skip the broken setup

apiToken.sale serves the standard Anthropic API — same models, same SDKs, one prepaid balance. Point your tool's base URL at it, and the config on this page works as written.