API Key Trouble

Certainly there must be something more to this than just clearing cache and restarting browser. I’m having the same issue. The error message with the partial API key does not match the one I generated in my account. I’m running into this issue on the image generation website. Is there any other resolution to getting this to work? i have purchased credits that will expire and I cannot use Dall-E-2.


Same issue here. I put the API in and I get the same error.

Same issue here. Someone find a solution? It is working for my husband’s account but not for mine? We create our account today

Same here! Maybe it is a problem with the API

Same here,
“error”: {
“message”: “Incorrect API key provided: sk-eXBr0***************************************PQrq. You can find your API key at https://beta.openai.com.”,
“type”: “invalid_request_error”,
“param”: null,
“code”: “invalid_api_key”

+1, definitely a problem with their API. I minted a brand new key and just used the CURL example from the completion endpoint and got the same error.

$ curl https://api.openai.com/v1/completions   -H "Content-Type: application/json"   -H "Authorization: Bearer $OPENAI_API_KEY"   -d '{
  "model": "text-davinci-003",
  "prompt": "Translate this into 1. French, 2. Spanish and 3. Japanese:\n\nWhat rooms do you have available?\n\n1.",
  "temperature": 0.3,
  "max_tokens": 100,
  "top_p": 1,
  "frequency_penalty": 0,
  "presence_penalty": 0
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   538  100   280  100   258   1075    990 --:--:-- --:--:-- --:--:--  2077{
    "error": {
        "message": "Incorrect API key provided: sk-MY7LJ***************************************8qrE. You can find your API key at https://beta.openai.com.",
        "type": "invalid_request_error",
        "param": null,
        "code": "invalid_api_key"

I think we’ve only got THREE threads on this now. :wink:


aaaand we are back! Just ran the exact same curl from y’day and it works perfectly now.

OpenAI Status doesn’t show any hiccups y’day though :man_shrugging:

1 Like

same issue here today
I generated the API key and as soon as I used it
It throws an error that:
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”

I used the first key I created and found it was accessible, but the newly generated key was still unavailable

@jayadityanautiyal07 there is no such thing as a “ChatGPT Error”, no clue where you are getting this message from, mind sharing?

1 Like

Logan, I have not used this, and have just become aware of it

However, it is a top hit if you search for ChatGPT API

There may be a level further down as this looks like a node wrapper. I haven’t got the time to have a look right now. Here is a second link

1 Like

These are not official API’s and violate our terms of use.

Hello There, thank you very much!

I face a similar issue with Curl in windows 10 as I cannot use my environment variable in the H param. Can anyone help out?

curl https://api.openai.com/v1/models -H “Authorization: Bearer $OPENAI_API_KEY”
“error”: {
“message”: “Incorrect API key provided: $OPENAI_***_KEY. You can find your API key at OpenAI API”,
“type”: “invalid_request_error”,
“param”: null,
“code”: “invalid_api_key”

Many thanks for your help!

Maybe this is resolved in principle since the thread has gone quiet, but I have still had the same problem today (in March 2023) and it seems to affect both terminal commands and python scripts intermittently and unpredictably. The chatbot itself - gpt-3.5-turbo version in beta on playground - suggested that it may be an issue with how the openai module is treating assignments of environment variables in the background. I have no idea, but it reckoned that the dotenv approach would work, and it did.
Installing the latest version of dotenv (1.0.0 on macOS) and then, assuming that NOTHING is in the .env file except the unquoted sk-… API_KEY:

import dotenv
for k in dotenv.dotenv_values():

Because there is only one entry in the dictionary returned by dotenv.dotenv_values() with a blank value and key equal to the OPEN_API_KEY.
It’s ugly, but it works. First post on this forum so apologies if I’ve done or said something wrong.

1 Like

Dear pudepiedj,
thank you very much. Your solution might work on macOS, but do you know how to apply dotenv directly in curl on windows 10? Running the API from curl, is the main issue i face. Did not digg in python yet, but the API runs properly, but not in curl.

I can’t help with Windows 10, but I can reproduce the error and - I think - resolve it using curl from a macOS terminal, so perhaps that will help.
The problem appears to be that the assignment of the OPENAI_API_KEY from within Python doesn’t transfer to the environment variables used by terminal, as printenv confirms, so it can’t find it. I have no idea how to solve that but this does work in terminal for me (note carefully the semi-colon after the key definition):


curl https://api.openai.com/v1/embeddings
-H “Content-Type: application/json”
-H “Authorization: Bearer $OPENAI_API_KEY”
-d ‘{“input”: “This is a test embedding using ADA”, “model”:“text-embedding-ada-002”}’

Notes: this assigns a variable to the shell not to the environment, but at least it allows the code to run in situ rather than entering the sk-… directly into the curl command. Assigning to an environment variable doesn’t seem to work so maybe the API isn’t accessing the environment correctly? Hope this helps.

I think the environment variable can be set temporarily and will then work. This requires a subtle change to the assignment which has something to do with working in a different shell - you may need to use bash where I have zsh (and note the single quotes):

OPENAI_API_KEY=sk-… zsh -c ‘echo $OPENAI_API_KEY’
then curl as before.

Gleaned from bash - How to print / echo environment variables? - Stack Overflow

Dear pudepiedj,
many thanks for your appreciated inputs and explanations. Unfortunately none of it solves it in windows 10. I can access API in Python but still not in Curl and I tried in Powershell too. Best, Jan

A neater solution which may be transferable to Windows 10 suitably modified by using some combination of doskey, call and *.bat is to put the API_KEY inside a file then execute that file from the terminal using what on a Mac is source. I think this method is common and that you will have an equivalent of zsh. Use any text editor to create a file called “.myapikey”, save it and execute it from the terminal.
This is on Mac:

sudo nano /.myapikey
# inside nano insert this line into the .myapikey file
# save the file and close the editor
source /.myapikey

I asked gpt-3.5-turbo what the equivalent on Windows 10 is, and it suggested this:

On Windows 10, the equivalent command sequence to set an environment variable from a file and use it in a command prompt window would be:

1. Open a command prompt window.

2. Navigate to the folder where the `.myfile` file is located using the `cd` command.

3. Use the `set` command to set the environment variable. For example:

set /p OPENAI_API_KEY=<.myfile

This command reads the value of `OPENAI_API_KEY` from the `.myfile` file and sets it as an environment variable.

4. Verify that the environment variable is set correctly by typing `echo %OPENAI_API_KEY%` and pressing Enter. This should display the value of the `OPENAI_API_KEY` variable.

Note that the syntax for setting environment variables on Windows is slightly different from MacOS/Linux. On Windows, you use the `%` symbol to enclose the name of the environment variable when you want to reference its value, rather than using the `$` symbol like on MacOS/Linux.
1 Like

This is great @pudepiedj If curl on CMD does not work properly, or only with restrictions. Windows users can use powershell as well:

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force

$headers = @{
    "Authorization" = "Bearer $env:OPENAI_API_KEY"
    "model" = "text-davinci-002"
Invoke-WebRequest -Uri "https://api.openai.com/v1/models" -Headers $headers
Get-ChildItem Env:OPENAI_API_KEY

I will check your proposition :slight_smile:
Best, Jan

(newbie) setting up API. The OpenAI website doesn’t appear to be showing me my full API keys on the API key page? Both the existing key and the one generated by me have ellipses in them, and I don’t see how or where to see the full key. (tried to google this but without success).