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(lint) : resolve UP037 violations
KnyazShff4794c02350
diff --git a/litellm/litellm_core_utils/litellm_logging.py b/litellm/litellm_core_utils/litellm_logging.pyindex 6e09542430d..f01d8bf59f6 100644--- a/litellm/litellm_core_utils/litellm_logging.py+++ b/litellm/litellm_core_utils/litellm_logging.py@@ -13,7 +13,6 @@ import tracebackfrom datetime import datetime as dt_objectfrom functools import lru_cachefrom typing import (- TYPE_CHECKING,Any,Callable,Dict,@@ -75,6 +74,7 @@ from litellm.litellm_core_utils.redact_messages import (redact_message_input_output_from_logging,)from litellm.llms.base_llm.ocr.transformation import OCRResponse+from litellm.llms.base_llm.passthrough.transformation import BasePassthroughConfigfrom litellm.llms.base_llm.search.transformation import SearchResponsefrom litellm.responses.utils import ResponseAPILoggingUtilsfrom litellm.types.agents import LiteLLMSendMessageResponse@@ -173,8 +173,6 @@ from .initialize_dynamic_callback_params import ()from .specialty_caches.dynamic_logging_cache import DynamicLoggingCache-if TYPE_CHECKING:- from litellm.llms.base_llm.passthrough.transformation import BasePassthroughConfigtry:from litellm_enterprise.enterprise_callbacks.callback_controls import (EnterpriseCallbackControls,@@ -1367,7 +1365,7 @@ class Logging(LiteLLMLoggingBaseClass):OpenAIFileObject,LiteLLMRealtimeStreamLoggingObject,OpenAIModerationResponse,- "SearchResponse",+ SearchResponse,dict,list,],@@ -1909,7 +1907,7 @@ class Logging(LiteLLMLoggingBaseClass):def _flush_passthrough_collected_chunks_helper(self,raw_bytes: List[bytes],- provider_config: "BasePassthroughConfig",+ provider_config: BasePassthroughConfig,) -> Optional["CostResponseTypes"]:all_chunks = provider_config._convert_raw_bytes_to_str_lines(raw_bytes)complete_streaming_response = provider_config.handle_logging_collected_chunks(@@ -1924,7 +1922,7 @@ class Logging(LiteLLMLoggingBaseClass):def flush_passthrough_collected_chunks(self,raw_bytes: List[bytes],- provider_config: "BasePassthroughConfig",+ provider_config: BasePassthroughConfig,):"""Flush collected chunks from the logging object@@ -1947,7 +1945,7 @@ class Logging(LiteLLMLoggingBaseClass):async def async_flush_passthrough_collected_chunks(self,raw_bytes: List[bytes],- provider_config: "BasePassthroughConfig",+ provider_config: BasePassthroughConfig,):complete_streaming_response = self._flush_passthrough_collected_chunks_helper(raw_bytes=raw_bytes,diff --git a/litellm/passthrough/main.py b/litellm/passthrough/main.pyindex 9cf9c80b900..75ed91c1d3b 100644--- a/litellm/passthrough/main.py+++ b/litellm/passthrough/main.py@@ -8,7 +8,6 @@ import asyncioimport contextvarsfrom functools import partialfrom typing import (- TYPE_CHECKING,Any,AsyncGenerator,Coroutine,@@ -22,6 +21,8 @@ from httpx._types import CookieTypes, QueryParamTypes, RequestFilesfrom litellm._logging import verbose_loggerfrom litellm.litellm_core_utils.get_llm_provider_logic import get_llm_provider+from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj+from litellm.llms.base_llm.passthrough.transformation import BasePassthroughConfigfrom litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandlerfrom litellm.llms.custom_httpx.llm_http_handler import BaseLLMHTTPHandlerfrom litellm.passthrough.utils import CommonUtils@@ -30,17 +31,13 @@ from litellm.utils import clientbase_llm_http_handler = BaseLLMHTTPHandler()from .utils import BasePassthroughUtils-if TYPE_CHECKING:- from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj- from litellm.llms.base_llm.passthrough.transformation import BasePassthroughConfig-class AsyncPassthroughStreamingResponse(AsyncGenerator[Any, Any]):def __init__(self,response: Coroutine[Any, Any, httpx.Response],- litellm_logging_obj: "LiteLLMLoggingObj",- provider_config: "BasePassthroughConfig",+ litellm_logging_obj: LiteLLMLoggingObj,+ provider_config: BasePassthroughConfig,) -> None:self._initialized = Falseself._status_code: int = 0@@ -119,7 +116,7 @@ class AsyncPassthroughStreamingResponse(AsyncGenerator[Any, Any]):e,)- def __aiter__(self) -> "AsyncPassthroughStreamingResponse":+ def __aiter__(self) -> AsyncPassthroughStreamingResponse:return selfasync def __anext__(self) -> bytes:@@ -160,8 +157,8 @@ class PassthroughStreamingResponse(Generator[Any, Any, Any]):def __init__(self,response: httpx.Response,- litellm_logging_obj: "LiteLLMLoggingObj",- provider_config: "BasePassthroughConfig",+ litellm_logging_obj: LiteLLMLoggingObj,+ provider_config: BasePassthroughConfig,) -> None:self._response = responseself.headers = response.headers@@ -192,7 +189,7 @@ class PassthroughStreamingResponse(Generator[Any, Any, Any]):e,)- def __iter__(self) -> "PassthroughStreamingResponse":+ def __iter__(self) -> PassthroughStreamingResponse:return selfdef __next__(self) -> bytes:@@ -260,7 +257,7 @@ async def allm_passthrough_route(from litellm.utils import ProviderConfigManagerprovider_config = cast(- "BasePassthroughConfig" | None, kwargs.get("provider_config")+ BasePassthroughConfig | None, kwargs.get("provider_config")) or ProviderConfigManager.get_provider_passthrough_config(provider=LlmProviders(custom_llm_provider),model=model,@@ -328,7 +325,7 @@ async def allm_passthrough_route(if resolved_custom_llm_provider:try:provider_config = cast(- "BasePassthroughConfig" | None, kwargs.get("provider_config")+ BasePassthroughConfig | None, kwargs.get("provider_config")) or ProviderConfigManager.get_provider_passthrough_config(provider=LlmProviders(resolved_custom_llm_provider),model=model,@@ -387,7 +384,7 @@ def llm_passthrough_route(_is_async = allm_passthrough_route- litellm_logging_obj = cast("LiteLLMLoggingObj", kwargs.get("litellm_logging_obj"))+ litellm_logging_obj = cast(LiteLLMLoggingObj, kwargs.get("litellm_logging_obj"))model, custom_llm_provider, api_key, api_base = get_llm_provider(model=model,@@ -432,7 +429,7 @@ def llm_passthrough_route()provider_config = cast(- "BasePassthroughConfig" | None, kwargs.get("provider_config")+ BasePassthroughConfig | None, kwargs.get("provider_config")) or ProviderConfigManager.get_provider_passthrough_config(provider=LlmProviders(custom_llm_provider),model=model,@@ -550,8 +547,8 @@ async def _async_passthrough_request(client: HTTPHandler | AsyncHTTPHandler,request: httpx.Request,is_streaming_request: bool,- litellm_logging_obj: "LiteLLMLoggingObj",- provider_config: "BasePassthroughConfig",+ litellm_logging_obj: LiteLLMLoggingObj,+ provider_config: BasePassthroughConfig,) -> httpx.Response | AsyncGenerator[Any, Any]:"""Handle async passthrough requests.diff --git a/litellm/utils.py b/litellm/utils.pyindex a43d5e9cc9e..a13a2a7fc62 100644--- a/litellm/utils.py+++ b/litellm/utils.py@@ -549,7 +549,7 @@ def _add_custom_logger_callback_to_specific_event(callback: str, logging_event:def _custom_logger_class_exists_in_success_callbacks(- callback_class: "CustomLogger",+ callback_class: CustomLogger,) -> bool:"""Returns True if an instance of the custom logger exists in litellm.success_callback or litellm._async_success_callback@@ -564,7 +564,7 @@ def _custom_logger_class_exists_in_success_callbacks(def _custom_logger_class_exists_in_failure_callbacks(- callback_class: "CustomLogger",+ callback_class: CustomLogger,) -> bool:"""Returns True if an instance of the custom logger exists in litellm.failure_callback or litellm._async_failure_callback@@ -624,7 +624,7 @@ def load_credentials_from_list(kwargs: dict):def get_dynamic_callbacks(- dynamic_callbacks: Optional[List[Union[str, Callable, "CustomLogger"]]],+ dynamic_callbacks: Optional[List[Union[str, Callable, CustomLogger]]],) -> List:returned_callbacks = litellm.callbacks.copy()if dynamic_callbacks:@@ -752,7 +752,7 @@ def function_setup(coroutine_checker = get_coroutine_checker_fn()## DYNAMIC CALLBACKS ##- dynamic_callbacks: Optional[List[Union[str, Callable, "CustomLogger"]]] = kwargs.pop("callbacks", None)+ dynamic_callbacks: Optional[List[Union[str, Callable, CustomLogger]]] = kwargs.pop("callbacks", None)all_callbacks = get_dynamic_callbacks(dynamic_callbacks=dynamic_callbacks)if len(all_callbacks) > 0:@@ -836,10 +836,10 @@ def function_setup(for index in reversed(removed_async_items):litellm.failure_callback.pop(index)### DYNAMIC CALLBACKS ###- dynamic_success_callbacks: Optional[List[Union[str, Callable, "CustomLogger"]]] = None- dynamic_async_success_callbacks: Optional[List[Union[str, Callable, "CustomLogger"]]] = None- dynamic_failure_callbacks: Optional[List[Union[str, Callable, "CustomLogger"]]] = None- dynamic_async_failure_callbacks: Optional[List[Union[str, Callable, "CustomLogger"]]] = None+ dynamic_success_callbacks: Optional[List[Union[str, Callable, CustomLogger]]] = None+ dynamic_async_success_callbacks: Optional[List[Union[str, Callable, CustomLogger]]] = None+ dynamic_failure_callbacks: Optional[List[Union[str, Callable, CustomLogger]]] = None+ dynamic_async_failure_callbacks: Optional[List[Union[str, Callable, CustomLogger]]] = Noneif kwargs.get("success_callback", None) is not None and isinstance(kwargs["success_callback"], list):removed_async_items = []for index, callback in enumerate(kwargs["success_callback"]):@@ -7368,8 +7368,8 @@ def validate_and_fix_openai_tools(tools: Optional[List]) -> Optional[List[dict]]def validate_and_fix_thinking_param(- thinking: Optional["AnthropicThinkingParam"],-) -> Optional["AnthropicThinkingParam"]:+ thinking: Optional[AnthropicThinkingParam],+) -> Optional[AnthropicThinkingParam]:"""Normalizes camelCase keys in the thinking param to snake_case.Handles clients that send budgetTokens instead of budget_tokens.@@ -8193,7 +8193,7 @@ class ProviderConfigManager:@staticmethoddef get_provider_skills_api_config(provider: LlmProviders,- ) -> Optional["BaseSkillsAPIConfig"]:+ ) -> Optional[BaseSkillsAPIConfig]:"""Get provider-specific Skills API configuration@@ -8210,7 +8210,7 @@ class ProviderConfigManager:@staticmethoddef get_provider_evals_api_config(provider: LlmProviders,- ) -> Optional["BaseEvalsAPIConfig"]:+ ) -> Optional[BaseEvalsAPIConfig]:"""Get provider-specific Evals API configuration@@ -8645,7 +8645,7 @@ class ProviderConfigManager:def get_provider_realtime_http_config(model: str,provider: LlmProviders,- ) -> Optional["BaseRealtimeHTTPConfig"]:+ ) -> Optional[BaseRealtimeHTTPConfig]:"""Return the HTTP transformation config for realtime HTTP endpoints(POST /realtime/client_secrets and POST /realtime/calls).@@ -8736,7 +8736,7 @@ class ProviderConfigManager:def get_provider_ocr_config(model: str,provider: LlmProviders,- ) -> Optional["BaseOCRConfig"]:+ ) -> Optional[BaseOCRConfig]:"""Get OCR configuration for a given provider."""@@ -8776,8 +8776,8 @@ class ProviderConfigManager:@staticmethoddef get_provider_search_config(- provider: "SearchProviders",- ) -> Optional["BaseSearchConfig"]:+ provider: SearchProviders,+ ) -> Optional[BaseSearchConfig]:"""Get Search configuration for a given provider."""@@ -8849,7 +8849,7 @@ class ProviderConfigManager:def get_provider_text_to_speech_config(model: str,provider: LlmProviders,- ) -> Optional["BaseTextToSpeechConfig"]:+ ) -> Optional[BaseTextToSpeechConfig]:"""Get text-to-speech configuration for a given provider."""