Skip to content

The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]

Fix:test_aaaaazure_tenant_id_auth

Sameer Kankutecd96c8cbb0b9
diff --git a/litellm/llms/azure/azure.py b/litellm/llms/azure/azure.py
index 3ef0186ba0e..7250d6fc94c 100644
--- a/litellm/llms/azure/azure.py
+++ b/litellm/llms/azure/azure.py
@@ -215,7 +215,7 @@ class AzureChatCompletion(BaseAzureLLM, BaseLLM):
### CHECK IF CLOUDFLARE AI GATEWAY ###
### if so - set the model as part of the base url
- if "gateway.ai.cloudflare.com" in api_base:
+ if api_base is not None and "gateway.ai.cloudflare.com" in api_base:
client = self._init_azure_client_for_cloudflare_ai_gateway(
api_base=api_base,
model=model,
@@ -1338,7 +1338,7 @@ class AzureChatCompletion(BaseAzureLLM, BaseLLM):
prompt: Optional[str] = None,
) -> dict:
client_session = litellm.client_session or httpx.Client()
- if "gateway.ai.cloudflare.com" in api_base:
+ if api_base is not None and "gateway.ai.cloudflare.com" in api_base:
## build base url - assume api base includes resource name
if not api_base.endswith("/"):
api_base += "/"
diff --git a/litellm/llms/custom_httpx/http_handler.py b/litellm/llms/custom_httpx/http_handler.py
index 7fdb78c1670..57a6d04c995 100644
--- a/litellm/llms/custom_httpx/http_handler.py
+++ b/litellm/llms/custom_httpx/http_handler.py
@@ -1168,8 +1168,10 @@ def get_async_httpx_client(
return _cached_client
if params is not None:
- params["shared_session"] = shared_session
- _new_client = AsyncHTTPHandler(**params)
+ # Filter out params that are only used for cache key, not for AsyncHTTPHandler.__init__
+ handler_params = {k: v for k, v in params.items() if k != "disable_aiohttp_transport"}
+ handler_params["shared_session"] = shared_session
+ _new_client = AsyncHTTPHandler(**handler_params)
else:
_new_client = AsyncHTTPHandler(
timeout=httpx.Timeout(timeout=600.0, connect=5.0),
@@ -1215,7 +1217,9 @@ def _get_httpx_client(params: Optional[dict] = None) -> HTTPHandler:
return _cached_client
if params is not None:
- _new_client = HTTPHandler(**params)
+ # Filter out params that are only used for cache key, not for HTTPHandler.__init__
+ handler_params = {k: v for k, v in params.items() if k != "disable_aiohttp_transport"}
+ _new_client = HTTPHandler(**handler_params)
else:
_new_client = HTTPHandler(timeout=httpx.Timeout(timeout=600.0, connect=5.0))
diff --git a/litellm/llms/openai/common_utils.py b/litellm/llms/openai/common_utils.py
index 9f1ec9250cf..8bcecd35232 100644
--- a/litellm/llms/openai/common_utils.py
+++ b/litellm/llms/openai/common_utils.py
@@ -212,7 +212,8 @@ class BaseOpenAILLM:
try:
# Get SSL config and include in params for proper cache key
ssl_config = get_ssl_configuration()
- params = {"ssl_verify": ssl_config} if ssl_config is not None else None
+ params = {"ssl_verify": ssl_config} if ssl_config is not None else {}
+ params["disable_aiohttp_transport"] = litellm.disable_aiohttp_transport
# Get a cached AsyncHTTPHandler which manages the httpx.AsyncClient
cached_handler = get_async_httpx_client(
diff --git a/tests/local_testing/test_azure_openai.py b/tests/local_testing/test_azure_openai.py
index ed0dda3e15a..e95c1b6fcce 100644
--- a/tests/local_testing/test_azure_openai.py
+++ b/tests/local_testing/test_azure_openai.py
@@ -41,6 +41,11 @@ async def test_aaaaazure_tenant_id_auth(respx_mock: MockRouter):
PROD Test
"""
litellm.disable_aiohttp_transport = True # since this uses respx, we need to set use_aiohttp_transport to False
+
+ # Clear the HTTP client cache to ensure respx mocking works
+ # This is critical because respx only intercepts clients created AFTER mocking is active
+ if hasattr(litellm, 'in_memory_llm_clients_cache'):
+ litellm.in_memory_llm_clients_cache.flush_cache()
router = Router(
model_list=[