#OpenAI API 401 Unauthorized

2 messages · Page 1 of 1 (latest)

worn wolf
#

I keep receiving a '401 Unauthorized - Invalid API Key' HTTP Status Code.

This keep happening no matter the environment or API Key I use.

I have tried using the following programming technologies:
C#.NET - Created an ASP.NET Web Application that talked to a third party OpenAI API library.
JavaScript/Node.js - I have used the library provided by OpenAI as well as used 2 other third party libraries. I build a simple JavaScript Web Application to make the calls, as well as attempted to do this in the console.

I have verified that my environment variables for the OPENAI_API_KEY are being passed properly.

I have revoked my API Key twice now, using my third API key now.

I have not hit my usage cap.

I have internet access.

I am able to use ChatGPT, and all the models in the OpenAI Playground without issue.

I even used ChatGPT and the Codex models in OpenAI Playground to help me work through some issues.

I have read all provided documentation from OpenAI, and all third party libraries I used.

I have verified I'm passing Authorization properly, both the API Key and I have tried included the Organization Key as well.

No matter what I try, the end result is always '401 Unauthorized'.

I contacted support, but they're closed till Monday. Anyone know what the problem could possibly be?

#

const openAI = require('@tectalic/openai').default;

// Test to see if the environment variable is passing the API Key properly.
//console.log(process.env);
console.log(process.env.OPENAI_API_KEY);

const openAIClient = openAI({
headers: {
Authorization: 'Bearer ${process.env.OPENAI_API_KEY}',
'OpenAI-Organization-Key': 'org-xxxxxxxxx'
}
});

openAIClient.completions.create({
model: 'text-davinci-002',
prompt: 'Will using a third party package save time?'
}).then((response) => {
if(response.ok){
console.log(response.data.choices[0].text.trim());
} else {
console.log("Error: ", response.status, response.statusText);
}
}).catch(error => {
console.log("Error: ", error.response.status, error.response.statusText);
});