# Codex: 401 Unauthorized, Incorrect API key provided

> Codex read a key (from `CODEX_API_KEY` or `codex login --with-api-key`) and OpenAI rejected it: mistyped, revoked, or from a project without access. 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

```text
ERROR: unexpected status 401 Unauthorized: Incorrect API key provided: sk-proj-*****. You can find your API key at https://platform.openai.com/account/api-keys.
```

## What it means

Codex read a key (from `CODEX_API_KEY` or `codex login --with-api-key`) and OpenAI rejected it: mistyped, revoked, or from a project without access.

## Fix

1. Create a new key at platform.openai.com and run `codex login --with-api-key` again.
2. Or switch to a ChatGPT sign-in with `codex login`, which bills your ChatGPT plan instead of API credits.

## In an EnvHaven workspace

Yes, if a wrong key is set.

## 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.

## Keep reading

- [Codex](https://envhaven.com/agents/codex)
- [Is Codex down?](https://envhaven.com/status/codex)
- [Every agent error](https://envhaven.com/errors)

Source: https://envhaven.com/errors/codex/incorrect-api-key-provided
