401 Incorrect API key provided

Hi, folks.
I’ve got a error message that says " 401 Incorrect API key provided: sk-Eyftb***************************************99vW."
But I’ve never used the API key, there is no such an api key on my openai_api key list.
These are the things I’ve tried to solve the issue.

  • generate another api key(e.g. test)
  • clear browser’s cache
  • confirmed api key that I’m actually using in .env.local with the openai_api_key on openai’s api page.
  • confirmed there are no typos or space on openai_api_key code.

anyone got the same problem?

An API key will first be looked for in the operating system’s environment variables.

See if you haven’t already set an environment variable OPENAI_API_KEY, and if so, change it to one that is valid.

2 Likes

I figured it out! really appreciate it !! :joy:

Hey,

How did you solve this? Been having the same problem for the past hour.

Did you do something like:

export OPENAI_API_KEY=sk-………

In the terminal/cmd window?

I expect that the prior error was resolved by discovering the source of incorrect authentication credentials that were being employed in making API calls.

What software platform is being used?

For example, you might write some python code taken right from the API Reference, using the openai python module.

from openai import OpenAI
client = OpenAI()

completion = client.chat.completions.create(
  model="gpt-3.5-turbo",
  messages=[
    {"role": "system", "content": "You are a helpful assistant."},
    {"role": "user", "content": "Hello!"}
  ]
)

print(completion.choices[0].message)

If on Windows, how does this code know what API key to use? Environment variable.

Start typing “environment” into the Windows 10 start menu, and you get:

image

Under system variables, look for an existing API key, or place your key created from the account’s API key management into a new one:

image