From fcdb472ee5cbe2cc719253ff2fa740f44af70ad7 Mon Sep 17 00:00:00 2001 From: Viral Date: Thu, 13 Mar 2025 10:51:18 -0700 Subject: [PATCH] feature: Allow config litellm.api_key and litellm.api_base by environment variables --- litellm/__init__.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/litellm/__init__.py b/litellm/__init__.py index d66707f8b3..439585dfaa 100644 --- a/litellm/__init__.py +++ b/litellm/__init__.py @@ -1,4 +1,11 @@ ### Hide pydantic namespace conflict warnings globally ### +""" + This automatically infers the following arguments from their corresponding environment variables if they are not provided: + - `api_key` from `LITELLM_API_KEY` + - `api_base` from `LITELLM_API_BASE` + + If provided they will be overwritten by provided values +""" import warnings warnings.filterwarnings("ignore", message=".*conflict with protected namespace.*") @@ -155,7 +162,7 @@ drop_params = bool(os.getenv("LITELLM_DROP_PARAMS", False)) modify_params = False retry = True ### AUTH ### -api_key: Optional[str] = None +api_key: Optional[str] = os.getenv("LITELLM_API_KEY") openai_key: Optional[str] = None groq_key: Optional[str] = None databricks_key: Optional[str] = None @@ -328,7 +335,7 @@ def identify(event_details): ####### ADDITIONAL PARAMS ################### configurable params if you use proxy models like Helicone, map spend to org id, etc. -api_base: Optional[str] = None +api_base: Optional[str] = os.getenv("LITELLM_API_BASE") headers = None api_version = None organization = None