There is no way to pass proxy to `AsyncOpenAI`
Confirm this is an issue with the Python library and not an underlying OpenAI API
- [X] This is an issue with the Python library
Describe the bug
The parent of AsyncOpenAI which is AsyncAPIClient Accepts a parameter called proxies. However, there is no way to pass proxies when constructing AsyncOpenAI. This makes it tough to use the library correctly.
Clarification
It's not ideal to pass an HTTP client at all. AsyncAPIClient constructs a special client called AsyncHttpxClientWrapper with certain defaults; therefore it's hard to make a correct client and pass it as http_client
To Reproduce
1- Try to pass proxies param to AsyncOpenAI
2- It will fail as it does not accept proxies as a parameter
Code snippets
AsyncClient(proxies="")
# Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# TypeError: AsyncOpenAI.__init__() got an unexpected keyword argument 'proxies'
OS
Linux
Python version
Pytho v3.12.3
Library version
1.35.10
You can pass proxies by passing a http client, we provide a default client class you can instantiate that uses our defaults.
https://github.com/openai/openai-python?tab=readme-ov-file#configuring-the-http-client
from openai import AsyncOpenAI, DefaultAsyncHttpxClient
client = AsyncOpenAI(
# Or use the `OPENAI_BASE_URL` env var
base_url="http://my.test.server.example.com:8083",
http_client=DefaultHttpxClient(
proxies="http://my.test.proxy.example.com",
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
),
)