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
refactor(types): replace Any with proven types in 5 files (#42722)
devin-ai-integration[bot]860bc7811deb
diff --git a/litellm/_logging.py b/litellm/_logging.pyindex 8bd7a86ecf5..802b01b2e90 100644--- a/litellm/_logging.py+++ b/litellm/_logging.py@@ -9,7 +9,7 @@ import sysfrom collections.abc import Iteratorfrom datetime import datetimefrom logging import Formatter-from typing import Any, Final, TextIO+from typing import Final, TextIOfrom urllib.parse import unquoteimport litellm@@ -672,13 +672,13 @@ def _try_parse_json_message(message: str) -> dict[str, object] | None:msg_stripped: Final = message.strip()if not (msg_stripped.startswith("{") or msg_stripped.startswith("[")):return None- parsed: Final = safe_json_loads(message, default=None)+ parsed: Final[object] = safe_json_loads(message, default=None)if parsed is None or not isinstance(parsed, dict):return Nonereturn parsed-def _try_parse_embedded_python_dict(message: str) -> dict[str, Any] | None:+def _try_parse_embedded_python_dict(message: str) -> dict[str, object] | None:"""Try to find and parse a Python dict repr (e.g. str(d) or repr(d)) embedded inthe message. Handles patterns like:@@ -702,7 +702,7 @@ def _try_parse_embedded_python_dict(message: str) -> dict[str, Any] | None:if depth == 0:substr = message[start : j + 1]try:- result = ast.literal_eval(substr)+ result: object = ast.literal_eval(substr)if isinstance(result, dict) and len(result) > 0:return resultexcept (ValueError, SyntaxError, TypeError):diff --git a/litellm/llms/bedrock/chat/invoke_transformations/amazon_twelvelabs_pegasus_transformation.py b/litellm/llms/bedrock/chat/invoke_transformations/amazon_twelvelabs_pegasus_transformation.pyindex fe287111fdd..f4867f8dfc0 100644--- a/litellm/llms/bedrock/chat/invoke_transformations/amazon_twelvelabs_pegasus_transformation.py+++ b/litellm/llms/bedrock/chat/invoke_transformations/amazon_twelvelabs_pegasus_transformation.py@@ -67,7 +67,7 @@ class AmazonTwelveLabsPegasusConfig(AmazonInvokeConfig, BaseConfig):optional_params["responseFormat"] = self._normalize_response_format(value)return optional_params- def _normalize_response_format(self, value: Any) -> Any:+ def _normalize_response_format(self, value: Any) -> object:"""Normalize response_format to TwelveLabs format.TwelveLabs expects:diff --git a/litellm/llms/sap/chat/transformation.py b/litellm/llms/sap/chat/transformation.pyindex 4c73ccacc16..2955b8f16c5 100755--- a/litellm/llms/sap/chat/transformation.py+++ b/litellm/llms/sap/chat/transformation.py@@ -358,13 +358,13 @@ class GenAIHubOrchestrationConfig(OpenAIGPTConfig):))- config_payload: Final[dict[str, Any]] = {+ config_payload: Final[dict[str, object]] = {"modules": modules if len(modules) > 1 else modules[0],}if stream_config:config_payload["stream"] = stream_config- request_body: Final[dict[str, Any]] = {"config": config_payload}+ request_body: Final[dict[str, object]] = {"config": config_payload}if placeholder_values is not None:request_body["placeholder_values"] = placeholder_valuesdiff --git a/litellm/proxy/guardrails/guardrail_hooks/pangea/pangea.py b/litellm/proxy/guardrails/guardrail_hooks/pangea/pangea.pyindex 5acf837cf84..aa61d98e76f 100644--- a/litellm/proxy/guardrails/guardrail_hooks/pangea/pangea.py+++ b/litellm/proxy/guardrails/guardrail_hooks/pangea/pangea.py@@ -1,6 +1,6 @@# litellm/proxy/guardrails/guardrail_hooks/pangea.pyimport os-from typing import TYPE_CHECKING, Any, Final, cast+from typing import TYPE_CHECKING, Finalfrom fastapi import HTTPException@@ -230,7 +230,7 @@ class PangeaHandler(CustomGuardrail):messages: Final = data.get("messages")if messages is None:return # No messages to check- input_messages = cast(list[dict[Any, Any]], messages)+ input_messages = messageselse:returndiff --git a/litellm/proxy/types_utils/utils.py b/litellm/proxy/types_utils/utils.pyindex c5d0b716db7..a85a96aecfd 100644--- a/litellm/proxy/types_utils/utils.py+++ b/litellm/proxy/types_utils/utils.py@@ -52,7 +52,7 @@ def get_instance_fn(value: str, config_file_path: str | None = None) -> Any:module = importlib.import_module(module_name)# Get the instance from the module- instance: Final = getattr(module, instance_name)+ instance: Final[object] = getattr(module, instance_name)return instanceexcept ImportError as e:@@ -167,7 +167,7 @@ def _load_instance_from_remote_storage(remote_url: str, config_file_path: str |spec.loader.exec_module(module)# Get the instance- instance: Final = getattr(module, instance_name)+ instance: Final[object] = getattr(module, instance_name)# Clean up the temporary filetry: