#Getting 'invalid_request_url' when trying to connect to API.

1 messages · Page 1 of 1 (latest)

rain patrol
#

I asked ChatGTP to write a node script to connect to it's own API asking a question and passing in the contents of a short file for analysis. Reading the code I can't see any issues with it. I put some logging in, and I see that my API key is taken from my unix shell environment and inserted into the request, so I know it's not the API key, however it returns this error, and I am not sure what is wrong.

{ "error": { "message": "Invalid URL (POST /v1/chatgpt/generate)", "type": "invalid_request_error", "param": null, "code": null } }

The full url that it is using is https://api.openai.com/v1/chatgpt/generate can anyone explain besides the key and the URL what else might throw this error?

`const fs = require('fs');
const request = require('request');

const CHATGPT_URL = 'https://api.openai.com/v1/chatgpt/generate';

// Read the API key from the YOUR_API_KEY environment variable
const API_KEY = process.env.OPENAI_KEY;

// The file path of the file you want to pass to ChatGPT
const filePath = process.argv[2];

// Read the contents of the file
const fileContents = fs.readFileSync(filePath, 'utf8');

// The prompt to pass to ChatGPT
const prompt = Can this thing do things?;

// The options for the ChatGPT request
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Authorization: Bearer ${API_KEY}
},
body: JSON.stringify({
prompt: prompt,
temperature: 0.5,
max_tokens: 100
}),
url: CHATGPT_URL
};

console.log(options);

// Make the request to ChatGPT
request(options, (error, response, body) => {
if (error) {
console.error(error);
return;
}

console.log(body);
});
`