From 6e351136d7588c21519c54846329da8785af45a0 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Tue, 18 Mar 2025 08:56:08 -0700 Subject: [PATCH] handle _get_async_http_client for OpenAI --- litellm/llms/openai/openai.py | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/litellm/llms/openai/openai.py b/litellm/llms/openai/openai.py index 880a043d08a..a5e33795c82 100644 --- a/litellm/llms/openai/openai.py +++ b/litellm/llms/openai/openai.py @@ -370,7 +370,7 @@ class OpenAIChatCompletion(BaseLLM): _new_client: Union[OpenAI, AsyncOpenAI] = AsyncOpenAI( api_key=api_key, base_url=api_base, - http_client=litellm.aclient_session, + http_client=OpenAIChatCompletion._get_async_http_client(), timeout=timeout, max_retries=max_retries, organization=organization, @@ -379,7 +379,7 @@ class OpenAIChatCompletion(BaseLLM): _new_client = OpenAI( api_key=api_key, base_url=api_base, - http_client=litellm.client_session, + http_client=OpenAIChatCompletion._get_sync_http_client(), timeout=timeout, max_retries=max_retries, organization=organization, @@ -401,6 +401,28 @@ class OpenAIChatCompletion(BaseLLM): ) return client + @staticmethod + def _get_async_http_client() -> Optional[httpx.AsyncClient]: + if litellm.ssl_verify: + return httpx.AsyncClient( + limits=httpx.Limits( + max_connections=1000, max_keepalive_connections=100 + ), + verify=litellm.ssl_verify, + ) + return litellm.aclient_session + + @staticmethod + def _get_sync_http_client() -> Optional[httpx.Client]: + if litellm.ssl_verify: + return httpx.Client( + limits=httpx.Limits( + max_connections=1000, max_keepalive_connections=100 + ), + verify=litellm.ssl_verify, + ) + return litellm.client_session + @track_llm_api_timing() async def make_openai_chat_completion_request( self,