From 765e020e75e66bb508df4198899a673fccff27ad Mon Sep 17 00:00:00 2001 From: Ognjen Francuski Date: Tue, 20 Aug 2024 10:16:03 +0200 Subject: [PATCH] Update handling of 'litellm.ssl_verify' in HTTP handlers to allow for custom, self-signed certificates. --- litellm/__init__.py | 2 +- litellm/llms/custom_httpx/http_handler.py | 30 +++++++++++++++++------ 2 files changed, 23 insertions(+), 9 deletions(-) diff --git a/litellm/__init__.py b/litellm/__init__.py index 6c7529477f5..80e76c2efa1 100644 --- a/litellm/__init__.py +++ b/litellm/__init__.py @@ -111,7 +111,7 @@ common_cloud_provider_auth_params: dict = { "providers": ["vertex_ai", "bedrock", "watsonx", "azure", "vertex_ai_beta"], } use_client: bool = False -ssl_verify: bool = True +ssl_verify: Union[str, bool] = True ssl_certificate: Optional[str] = None disable_streaming_logging: bool = False in_memory_llm_clients_cache: dict = {} diff --git a/litellm/llms/custom_httpx/http_handler.py b/litellm/llms/custom_httpx/http_handler.py index 1828a92d2eb..1b3ad5e35e1 100644 --- a/litellm/llms/custom_httpx/http_handler.py +++ b/litellm/llms/custom_httpx/http_handler.py @@ -35,11 +35,18 @@ class AsyncHTTPHandler: self, timeout: Optional[Union[float, httpx.Timeout]], concurrent_limit: int ) -> httpx.AsyncClient: - # Check if the HTTP_PROXY and HTTPS_PROXY environment variables are set and use them accordingly. - ssl_verify = bool(os.getenv("SSL_VERIFY", litellm.ssl_verify)) + # SSL certificates (a.k.a CA bundle) used to verify the identity of requested hosts. + # /path/to/certificate.pem + ssl_verify = os.getenv( + "SSL_VERIFY", + litellm.ssl_verify + ) + # An SSL certificate used by the requested host to authenticate the client. + # /path/to/client.pem cert = os.getenv( - "SSL_CERTIFICATE", litellm.ssl_certificate - ) # /path/to/client.pem + "SSL_CERTIFICATE", + litellm.ssl_certificate + ) if timeout is None: timeout = _DEFAULT_TIMEOUT @@ -212,11 +219,18 @@ class HTTPHandler: if timeout is None: timeout = _DEFAULT_TIMEOUT - # Check if the HTTP_PROXY and HTTPS_PROXY environment variables are set and use them accordingly. - ssl_verify = bool(os.getenv("SSL_VERIFY", litellm.ssl_verify)) + # SSL certificates (a.k.a CA bundle) used to verify the identity of requested hosts. + # /path/to/certificate.pem + ssl_verify = os.getenv( + "SSL_VERIFY", + litellm.ssl_verify + ) + # An SSL certificate used by the requested host to authenticate the client. + # /path/to/client.pem cert = os.getenv( - "SSL_CERTIFICATE", litellm.ssl_certificate - ) # /path/to/client.pem + "SSL_CERTIFICATE", + litellm.ssl_certificate + ) if client is None: # Create a client with a connection pool