简体   繁体   中英

Why is my API key triggering an error in openAI call?

The API key is working when I enter it manually in the object initialisation, but when I try to use a .env variable then an error is triggered.

This is what i've done and it doesn't work:

const APIKEY = process.env.OPENAI_API_KEY;
const configuration = new Configuration({
  apiKey: APIKEY,
});

if I console.log(process.env.OPENAI_API_KEY) it prints the correct API key. So what am I doing wrong here?

Here is the error:

在此处输入图像描述

Do you see that period at the end of the key in your error message? Make sure that's not in.env. I just had a similar problem with a semicolon.

The API keys have a different format, as the error message says it's incorrect. All API keys start with sk- . Try checking if you used a correct one.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM