"Incorrect API key provided: error again"

Was using a Pay as you go with enough Credit balance. I am getting :“Incorrect API key provided” error, i am using command promt with Curl (with i got through Git).

curl https://api.openai.com/v1/audio/speech ^
-H "Authorization: Bearer <sk-7********************************************o>" ^
-H "Content-Type: application/json" ^
-d "{""model"": ""<tts-1>"", ""input"": ""<[Vietnamese]Hãy cùng các thầy cô khám phá Mục tiêu Phát triển Bền vững (SDGs) và truyền cảm hứng để các bạn học sinh của chúng ta trở thành thế hệ tiên phong cho sự thay đổi ngay hôm nay!.>"", ""voice"": ""<Fable>"", ""speed"": <1.0>}" ^
--output <OpenAI-TTS-Fable>.mp3

the result are:“Incorrect API key provided” along with: “The system cannot find the file specified”.

What do i need to do to fix this?

Welcome to the community!

Where did you find this? one of the issues is probably the <>.

here’s what it’s supposed to look like

curl https://api.openai.com/v1/audio/speech \
  -H "Authorization: Bearer $OPENAI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "tts-1",
    "input": "The quick brown fox jumped over the lazy dog.",
    "voice": "alloy"
  }' \
  --output speech.mp3

here are the docs: https://platform.openai.com/docs/api-reference/audio/createSpeech


you may also (or not) run into issues with pay as you go. if you get a 429 error after fixing your request, check here: [March 8+] API Error 429...check plan or billing details = Monthly Billed Accounts Switched to Prepaid

2 Likes

I got the code snippet from a link given by my superior, i will try again with your fix, thank you very much. Also it’s a Pay as you go account without chatGPT4 subscription, does that effect the outcome?

nope. you just need a platform account: platform.openai.com.

chatgpt accounts are on chat.openai.com and are completely unrelated to the API.

1 Like

I applies yorr previous fix but now it’s:

“You didn’t provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you’re accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.

Sorry for the barrage of question, and hoppefully this will result it.

Where he wrote this as part of the curl command:

You need to replace that with the API key, either by setting the value OPENAI_API_KEY as an environment variable in your system, or hard-coding the actual text of the key into the script (which you then must keep secure):

curl https://api.openai.com/v1/audio/speech \
  -H "Authorization: Bearer sk-3855nhnfgjadfj3855..." \
1 Like

uh uhm… if by that you mean replace $OPENAI_API_KEY with my actual API key then yes i did, i even revoked the old one and got a new one (i don’t think i used the old one by accident), i didn’t even change anything this time other than “$OPENAI_API_KEY” to my API to see if it work and the result are still:

“You didn’t provide an API key. You need to provide your API key in an Authorization header using Bearer auth (i.e. Authorization: Bearer YOUR_KEY), or as the password field (with blank username) if you’re accessing the API from your browser and are prompted for a username and password. You can obtain an API key from https://platform.openai.com/account/api-keys.
but thank you for the answer.

Are you enclosing it in the greater-than sign like in your first post now edited? That is wrong. It is just the bare string.

Also, I don’t know why you’re using double quotes as escape when you can just quote with single quotes. You would normally have a variable as input, so don’t need to worry about the characters within.

1 Like

yes, i amnew to this and made a lot of mistake, including forgetting to edit out the input, sorry and thanks for the support.

1 Like