VIBE⌇BRATOR
Take the Vibe Check
Error explained

401 Unauthorized from an API

401 Unauthorized

The API did not accept your credentials: the key was missing, wrong, or no longer valid.

What it means

A 401 means the request did not carry valid credentials. For an AI API that means the key: it was not sent, it is wrong, or it is no longer valid. It is not the same as 403, where the server knows who you are but will not let you do that.

Anthropic's API calls it authentication_error and ties it to a key that is malformed, revoked or expired. OpenAI's version reads "Incorrect API key provided".

Common causes

A prompt to fix it

Paste it into your AI coding tool and fill in the parts in angle brackets. It asks the tool to find the cause and show you before it changes anything.

Paste it, then fill in the <angle brackets>
My app gets 401 Unauthorized from <the API, for example OpenAI or Anthropic>.
The error body says: <paste it, but not the key itself>

Do not print, log or paste my API key anywhere, including in your answer.

Check each of these and tell me what you find:
1. Which environment variable the code reads the key from, and whether that exact name is set where the code runs: locally (.env.local) and in the Vercel project settings.
2. Whether the call happens on the server. If the key is used in browser code or in a NEXT_PUBLIC_ variable, move the call to a server route and keep the key on the server.
3. Whether the value could have a stray space, quote or line break around it.
4. Whether the key belongs to the account or project the request is for.

Then fix only what is wrong. If the key itself is bad, tell me to create a new one in the provider's dashboard. Do not invent one.

How to check it is fixed

Tested prompts that help

Sources

Everything above comes from these pages. We read them on September 27, 2026; if one has changed since, it wins.