OpenAI API 401 Unauthorized (authentication error)

Is there an outage right now?

OpenAI API official status is operational. If this error persists, it is likely an implementation or environment issue on your side.

View OpenAI API status

What this error means

401 means authentication failed: invalid/expired/missing API key, or wrong org/project.

Common causes

  • Wrong, expired, or deleted API key
  • Malformed Authorization header (missing Bearer)
  • Env var not loaded (unset / typo)
  • Wrong Organization / Project
  • Insufficient key permissions

How to fix

  1. 1.Reissue the API key and set it correctly via env
  2. 2.Use `Authorization: Bearer <KEY>` format
  3. 3.Read the key from env, not hardcoded
  4. 4.Pass the correct Organization/Project
  5. 5.Check the key scopes/permissions

When waiting helps (and when it won't)

401 is a config issue—waiting will not fix it. Re-check key, header and env vars.

Alternatives when OpenAI API is down

Claude APIGemini API / AI StudioMistral APIDeepSeek APIGroq API

Related errors

FAQ

What is 401 Unauthorized?

401 means authentication failed: invalid/expired/missing API key, or wrong org/project.

How do I fix 401 Unauthorized?

Reissue the API key and set it correctly via env / Use `Authorization: Bearer <KEY>` format / Read the key from env, not hardcoded / Pass the correct Organization/Project / Check the key scopes/permissions