Azure Open AI Assistant API connection error

Hi, I am attempting to create an assistant via Azure Open AI Assistant API and am getting a connection error.

          assistant = client.beta.assistants.create(
              tools=[{"type": "retrieval"}, {"type": "code_interpreter"}],
          assistant_id =

          # ai_assistants = client.beta.assistants.list(
          #     order="desc",
          #     limit="20",
          # )
      except Exception as e:

The Azure Endpoint is this: AZURE_OPENAI_ENDPOINT=https://[myresource]

I also tried AZURE_OPENAI_ENDPOINT=https://[myresource] with the same error. Screenshot attached.

The client.beta.assistants.list() function produces the same error.

1 Like

Here’s how you can consume Azure OpenAI service with the OpenAI python package.

1 Like

Particularly, you’ll need to use your model deployment name besides the different library methods.

Hmm, so I updated the code to include the azure_deployment parameter in the model and I still get the connection error. Do you know if there is something specific to Azure that needs to happen? The deployed model is exactly what’s in the code, gpt-4 1106-Preview.

client = AzureOpenAI(
            azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"),
1 Like

It is the model name that you must replace with the deployment name. It often can be the same, but you are also given an opportunity to rename it.

Then more modifications in your use of the OpenAI python library, as outlined in my link above.

from openai import AzureOpenAI
client = AzureOpenAI(
    azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT")

If this is the first of any use of OpenAI Azure services, I’d start with chat completions and see that you get a simple response there.

More, if using entra ID:

from azure.identity import DefaultAzureCredential, get_bearer_token_provider
from openai import AzureOpenAI

token_provider = get_bearer_token_provider(
    DefaultAzureCredential(), ""

api_version = "2023-12-01-preview"
endpoint = ""

client = AzureOpenAI(
1 Like

Primero tienes que verificar la Clave de la API, que sea verificada y tenga validez, comprobar el punto inicial de conexión de la API, asegurar los parámetros, y como siempre digo utilicen la Documentación, si esta desactualizada, pregunten al area de ayuda… inspeccionen la conectividad con Internet, sea local, global, etc que no existan firewalls, cortadores que son de los mas antiguos, o tambien VPNs o bloqueadores, por el desarrollo, disponibilidad de direcciones regionales que confirme el modelo general. Tambien reúna información con descripciones… por ultimo para resolución de problemas, actualización de Software, si no tenemos eso, cambiar dispositivos físicos, bibliotecas de Clientes, aprovechar registro Azure; y verificar estado de la API ¡Saludos!

1 Like

When I am trying to run Python code for Azure OpenAI API Chat Completions locally, providing all required parameters, it is giving me below error intermittently. Need your help, if you could suggest how this could be resolved.

httpcore.ConnectError: [Errno 11001] getaddrinfo failed
The above exception was the direct cause of the following exception:
httpx.ConnectError: [Errno 11001] getaddrinfo failed
The above exception was the direct cause of the following exception:
raise APIConnectionError(request=request) from err
openai.APIConnectionError: Connection error.

Hey, not sure if this will help you, but here is what worked for me for Azure Open AI Chat completions:

Screenshot from 2024-03-27 08-48-18
Screenshot from 2024-03-27 08-47-57

Thanks for sharing. We have the same code & it’s working in AWS EC2 environment, but problem lies (connection error) when we run it from local internet connection.
By the way, when you say worked , you run it in your local internet connection or any other organization internet etc.

Hey, for us it’s working on the corporate network.

Ok, not in your local network…right? we have the same problem. but not sure why?

Sorry, I wasn’t clear - the code works both locally and on the corporate network when deployed to production.