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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
Apply Black formatting to 11 files
yuneng-jiangc6bb7a5be533
diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.pyindex 56f7f305dca..5323f692b80 100644--- a/litellm/litellm_core_utils/litellm_logging.py+++ b/litellm/litellm_core_utils/litellm_logging.py@@ -1686,7 +1686,9 @@ class Logging(LiteLLMLoggingBaseClass):)return logging_result- def _merge_hidden_params_from_response_into_metadata(self, logging_result: Any) -> None:+ def _merge_hidden_params_from_response_into_metadata(+ self, logging_result: Any+ ) -> None:"""Copy response._hidden_params into litellm_params.metadata['hidden_params'].@@ -1704,9 +1706,9 @@ class Logging(LiteLLMLoggingBaseClass):self.model_call_details["litellm_params"].setdefault("metadata", {})if self.model_call_details["litellm_params"]["metadata"] is None:self.model_call_details["litellm_params"]["metadata"] = {}- self.model_call_details["litellm_params"]["metadata"]["hidden_params"] = getattr(- logging_result, "_hidden_params", {}- )+ self.model_call_details["litellm_params"]["metadata"][+ "hidden_params"+ ] = getattr(logging_result, "_hidden_params", {})def _process_hidden_params_and_response_cost(self,diff --git a/litellm/litellm_core_utils/prompt_templates/common_utils.py b/litellm/litellm_core_utils/prompt_templates/common_utils.pyindex 2ef8e89c761..cec61405ebb 100644--- a/litellm/litellm_core_utils/prompt_templates/common_utils.py+++ b/litellm/litellm_core_utils/prompt_templates/common_utils.py@@ -297,7 +297,10 @@ def _insert_user_continue_message(while i < len(result_messages):curr_message = result_messages[i]inserted_continue_message = False- if _counts_for_alternation(curr_message) and curr_message["role"] == "assistant":+ if (+ _counts_for_alternation(curr_message)+ and curr_message["role"] == "assistant"+ ):# Preserve old behavior for malformed adjacent assistant sequences like# assistant(tool_calls) -> assistant(no-tool-calls) with no tool message.if i > 0 and result_messages[i - 1].get("role") == "assistant":@@ -584,7 +587,9 @@ def _decode_vector_store_ids_in_tools(continueparsed = parse_unified_id(vs_id)- provider_resource_id = parsed.get("provider_resource_id") if parsed else None+ provider_resource_id = (+ parsed.get("provider_resource_id") if parsed else None+ )if not provider_resource_id:verbose_logger.warning(diff --git a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.pyindex b9a8d1de488..058d992e4a6 100644--- a/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py+++ b/litellm/llms/anthropic/experimental_pass_through/adapters/transformation.py@@ -869,19 +869,25 @@ class LiteLLMAnthropicMessagesAdapter:# Handle array itemsif "items" in schema:- LiteLLMAnthropicMessagesAdapter._add_additional_properties_false(schema["items"])+ LiteLLMAnthropicMessagesAdapter._add_additional_properties_false(+ schema["items"]+ )# Handle anyOf/oneOf/allOffor key in ("anyOf", "oneOf", "allOf"):if key in schema:for sub_schema in schema[key]:- LiteLLMAnthropicMessagesAdapter._add_additional_properties_false(sub_schema)+ LiteLLMAnthropicMessagesAdapter._add_additional_properties_false(+ sub_schema+ )# Handle $defs / definitionsfor key in ("$defs", "definitions"):if key in schema:for def_schema in schema[key].values():- LiteLLMAnthropicMessagesAdapter._add_additional_properties_false(def_schema)+ LiteLLMAnthropicMessagesAdapter._add_additional_properties_false(+ def_schema+ )def _add_system_message_to_messages(self,diff --git a/litellm/llms/azure_ai/agents/handler.py b/litellm/llms/azure_ai/agents/handler.pyindex 3fbda13d3c7..c3cd06ab4de 100644--- a/litellm/llms/azure_ai/agents/handler.py+++ b/litellm/llms/azure_ai/agents/handler.py@@ -112,9 +112,7 @@ class AzureAIAgentsHandler:text_obj = content_item.get("text", {})content = text_obj.get("value", "")raw_annotations = text_obj.get("annotations")- annotations = self._transform_annotations(- raw_annotations- )+ annotations = self._transform_annotations(raw_annotations)return content, annotationsreturn "", None@@ -146,9 +144,7 @@ class AzureAIAgentsHandler:url_citation["start_index"] = ann["start_index"]if "end_index" in ann and "end_index" not in url_citation:url_citation["end_index"] = ann["end_index"]- result.append(- {"type": "url_citation", "url_citation": url_citation}- )+ result.append({"type": "url_citation", "url_citation": url_citation})else:# Pass through unknown annotation types as-isresult.append(ann)@@ -696,9 +692,7 @@ class AzureAIAgentsHandler:raw_annotations = content_item.get("text", {}).get("annotations")- transformed = self._transform_annotations(- raw_annotations- )+ transformed = self._transform_annotations(raw_annotations)if transformed:if collected_annotations is None:collected_annotations = []diff --git a/litellm/llms/moonshot/chat/transformation.py b/litellm/llms/moonshot/chat/transformation.pyindex c97bd6c4e12..e4d7b5f033b 100644--- a/litellm/llms/moonshot/chat/transformation.py+++ b/litellm/llms/moonshot/chat/transformation.py@@ -168,7 +168,9 @@ class MoonshotChatConfig(OpenAIGPTConfig):if (msg.get("role") == "assistant"and msg.get("tool_calls")- and not msg.get("reasoning_content") # Check using .get() which works for both dicts and Pydantic models+ and not msg.get(+ "reasoning_content"+ ) # Check using .get() which works for both dicts and Pydantic models):patched = dict(cast(dict, msg))provider_fields = patched.get("provider_specific_fields") or {}diff --git a/litellm/llms/openai/chat/gpt_5_transformation.py b/litellm/llms/openai/chat/gpt_5_transformation.pyindex 1a976beac81..fc48704cd10 100644--- a/litellm/llms/openai/chat/gpt_5_transformation.py+++ b/litellm/llms/openai/chat/gpt_5_transformation.py@@ -235,7 +235,9 @@ class OpenAIGPT5Config(OpenAIGPTConfig):elif effective_effort == "minimal":# minimal is opt-out: unknown models pass through; only block when# the model map explicitly sets supports_minimal_reasoning_effort=false.- if self._is_reasoning_effort_level_explicitly_disabled(model, effective_effort):+ if self._is_reasoning_effort_level_explicitly_disabled(+ model, effective_effort+ ):if litellm.drop_params or drop_params:non_default_params.pop("reasoning_effort", None)optional_params.pop("reasoning_effort", None)diff --git a/litellm/llms/ovhcloud/chat/transformation.py b/litellm/llms/ovhcloud/chat/transformation.pyindex 84090fafd31..1416b782f17 100644--- a/litellm/llms/ovhcloud/chat/transformation.py+++ b/litellm/llms/ovhcloud/chat/transformation.py@@ -28,9 +28,7 @@ class OVHCloudChatConfig(OpenAIGPTConfig):"""supports_function_calling: Optional[bool] = Nonetry:- model_info = _get_model_info_helper(- model, custom_llm_provider="ovhcloud"- )+ model_info = _get_model_info_helper(model, custom_llm_provider="ovhcloud")supports_function_calling = model_info.get("supports_function_calling", None)diff --git a/litellm/llms/vertex_ai/gemini/transformation.py b/litellm/llms/vertex_ai/gemini/transformation.pyindex f6310778c71..7945c44d44c 100644--- a/litellm/llms/vertex_ai/gemini/transformation.py+++ b/litellm/llms/vertex_ai/gemini/transformation.py@@ -555,7 +555,9 @@ def _gemini_convert_messages_with_history( # noqa: PLR0915}}if "thought_signature" in invocation:- tc_part["thoughtSignature"] = invocation["thought_signature"]+ tc_part["thoughtSignature"] = invocation[+ "thought_signature"+ ]assistant_content.append(tc_part) # type: ignore# Re-inject toolResponse part if response is present@@ -566,11 +568,11 @@ def _gemini_convert_messages_with_history( # noqa: PLR0915}if invocation.get("tool_type"):tr_dict["toolType"] = invocation["tool_type"]- tr_part: Dict[str, Any] = {- "toolResponse": tr_dict- }+ tr_part: Dict[str, Any] = {"toolResponse": tr_dict}if "thought_signature" in invocation:- tr_part["thoughtSignature"] = invocation["thought_signature"]+ tr_part["thoughtSignature"] = invocation[+ "thought_signature"+ ]assistant_content.append(tr_part) # type: ignoremsg_i += 1diff --git a/litellm/proxy/auth/user_api_key_auth.py b/litellm/proxy/auth/user_api_key_auth.pyindex e2f06abc52f..800cca21dbe 100644--- a/litellm/proxy/auth/user_api_key_auth.py+++ b/litellm/proxy/auth/user_api_key_auth.py@@ -920,9 +920,9 @@ async def _user_api_key_auth_builder( # noqa: PLR0915route=route,)if _end_user_object is not None:- end_user_params["allowed_model_region"] = (- _end_user_object.allowed_model_region- )+ end_user_params[+ "allowed_model_region"+ ] = _end_user_object.allowed_model_regionif _end_user_object.litellm_budget_table is not None:_apply_budget_limits_to_end_user_params(end_user_params=end_user_params,@@ -1499,9 +1499,9 @@ async def _user_api_key_auth_builder( # noqa: PLR0915if _end_user_object is not None:valid_token_dict.update(end_user_params)- valid_token_dict["end_user_object_permission"] = (- _end_user_object.object_permission- )+ valid_token_dict[+ "end_user_object_permission"+ ] = _end_user_object.object_permission# check if token is from litellm-ui, litellm ui makes keys to allow users to login with sso. These keys can only be used for LiteLLM UI functions# sso/login, ui/login, /key functions and /user functionsdiff --git a/litellm/responses/litellm_completion_transformation/transformation.py b/litellm/responses/litellm_completion_transformation/transformation.pyindex 8da2a5e7c67..b6479a36998 100644--- a/litellm/responses/litellm_completion_transformation/transformation.py+++ b/litellm/responses/litellm_completion_transformation/transformation.py@@ -232,9 +232,7 @@ class LiteLLMCompletionResponsesConfig:# only pass non-None valueslitellm_completion_request = {- k: v- for k, v in litellm_completion_request.items()- if v is not None+ k: v for k, v in litellm_completion_request.items() if v is not None}return litellm_completion_requestdiff --git a/litellm/router_utils/pre_call_checks/deployment_affinity_check.py b/litellm/router_utils/pre_call_checks/deployment_affinity_check.pyindex 728e689eaab..148b7fce0ee 100644--- a/litellm/router_utils/pre_call_checks/deployment_affinity_check.py+++ b/litellm/router_utils/pre_call_checks/deployment_affinity_check.py@@ -70,9 +70,7 @@ class DeploymentAffinityCheck(CustomLogger):self.VALID_FLAGS,)- def _get_effective_flags(- self, model_group: str- ) -> Tuple[bool, bool, bool]:+ def _get_effective_flags(self, model_group: str) -> Tuple[bool, bool, bool]:"""Return (enable_user_key_affinity, enable_responses_api_affinity, enable_session_id_affinity)for the given model group.@@ -316,9 +314,11 @@ class DeploymentAffinityCheck(CustomLogger):request_kwargs = request_kwargs or {}typed_healthy_deployments = cast(List[dict], healthy_deployments)- enable_user_key, enable_responses_api, enable_session_id = (- self._get_effective_flags(model)- )+ (+ enable_user_key,+ enable_responses_api,+ enable_session_id,+ ) = self._get_effective_flags(model)# 1) Responses API continuity (high priority)if enable_responses_api:@@ -458,9 +458,11 @@ class DeploymentAffinityCheck(CustomLogger):return None# Resolve effective flags for this model group- enable_user_key, _enable_responses_api, enable_session_id = (- self._get_effective_flags(deployment_model_name)- )+ (+ enable_user_key,+ _enable_responses_api,+ enable_session_id,+ ) = self._get_effective_flags(deployment_model_name)if not enable_user_key and not enable_session_id:return None