OpenAI API 401 Incorrect API Key Provided

Share
Workaround available API Updated November 14, 2026Based on 4 user reportsHow we research

Quick answer

A 401 means the key is wrong, revoked, from another organization or project, or blocked by an IP allowlist. Create a fresh key in the right project and fix your environment variable.

Most likely fix: Check the header and variable

How to fix it

Try these in order — the most common fix is first.

  1. 1. Check the header and variable

    1. Print the key length (not the key) at runtime
    2. Remove spaces and newlines
    3. Restart the shell or server so new env vars load
    Did this fix it?
  2. 2. Create a new key

    1. platform.openai.com > API keys > Create new secret key in the correct project
    2. Update your secrets store
    Did this fix it?
  3. 3. Check organization and project

    1. Confirm OpenAI-Organization and OpenAI-Project headers if you set them
    Did this fix it?
  4. 4. Check IP allowlists

    1. Settings > Security: add your server IP or remove the restriction
    Did this fix it?

Symptoms

AuthenticationError: Incorrect API key provided, or Invalid Authentication.

Why it happens

  • Typo or trailing whitespace
  • Key deleted or revoked
  • Key from a different org or project
  • Stale cached environment variable
  • IP not on the allowlist
  • Removed from the organization

This guide also covers

  • openai 401 incorrect api key
  • openai invalid authentication
  • openai api key not working

Still not working?

If OpenAI keeps failing, you're not alone. See every OpenAI problem users report or the alternatives people switch to.

Have an app idea? Our small team builds any software: web and mobile apps, games, desktop, AI tools. Price agreed together.

Talk to us
Fixed it? Share this guide

The same problem in other apps

All ai & editing tools not working guides →

Other OpenAI errors

All 11 OpenAI errors and fixes →