CORS Error. Am I doing something wrong?

Every once in a while, I send GPT a prompt, and I will get no response. After getting tired of waiting, I can start sending it more prompts or repeat the last prompt, and start getting responses again like normal, but then my console logs the error from the ignored prompt

Access to fetch at 'https://api.openai.com/v1/chat/completions' from origin 'https://<mywebsite>.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.       
        
POST https://api.openai.com/v1/chat/completions net::ERR_FAILED 502 (Bad Gateway)

I’ve already added the following lines to .htaccess, so I assume this is something on OpenAI’s side?

Header set Access-Control-Allow-Origin https://openai.com
Header set Access-Control-Allow-Origin https://api.openai.com
1 Like

I have encountered the same situation as you did. Have you find out the soluton or where the issue from?

I have encountered the same situation too. Have you solved this problem?

Welcome to the community!

Please don’t do this, because then your next post will be “OpenAI keeps charging me despite me not using it!!!”

https://help.openai.com/en/articles/5112595-best-practices-for-api-key-safety

That’s irrelevant to the topic, and just random. IDK if you’re a bot, or just lost.

I have not figured out a direct cause or resolution. Since project is intended to run as a PWA, and as my development has winded down, I’m not paying attention to the dev console. However, If I recall correctly, I do have a work around in place. I’ve implemented a timeout in my fetch call. If fetch times out, it will retry up to 3 times.