Authenticate with an OpenAI API key
getting started
// what it does
Instead of a ChatGPT subscription you can pay usage-based through the OpenAI API. Pipe the key into codex login --with-api-key over stdin; the environment variable Codex reads is OPENAI_API_KEY (not CODEX_API_KEY). This is the practical choice for CI and shared automation where no interactive browser exists.
// shell
$ printenv OPENAI_API_KEY | codex login --with-api-key// gotcha
The key is read from stdin, not passed as an argument — codex login --with-api-key sk-... does not work; pipe it with printenv or echo. API-key usage bills your OpenAI API account separately from any ChatGPT plan.