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
fix: apply Black formatting to 7 files
yuneng-jiang35316e115f68
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/llms/gemini/image_generation/transformation.py b/litellm/llms/gemini/image_generation/transformation.pyindex 795ad275a66..b094fc133d7 100644--- a/litellm/llms/gemini/image_generation/transformation.py+++ b/litellm/llms/gemini/image_generation/transformation.py@@ -98,7 +98,6 @@ class GoogleImageGenConfig(BaseImageGenerationConfig):elif modality == "IMAGE":input_tokens_details.image_tokens += token_count-return ImageUsage(input_tokens=usage_metadata.get("promptTokenCount", 0),input_tokens_details=input_tokens_details,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/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/proxy/common_request_processing.py b/litellm/proxy/common_request_processing.pyindex bad70d30da3..8147d17c10e 100644--- a/litellm/proxy/common_request_processing.py+++ b/litellm/proxy/common_request_processing.py@@ -1004,7 +1004,8 @@ class ProxyBaseLLMRequestProcessing:self.data["deployment"] = llm_router.get_deployment(model_id=model_id)asyncio.create_task(proxy_logging_obj.update_request_status(- litellm_call_id=self.data.get("litellm_call_id", ""), status="success"+ litellm_call_id=self.data.get("litellm_call_id", ""),+ status="success",))if self._is_streaming_request(@@ -1029,11 +1030,13 @@ class ProxyBaseLLMRequestProcessing:)# Call response headers hook for streaming success- callback_headers = await proxy_logging_obj.post_call_response_headers_hook(- data=self.data,- user_api_key_dict=user_api_key_dict,- response=response,- request_headers=dict(request.headers),+ callback_headers = (+ await proxy_logging_obj.post_call_response_headers_hook(+ data=self.data,+ user_api_key_dict=user_api_key_dict,+ response=response,+ request_headers=dict(request.headers),+ ))if callback_headers:custom_headers.update(callback_headers)@@ -1439,7 +1442,8 @@ class ProxyBaseLLMRequestProcessing:)["guardrail_blocked"] = Trueexcept Exception as e:verbose_proxy_logger.exception(- "Error in deferred streaming guardrail initialization: %s", e,+ "Error in deferred streaming guardrail initialization: %s",+ e,)finally:try:@@ -1453,7 +1457,8 @@ class ProxyBaseLLMRequestProcessing:)except Exception as e:verbose_proxy_logger.exception(- "Error in deferred streaming async logging: %s", e,+ "Error in deferred streaming async logging: %s",+ e,)try:@@ -1466,7 +1471,8 @@ class ProxyBaseLLMRequestProcessing:)except Exception as e:verbose_proxy_logger.exception(- "Error in deferred streaming sync logging: %s", e,+ "Error in deferred streaming sync logging: %s",+ e,)async def _handle_llm_api_exception(