diff --git a/litellm/litellm_core_utils/credential_accessor.py b/litellm/litellm_core_utils/credential_accessor.py new file mode 100644 index 0000000000..d38fd58f6d --- /dev/null +++ b/litellm/litellm_core_utils/credential_accessor.py @@ -0,0 +1,15 @@ +"""Utils for accessing credentials.""" + +import litellm + + +class CredentialAccessor: + @staticmethod + def get_credential_values(credential_name: str) -> dict: + """Safe accessor for credentials.""" + if not litellm.credential_list: + return {} + for credential in litellm.credential_list: + if credential.credential_name == credential_name: + return credential.credential_values.copy() + return {} diff --git a/litellm/proxy/_new_secret_config.yaml b/litellm/proxy/_new_secret_config.yaml index 84b18925b2..4de9b76348 100644 --- a/litellm/proxy/_new_secret_config.yaml +++ b/litellm/proxy/_new_secret_config.yaml @@ -2,7 +2,7 @@ model_list: - model_name: gpt-4o litellm_params: model: azure/gpt-4o - credential_name: default_azure_credential + litellm_credential_name: default_azure_credential credential_list: - credential_name: default_azure_credential diff --git a/litellm/router.py b/litellm/router.py index 940b02c78c..7751de8ce3 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -5370,18 +5370,18 @@ class Router: client = self.cache.get_cache( key=cache_key, local_only=True, parent_otel_span=parent_otel_span ) - if client is None: - """ - Re-initialize the client - """ - InitalizeOpenAISDKClient.set_client( - litellm_router_instance=self, model=deployment - ) - client = self.cache.get_cache( - key=cache_key, - local_only=True, - parent_otel_span=parent_otel_span, - ) + # if client is None: + # """ + # Re-initialize the client + # """ + # InitalizeOpenAISDKClient.set_client( + # litellm_router_instance=self, model=deployment + # ) + # client = self.cache.get_cache( + # key=cache_key, + # local_only=True, + # parent_otel_span=parent_otel_span, + # ) return client else: if kwargs.get("stream") is True: diff --git a/litellm/types/utils.py b/litellm/types/utils.py index d1bfaac4ef..0c5d374517 100644 --- a/litellm/types/utils.py +++ b/litellm/types/utils.py @@ -1815,6 +1815,7 @@ all_litellm_params = [ "budget_duration", "use_in_pass_through", "merge_reasoning_content_in_choices", + "litellm_credential_name", ] + list(StandardCallbackDynamicParams.__annotations__.keys()) diff --git a/litellm/utils.py b/litellm/utils.py index ce5acbc694..f2434f877b 100644 --- a/litellm/utils.py +++ b/litellm/utils.py @@ -66,6 +66,7 @@ from litellm.litellm_core_utils.core_helpers import ( map_finish_reason, process_response_headers, ) +from litellm.litellm_core_utils.credential_accessor import CredentialAccessor from litellm.litellm_core_utils.default_encoding import encoding from litellm.litellm_core_utils.exception_mapping_utils import ( _get_response_headers, @@ -141,6 +142,7 @@ from litellm.types.utils import ( ChatCompletionMessageToolCall, Choices, CostPerToken, + CredentialItem, CustomHuggingfaceTokenizer, Delta, Embedding, @@ -455,6 +457,18 @@ def get_applied_guardrails(kwargs: Dict[str, Any]) -> List[str]: return applied_guardrails +def load_credentials_from_list(kwargs: dict): + """ + Updates kwargs with the credentials if credential_name in kwarg + """ + credential_name = kwargs.get("litellm_credential_name") + if credential_name and litellm.credential_list: + credential_accessor = CredentialAccessor.get_credential_values(credential_name) + for key, value in credential_accessor.items(): + if key not in kwargs: + kwargs[key] = value + + def get_dynamic_callbacks( dynamic_callbacks: Optional[List[Union[str, Callable, CustomLogger]]] ) -> List: @@ -485,6 +499,9 @@ def function_setup( # noqa: PLR0915 ## GET APPLIED GUARDRAILS applied_guardrails = get_applied_guardrails(kwargs) + ## LOAD CREDENTIALS + load_credentials_from_list(kwargs) + ## LOGGING SETUP function_id: Optional[str] = kwargs["id"] if "id" in kwargs else None