Skip to content

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

@alamenai

Description

@alamenai

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions