Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Uncaught (in promise) Error: Request failed with status code 401 #67

Open
alamenai opened this issue Jun 17, 2023 · 2 comments
Open

Comments

@alamenai
Copy link

Reproduce

  1. Generate the key from the OpenAPI.

  2. Installation

npm install openai-api

  1. 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

Screenshot from 2023-06-18 00-05-24

@weronikazak
Copy link

I've got the same problem. Did you manage to solve it?

@alamenai
Copy link
Author

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 ).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants