OpenAI API is working on Google Colab but giving timeout error in VSCode

Hello, I have a project to finish very soon. So while I have properly executed all the other tasks but when it comes to the OpenAI integration, for whatever reason it is not working on VSCode. So, I checked the same code on Google Colab and it seamlessly gave me results. When I try on VSCode, I get:
raise APITimeoutError(request=request) from err
openai.APITimeoutError: Request timed out.

Tried everything under the sun: turning off firewall, upgrading python. packages, libraries, creating virtual environment, increasing timeout, etc. I am genuinely frustrated right now. Can someone guide me how to go about from here?

Vscode is an interface, not a language or even a server.

For whatever reason your computer is timing out while Colab isn’t. It can be a wide variety of things.

We can’t help without information. You can start by posting your code.

1 Like
from openai import OpenAI
client = OpenAI(api_key='SECRET KEY')

response = client.chat.completions.create(
  model="gpt-3.5-turbo",
  messages=[
    {
      "role": "system",
      "content": "You will be provided with a block of text, and your task is to extract a list of keywords from it."
    },
    {
      "role": "user",
      "content": "Black-on-black ware is a 20th- and 21st-century pottery tradition developed by the Puebloan Native American ceramic artists in Northern New Mexico. Traditional reduction-fired blackware has been made for centuries by pueblo artists. Black-on-black ware of the past century is produced with a smooth surface, with the designs applied through selective burnishing or the application of refractory slip. Another style involves carving or incising designs and selectively polishing the raised areas. For generations several families from Kha'po Owingeh and P'ohwhĂłge Owingeh pueblos have been making black-on-black ware with the techniques passed down from matriarch potters. Artists from other pueblos have also produced black-on-black ware. Several contemporary artists have created works honoring the pottery of their ancestors."
    }
  ],
  temperature=0.5,
  max_tokens=64,
  top_p=1
)

print(response)

I am just running this file and I am also getting this error:
httpx.ConnectTimeout: timed out

Check Network Configuration:
Check Environment Configuration:
Check for Proxy Issues:

If it’s running elsewhere but not local, it’s likely a problem with your network.

2 Likes

I am trying to run it locally.

Hi @geto_may

Welcome to the dev forum.

I’d recommend trying with streaming.

Additionally you can also specify a timeout using the timeout param while instantiating the client.

1 Like

Hello, I have tried both but I still can’t bypass this error :smiling_face_with_tear:

Where are you located and are you running any proxies VPNs or using a work network? Have you tried turning off your anti-virus?

Simply see if network is functional for you at all. VSCode as an application or Python might not have been set to make network connections through your firewall, either OS firewall or some proprietary wannabe app firewall.

Thank you for this. I am getting timeout when trying to access the website. Can you please guide me on the next steps?

Contact whoever is responsible for maintaining the network you are on.

It sounds as though you likely didn’t have enough information yourself to be able to help anyone else debug your issue.