From 9022d144a6845286b81d801557a2482fc2b37005 Mon Sep 17 00:00:00 2001 From: Ishaan Jaff Date: Mon, 21 Jul 2025 15:01:43 -0700 Subject: [PATCH] [Bug Fix] - gemini leaking FD for sync calls with litellm.completion (#12824) * bug fix - gemini leaking FD for sync calls * fixes for leaking FD --- litellm/llms/anthropic/chat/handler.py | 5 ++++- .../vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py | 3 ++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/litellm/llms/anthropic/chat/handler.py b/litellm/llms/anthropic/chat/handler.py index 04cf66cf021..620d2f05119 100644 --- a/litellm/llms/anthropic/chat/handler.py +++ b/litellm/llms/anthropic/chat/handler.py @@ -27,6 +27,7 @@ from litellm.litellm_core_utils.core_helpers import map_finish_reason from litellm.llms.custom_httpx.http_handler import ( AsyncHTTPHandler, HTTPHandler, + _get_httpx_client, get_async_httpx_client, ) from litellm.types.llms.anthropic import ( @@ -433,7 +434,9 @@ class AnthropicChatCompletion(BaseLLM): else: if client is None or not isinstance(client, HTTPHandler): - client = HTTPHandler(timeout=timeout) # type: ignore + client = _get_httpx_client( + params={"timeout": timeout} + ) else: client = client diff --git a/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py b/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py index d09599e8789..e4a68dd82e0 100644 --- a/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py +++ b/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py @@ -35,6 +35,7 @@ from litellm.llms.base_llm.chat.transformation import BaseConfig, BaseLLMExcepti from litellm.llms.custom_httpx.http_handler import ( AsyncHTTPHandler, HTTPHandler, + _get_httpx_client, get_async_httpx_client, ) from litellm.types.llms.anthropic import AnthropicThinkingParam @@ -1881,7 +1882,7 @@ class VertexLLM(VertexBase): if isinstance(timeout, float) or isinstance(timeout, int): timeout = httpx.Timeout(timeout) _params["timeout"] = timeout - client = HTTPHandler(**_params) # type: ignore + client = _get_httpx_client(params=_params) else: client = client