ChatGPT error 401 : Incorrect API key provided

This issue has created a hell of hinderance in my work using this API.
Can anyone please look into a possible solution of this thread.
Even the fresh tokens that I mint doesnt work for like even once.

The exact error from the logs is

error - ChatGPTError: ChatGPT error 401: {
“error”: {
“message”: “Incorrect API key provided: sk-R7aMV***************************************oKYo. You can find your API key at OpenAI API”,
“type”: “invalid_request_error”,
“param”: null,
“code”: “invalid_api_key”

Hi @jayadityanautiyal07

Sharing the complete API call you’re making will be helpful.

1 Like

Using the key is in the image

calling the API
const resp = await api.sendMessage(
Tell me the quality of this code : ${decodedContent}

Please find the neccesary information

It works when someone else runs the code with their API key instead

I am having a similar issue with my fine-tuning code. The API is correct (tested on 2 different devices and accounts).

Here is the code:

import openai

# Set your OpenAI API key
openai.api_key = "not sharing for privacy reasons"

# Define your fine-tuning parameters
model_engine = "text-ada-002"
model_name = "1pg-ada-v1"
dataset = "dataset.txt"
epochs = 2
batch_size = 2

Error I’m getting is:
openai.error.AuthenticationError: Incorrect API key provided: 1pg-ada-v1. You can find your API key at OpenAI API.

Yes, that is all “well and good” but please post your actual code where you use those params to call the API.



1 Like

Thank you for your response. Here is the complete code:

import openai

# Set your OpenAI API key
openai.api_key = "***"

# Define your fine-tuning parameters
model_engine = "text-ada-002"
model_name = "model-ada-v1"
dataset = "training.txt"
epochs = 2
batch_size = 2

# Retrieve your fine-tuned model
model = openai.Model.retrieve(model_engine, model_name)

# Fine-tune your model on your custom dataset

# Generate text using your fine-tuned model
response = model.generate(
    prompt=''' For the text below, rewrite it using the trained model. 
Dear Colleagues, I has been working on this project for a long time and I've been faced many obstacles during the development process. I wants to inform you that I will completes the project tomorrow. Thanks for yous support.''',

# Print the generated text
generated_text = response.choices[0].text.strip()
print ("generated text ", generated_text)


Did you use ChatGPT to generate that code?



yes… i generated this code with the help of ChatGPT.

Thank you for your response. I’ll refer to the documenation.

1 Like

You are welcome @arzoop

Keep in mind that if you want ChatGPT to draft some module or method for you based on programming syntax and functions or libs which are very mature and have been around for many years, then of course you can get a pretty good draft code block using ChatGPT.

However, for code with depends on recent libraries and API methods which are constantly evolving, using a generative AI will simply result in a lot of hallucinated code which will waste your time.

For example, if you ask ChatGPT to write a “hello world” program or method in Python, the odds are very high you will get a nice reply which may be 100% correct.

However, if you ask ChatGPT to write a chat completion method for the new turbo model, ChatGPT will generate a lot of great sounding nonsense because it simply fits words to a model with data which is not there, missing or deprecated.

Think of it as that friend of your who “knows everything” and has a great answer to everything, even though they really have no idea. This is what happens when you ask ChatGPT to write code for libs and functions which were released after the cut-off date (not to mention all the deprecated code it will attempt to fit to the model).

It’s simply blah, blah blah… but it looks good, haha.



1 Like

What are you going for here? The tone comes off as unnecessarily demeaning.

No it is not demeaning, that is simply how you interpret it @dill (sorry you feel that way, TBH). I am simple stating a technical software development fact.

The fact is that experienced coders who use the OpenAI API can look at code posted here which ChatGPT has “written” with-regard-to OpenAI API requests and we can easily see that the code is hallucinating nonsense generated by ChatGPT.

How do we know this? Because ChatGPT uses deprecated API endpoints which have long been deprecated. The same goes for OpenAI API params.

In addition, ChatGPT will hallucinate functions, methods, parameters, etc which do not exist because of its cut-off date of mid 2021. So, when a developer is familiar with the API docs and have written a lot of OpenAI API code, they can immediately spot these hallucinations.

These are the facts. Nothing but the facts.

OpenAI says the same thing when their terms and conditions caution everyone about the mid 2021 cut-off date of their models pre-training data. So does all the literature on generative AI.

If you don’t believe me, @dill, read this paper released a few days ago by OpenAI:

It’s best to stick to technical facts @dill and not personality, your own biases and feeling about ChatGPT, and words or how experienced OpenAI API software developers here state a well-known technical fact (and serious limitation) about ChatGPT.

Can you easily spot when ChatGPT “makes up nonsense” when it generates OpenAI API related code, @dill ? Many of us who write OpenAPI API code can spot this kind of “ChatGPT generated spam code” in seconds.

However, we devs here do not yet “flag” ChatGPT generated spam code as such, as we understand many passionate ChatGPT users have not learned the limitations of generative AI (again, please visit link above and read OpenAI’s March 2023 research paper on GPT4).



Hi @jayadityanautiyal07

Thanks for sharing that

A couple of things stand out:

  • The module you are using isn’t in the list of official or community libraries and since I cannot see from the code you shared what code that’s making the call to the API, I cannot tell what’s wrong in the code.

  • Since you mentioned that the code works for other users’ API keys, I’d recommend generating another API key and using that instead. If that doesn’t work, contact support on

My advice is, use the official JS library from the link provided. Even the support will tell you to do so.

Also don’t use non-official libraries unless you have verified the code on GitHub.

1 Like