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: resolve ruff lint errors (#17490)
Anas AbdelR2abcc77944a8
diff --git a/litellm/batches/batch_utils.py b/litellm/batches/batch_utils.pyindex 50b48321db5..42ff534c289 100644--- a/litellm/batches/batch_utils.py+++ b/litellm/batches/batch_utils.py@@ -15,6 +15,7 @@ from litellm.utils import token_counterasync def calculate_batch_cost_and_usage(file_content_dictionary: List[dict],custom_llm_provider: Literal["openai", "azure", "vertex_ai", "hosted_vllm"],+ model_name: Optional[str] = None,) -> Tuple[float, Usage, List[str]]:"""Calculate the cost and usage of a batch@@ -37,6 +38,7 @@ async def calculate_batch_cost_and_usage(async def _handle_completed_batch(batch: Batch,custom_llm_provider: Literal["openai", "azure", "vertex_ai", "hosted_vllm"],+ model_name: Optional[str] = None,) -> Tuple[float, Usage, List[str]]:"""Helper function to process a completed batch and handle logging"""# Get batch results@@ -83,6 +85,7 @@ def _get_batch_models_from_file_content(def _batch_cost_calculator(file_content_dictionary: List[dict],custom_llm_provider: Literal["openai", "azure", "vertex_ai", "hosted_vllm"] = "openai",+ model_name: Optional[str] = None,) -> float:"""Calculate the cost of a batch based on the output file id@@ -251,6 +254,7 @@ def _get_batch_job_cost_from_file_content(def _get_batch_job_total_usage_from_file_content(file_content_dictionary: List[dict],custom_llm_provider: Literal["openai", "azure", "vertex_ai", "hosted_vllm"] = "openai",+ model_name: Optional[str] = None,) -> Usage:"""Get the tokens of a batch job from the file contentdiff --git a/litellm/integrations/custom_guardrail.py b/litellm/integrations/custom_guardrail.pyindex 782f9460044..bb5883dd475 100644--- a/litellm/integrations/custom_guardrail.py+++ b/litellm/integrations/custom_guardrail.py@@ -6,7 +6,6 @@ from typing import (List,Literal,Optional,- Tuple,Type,Union,get_args,diff --git a/litellm/llms/anthropic/chat/guardrail_translation/handler.py b/litellm/llms/anthropic/chat/guardrail_translation/handler.pyindex 9b6511f151c..5969a76ed90 100644--- a/litellm/llms/anthropic/chat/guardrail_translation/handler.py+++ b/litellm/llms/anthropic/chat/guardrail_translation/handler.py@@ -302,7 +302,7 @@ class AnthropicMessagesHandler(BaseTranslation):Get the string so far, check the apply guardrail to the string so far, and return the list of responses so far."""string_so_far = self.get_streaming_string_so_far(responses_so_far)- guardrailed_inputs = await guardrail_to_apply.apply_guardrail( # allow rejecting the response, if invalid+ _guardrailed_inputs = await guardrail_to_apply.apply_guardrail( # allow rejecting the response, if invalidinputs={"texts": [string_so_far]},request_data={},input_type="response",diff --git a/litellm/llms/custom_httpx/http_handler.py b/litellm/llms/custom_httpx/http_handler.pyindex d9a9d4f9dc1..62c3e82007b 100644--- a/litellm/llms/custom_httpx/http_handler.py+++ b/litellm/llms/custom_httpx/http_handler.py@@ -18,7 +18,6 @@ from litellm.constants import (AIOHTTP_CONNECTOR_LIMIT,AIOHTTP_CONNECTOR_LIMIT_PER_HOST,AIOHTTP_KEEPALIVE_TIMEOUT,- AIOHTTP_NEEDS_CLEANUP_CLOSED,AIOHTTP_TTL_DNS_CACHE,DEFAULT_SSL_CIPHERS,)diff --git a/litellm/llms/openai/responses/guardrail_translation/handler.py b/litellm/llms/openai/responses/guardrail_translation/handler.pyindex 9377eb4e193..fb8b16817b2 100644--- a/litellm/llms/openai/responses/guardrail_translation/handler.py+++ b/litellm/llms/openai/responses/guardrail_translation/handler.py@@ -32,8 +32,6 @@ from typing import TYPE_CHECKING, Any, Dict, List, Optional, Tuple, Union, castfrom openai import BaseModel-from openai import BaseModel-from litellm._logging import verbose_proxy_loggerfrom litellm.llms.base_llm.guardrail_translation.base_translation import BaseTranslationfrom litellm.responses.litellm_completion_transformation.transformation import (@@ -339,7 +337,7 @@ class OpenAIResponsesHandler(BaseTranslation):Process output streaming response by applying guardrails to text content."""string_so_far = self.get_streaming_string_so_far(responses_so_far)- guardrailed_inputs = await guardrail_to_apply.apply_guardrail(+ _guardrailed_inputs = await guardrail_to_apply.apply_guardrail(inputs={"texts": [string_so_far]},request_data={},input_type="response",diff --git a/litellm/llms/pass_through/guardrail_translation/handler.py b/litellm/llms/pass_through/guardrail_translation/handler.pyindex 0702086a578..c0979e37e66 100644--- a/litellm/llms/pass_through/guardrail_translation/handler.py+++ b/litellm/llms/pass_through/guardrail_translation/handler.py@@ -118,7 +118,7 @@ class PassThroughEndpointHandler(BaseTranslation):return data# Apply guardrail (pass-through doesn't modify the text, just checks it)- guardrailed_inputs = await guardrail_to_apply.apply_guardrail(+ _guardrailed_inputs = await guardrail_to_apply.apply_guardrail(inputs={"texts": [text_to_check]},request_data=data,input_type="request",@@ -178,7 +178,7 @@ class PassThroughEndpointHandler(BaseTranslation):request_data["litellm_metadata"] = user_metadata# Apply guardrail (pass-through doesn't modify the text, just checks it)- guardrailed_inputs = await guardrail_to_apply.apply_guardrail(+ _guardrailed_inputs = await guardrail_to_apply.apply_guardrail(inputs={"texts": [text_to_check]},request_data=request_data,input_type="response",diff --git a/litellm/proxy/guardrails/guardrail_hooks/generic_guardrail_api/generic_guardrail_api.py b/litellm/proxy/guardrails/guardrail_hooks/generic_guardrail_api/generic_guardrail_api.pyindex 33912b8fcd9..55f1fbc8c86 100644--- a/litellm/proxy/guardrails/guardrail_hooks/generic_guardrail_api/generic_guardrail_api.py+++ b/litellm/proxy/guardrails/guardrail_hooks/generic_guardrail_api/generic_guardrail_api.py@@ -6,7 +6,7 @@# Thank you users! We ❤️ you! - Krrish & Ishaanimport os-from typing import TYPE_CHECKING, Any, Dict, List, Literal, Optional, Tuple+from typing import TYPE_CHECKING, Any, Dict, Literal, Optionalfrom litellm._logging import verbose_proxy_loggerfrom litellm.integrations.custom_guardrail import CustomGuardraildiff --git a/litellm/proxy/hooks/parallel_request_limiter_v3.py b/litellm/proxy/hooks/parallel_request_limiter_v3.pyindex 2abba1d4976..c462493de6c 100644--- a/litellm/proxy/hooks/parallel_request_limiter_v3.py+++ b/litellm/proxy/hooks/parallel_request_limiter_v3.py@@ -1327,7 +1327,6 @@ class _PROXY_MaxParallelRequestsHandler_v3(CustomLogger):_get_parent_otel_span_from_kwargs,)from litellm.proxy.common_utils.callback_utils import (- get_metadata_variable_name_from_kwargs,get_model_group_from_litellm_kwargs,)from litellm.types.caching import RedisPipelineIncrementOperation