Error: Uncaught (in promise) Error: Request failed with status code 401
alamenai opened this issue · 2 comments
alamenai commented
Reproduce
-
Generate the key from the OpenAPI.
-
Installation
npm install openai-api
- Copy/past the example in my NextJS component ( Button )
const sendRequest = async (event: React.MouseEvent<HTMLImageElement>) => {
const request = {
title: prompt,
output: 'Done',
};
setRequests(request);
const gptResponse = await openai.complete({
engine: 'davinci',
prompt: 'this is a test',
maxTokens: 5,
temperature: 0.9,
topP: 1,
presencePenalty: 0,
frequencyPenalty: 0,
bestOf: 1,
n: 1,
stream: false,
stop: ['\n', 'testing'],
});
console.log(gptResponse.data);
};
Expected
Print the result
Current
createError.js?6b1b:16 Uncaught (in promise) Error: Request failed with status code 401
at createError (webpack-internal:///(:3000/app-client)/./node_modules/openai-api/node_modules/axios/lib/core/createError.js:16:15)
at settle (webpack-internal:///(:3000/app-client)/./node_modules/openai-api/node_modules/axios/lib/core/settle.js:17:12)
at XMLHttpRequest.onloadend (webpack-internal:///(:3000/app-client)/./node_modules/openai-api/node_modules/axios/lib/adapters/xhr.js:54:7)
Screenshot
weronikazak commented
I've got the same problem. Did you manage to solve it?
MenaiAla commented
I've got the same problem. Did you manage to solve it?
Based on the response status it means you are not authorized to use API. When I read the documentation I understand that the API token has limitation usage for free ( total of tokens per day ).