Issue with Azure OpenAI Client.init got an unexpected keyword argument proxies

I am deploying a Python application (UI built using Streamlit) on Azure App Service.
The app connects to Azure PostgreSQL and Azure OpenAI using the Python SDK.

Everything works correctly on my local machine.
But when the same application runs on Azure App Service, I get this startup error:

Client.init() got an unexpected keyword argument ‘proxies’

This error is thrown by the OpenAI Python SDK.

I create the Azure OpenAI client like this:

from openai import AzureOpenAI
import os

self.openai_client = AzureOpenAI(
api_key=os.environ.get(“AZURE_OPENAI_API_KEY”),
api_version=os.environ.get(“AZURE_OPENAI_API_VERSION”, “2024-12-01-preview”),
azure_endpoint=os.environ.get(“AZURE_OPENAI_ENDPOINT”)
)

I also tried explicitly creating an httpx client:

import httpx
http_client = httpx.Client(proxies=“http:// my-proxy:8080”)

self.openai_client = AzureOpenAI(
api_key=os.environ[“AZURE_OPENAI_API_KEY”],
api_version=os.environ.get(“AZURE_OPENAI_API_VERSION”, “2024-12-01-preview”),
azure_endpoint=os.environ[“AZURE_OPENAI_ENDPOINT”],
http_client=http_client,
)

My suspect:

Azure App Service sets HTTP_PROXY and HTTPS_PROXY environment variables automatically, so the SDK might be trying to create a proxied httpx client.

What I tried: Upgrading and downgrading openai
Passing my own httpx.Client

Fails with the same error above.
How can I solve this? Any suggestion is appreciated. Thank you.

1 Like