I tried a GET request for an SQL result from OpenAI SQL query API, but when I clicked I have the error and in console this error appear from image, please any can help me to fix that.
Asked
Active
Viewed 65 times
0
-
3Does this answer your question? [How does the 'Access-Control-Allow-Origin' header work?](https://stackoverflow.com/questions/10636611/how-does-the-access-control-allow-origin-header-work) (Or any of the many, many other questions found when searching the exact error message...) – David Jul 06 '23 at 12:45
-
1What does your `fetch` call look like? Please include that in your post. – Mr. Polywhirl Jul 06 '23 at 13:15
1 Answers
0
I found your same issue on openAI community.
OpenAI has CORS blocked for security reason. You shouldn't call openAI Api from your client, you are exposing your api key. Anyone can see your website code and steal your key.
You could use a proxy server or reverse proxy like NGINX to forward the request adding Access-Contro-Allow-Origin: * (or your website domain).
(This is just a bypass but it doesn't fix the security issue)
A better solution is to create a backend service (with node if you are familiar with js/ts), which can handle user authentication and mask your openAI api calls.

Marco Morozzi
- 36
- 4