API error for chat completion :Error bad gateway 502

Hello!, I have been having problem with the chat completions via openai, it is throwing 502 bad gateway for every 4-5 questions that I am asking via the api. Is this a running issue or any update on this and how to handle it.
Thank you.

Hi and welcome to the Developer Forum!

The API endpoints are very busy and you may encounter connection errors, you should ensure your code gracefully handles all connection and potential timeout problem that will occur from time to time with remote API based services.

The Error Codes Page has some sample code that you should try using, this is how the above user was able to solve the issue.

Here’s the relevant code I’m referring to:

import openai
from openai import OpenAI
client = OpenAI()

try:
  #Make your OpenAI API request here
  response = client.completions.create(
    prompt="Hello world",
    model="gpt-3.5-turbo-instruct"
  )
except openai.APIError as e:
  #Handle API error here, e.g. retry or log
  print(f"OpenAI API returned an API Error: {e}")
  pass
except openai.APIConnectionError as e:
  #Handle connection error here
  print(f"Failed to connect to OpenAI API: {e}")
  pass
except openai.RateLimitError as e:
  #Handle rate limit error (we recommend using exponential backoff)
  print(f"OpenAI API request exceeded rate limit: {e}")
  pass

Hi @Foxabilo Thanks, actually today it has been happening many times so I wanted to check if there is a known issue currently happening.

thanks @trenton.dambrowitz, I will check them out.

1 Like

Been facing this the whole of today. Since this is a paid API, is there any support on rectifying possible infra issues from OpenAI? Couldn’t find any updates on the status page either. Wondering whom to follow up with regarding this.

Hi and welcome to the Developer Forum!

You can contact help.openai.com and use the support bot in the bottom right corner, but these kinds of issues are usually transitory and may last a day or two while systems get upgraded and new updates rolled out. AI is a very fast moving industry and unfortunately that comes with an expectation of some intermittent issues while brand new systems are brought online.

Thanks Foxabilo. Raised an issue with Fin. Hope that counts!

1 Like