openai / openai-quickstart-node

Node.js example app from the OpenAI API quickstart tutorial
https://platform.openai.com/docs/quickstart?context=node
MIT License
2.55k stars 1.99k forks source link

[403 Forbidden]The OpenAI API can only be accessed over HTTPS. #48

Closed lyf61 closed 1 year ago

lyf61 commented 1 year ago

Describe the bug

request header Request URL: http://localhost:3000/api/generate Request Method: POST Status Code: 403 Forbidden

response {"error":{"message":"The OpenAI API can only be accessed over HTTPS. You should access https://api.openai.com rather than the current URL.","type":"invalid_request_error"}}

To Reproduce

the alert showed after clicked on the Generate names button

OS

macOS

Node version

v14.18.1

logankilpatrick commented 1 year ago

Can you share the full request you are passing in?

christopherwolf1 commented 1 year ago

I am also getting this error (macOS); running the openai-quickstart-node codebase with no modification

Relevant request in my case is this part of the try block

try { const response = await fetch("/api/generate", { method: "POST", headers: { "Content-Type": "application/json", }, body: JSON.stringify({ animal: animalInput }), });

Interestingly, I have my own code that uses a POST request and doesn't trigger the 403 error; there shouldn't really be any difference and I would expect the official quickstart to work out of the box

nitin-787 commented 1 year ago

I am also getting the same error, but while testing in postman it just works fine

here is my code

Note : I also tried using https instead http

`import 'dart:convert';

import 'package:chatgpt/constants/api_consts.dart'; import 'package:http/http.dart' as http;

class ApiService { static Future getModels() async { try { var response = await http.get( Uri.parse("$BASE_URL/models"), headers: {'Authorization': 'Bearer $API_KEY'}, );

  Map jsonResponse = jsonDecode(response.body);
  print("response $jsonResponse");
} catch (error) {
  print("error $error");
}

} } `

nitin-787 commented 1 year ago

hey in the morning i was also getting the same issue, but now it is resolve the issue had came because of my silly mistake

here is my solution @lyf61

solve this just removing the slash from the like

"https://api.openai.com/v1/"; ----> "https://api.openai.com/v1";

you can close this sir @logankilpatrick

lyf61 commented 1 year ago

problem solved after i turn off VPN.

nitin-787 commented 1 year ago

problem solved after i turn off VPN.

lol

furkanbora239 commented 1 year ago

i dont use vpn and my error look like html

<html>

<head>
    <title>403 Forbidden</title>
</head>

<body>
    <center>
        <h1>403 Forbidden</h1>
    </center>
    <hr>
    <center>cloudflare</center>
</body>

</html>