Codex: 401 Unauthorized, Missing bearer or basic authentication in header

Codex sent a request with no credentials. The exact message, why Codex prints it, and the fix.

Updated November 23, 2026 · Checked against Codex 0.157.1, reproduced in EnvHaven 1.9.0

The message

ERROR: unexpected status 401 Unauthorized: Missing bearer or basic authentication in header, url: https://api.openai.com/v1/responses

What it means

Codex sent a request with no credentials. The usual reason is an API key in OPENAI_API_KEY: Codex does not read that variable, so it is not signed in at all. It retries five times (“Reconnecting… 1/5”) before showing this.

Fix

  1. Sign in with ChatGPT: run codex and choose the ChatGPT sign-in, or codex login --device-auth without a browser.
  2. Or use an API key the way Codex reads it: codex login --with-api-key, or export it as CODEX_API_KEY.

In an EnvHaven workspace

Yes, until Codex is signed in. Sign in from the workspace’s Launch menu, which runs codex login --device-auth for you.

Where this comes from

This message was produced by Codex (Codex 0.157.1) itself, in a throwaway EnvHaven 1.9.0 container, on 2026-11-23; the text above is copied from that output.