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
chore: lint
Yuta Saitofb00b38fcdd8
diff --git a/litellm/integrations/focus/destinations/factory.py b/litellm/integrations/focus/destinations/factory.pyindex 6f5dc5dc06a..cb7696a11de 100644--- a/litellm/integrations/focus/destinations/factory.py+++ b/litellm/integrations/focus/destinations/factory.py@@ -26,7 +26,9 @@ class FocusDestinationFactory:)if provider_lower == "s3":return FocusS3Destination(prefix=prefix, config=normalized_config)- raise NotImplementedError(f"Provider '{provider}' not supported for Focus export")+ raise NotImplementedError(+ f"Provider '{provider}' not supported for Focus export"+ )@staticmethoddef _resolve_config(@@ -50,9 +52,7 @@ class FocusDestinationFactory:or os.getenv("FOCUS_S3_SESSION_TOKEN"),}if not resolved.get("bucket_name"):- raise ValueError(- "FOCUS_S3_BUCKET_NAME must be provided for S3 exports"- )+ raise ValueError("FOCUS_S3_BUCKET_NAME must be provided for S3 exports")return {k: v for k, v in resolved.items() if v is not None}raise NotImplementedError(f"Provider '{provider}' not supported for Focus export configuration"diff --git a/litellm/integrations/focus/focus_logger.py b/litellm/integrations/focus/focus_logger.pyindex 28629f64d38..5f47590f0b8 100644--- a/litellm/integrations/focus/focus_logger.py+++ b/litellm/integrations/focus/focus_logger.py@@ -14,7 +14,6 @@ from litellm.integrations.custom_logger import CustomLoggerfrom .database import FocusLiteLLMDatabasefrom .destinations import (- FocusDestination,FocusDestinationFactory,FocusTimeWindow,)@@ -50,9 +49,7 @@ class FocusLogger(CustomLogger):self.export_format = (export_format or os.getenv("FOCUS_FORMAT") or "parquet").lower()- self.frequency = (- frequency or os.getenv("FOCUS_FREQUENCY") or "hourly"- ).lower()+ self.frequency = (frequency or os.getenv("FOCUS_FREQUENCY") or "hourly").lower()self.cron_offset_minute = (cron_offset_minuteif cron_offset_minute is not None@@ -90,7 +87,9 @@ class FocusLogger(CustomLogger):) -> None:"""Public hook to trigger export immediately."""if bool(start_time_utc) ^ bool(end_time_utc):- raise ValueError("start_time_utc and end_time_utc must be provided together")+ raise ValueError(+ "start_time_utc and end_time_utc must be provided together"+ )if start_time_utc and end_time_utc:window = FocusTimeWindow(@@ -160,7 +159,6 @@ class FocusLogger(CustomLogger):scheduler: AsyncIOScheduler,) -> None:"""Register the export cron/interval job with the provided scheduler."""- from litellm.integrations.custom_logger import CustomLoggerfocus_loggers: List[CustomLogger@@ -168,7 +166,9 @@ class FocusLogger(CustomLogger):callback_type=FocusLogger)if not focus_loggers:- verbose_logger.debug("No Focus export logger registered; skipping scheduler")+ verbose_logger.debug(+ "No Focus export logger registered; skipping scheduler"+ )returnfocus_logger = cast(FocusLogger, focus_loggers[0])@@ -218,7 +218,9 @@ class FocusLogger(CustomLogger):normalized = self._transformer.transform(data)if normalized.is_empty():- verbose_logger.debug("Focus export: normalized data empty for window %s", window)+ verbose_logger.debug(+ "Focus export: normalized data empty for window %s", window+ )returnawait self._serialize_and_upload(normalized, window)diff --git a/litellm/integrations/focus/transformer.py b/litellm/integrations/focus/transformer.pyindex a98ea21b1bb..cac12b7be14 100644--- a/litellm/integrations/focus/transformer.py+++ b/litellm/integrations/focus/transformer.py@@ -35,6 +35,7 @@ class FocusTransformer:return col.dt.strftime("%Y-%m-%dT%H:%M:%SZ")DEC = pl.Decimal(18, 6)+def dec(col):return col.cast(DEC)diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.pyindex 6c5a2397204..7535a79dfac 100644--- a/litellm/proxy/proxy_server.py+++ b/litellm/proxy/proxy_server.py@@ -533,9 +533,9 @@ except ImportError:server_root_path = os.getenv("SERVER_ROOT_PATH", "")_license_check = LicenseCheck()premium_user: bool = _license_check.is_premium()-premium_user_data: Optional["EnterpriseLicenseData"] = (- _license_check.airgapped_license_data-)+premium_user_data: Optional[+ "EnterpriseLicenseData"+] = _license_check.airgapped_license_dataglobal_max_parallel_request_retries_env: Optional[str] = os.getenv("LITELLM_GLOBAL_MAX_PARALLEL_REQUEST_RETRIES")@@ -1083,9 +1083,7 @@ try:# In non-root Docker, we restructure in /var/lib/litellm/ui.try:_restructure_ui_html_files(ui_path)- verbose_proxy_logger.info(- f"Restructured UI directory: {ui_path}"- )+ verbose_proxy_logger.info(f"Restructured UI directory: {ui_path}")except PermissionError as e:verbose_proxy_logger.exception(f"Permission error while restructuring UI directory {ui_path}: {e}"@@ -1171,9 +1169,9 @@ master_key: Optional[str] = Noneconfig_agents: Optional[List[AgentConfig]] = Noneotel_logging = Falseprisma_client: Optional[PrismaClient] = None-shared_aiohttp_session: Optional["ClientSession"] = (- None # Global shared session for connection reuse-)+shared_aiohttp_session: Optional[+ "ClientSession"+] = None # Global shared session for connection reuseuser_api_key_cache = DualCache(default_in_memory_ttl=UserAPIKeyCacheTTLEnum.in_memory_cache_ttl.value)@@ -1181,9 +1179,9 @@ model_max_budget_limiter = _PROXY_VirtualKeyModelMaxBudgetLimiter(dual_cache=user_api_key_cache)litellm.logging_callback_manager.add_litellm_callback(model_max_budget_limiter)-redis_usage_cache: Optional[RedisCache] = (- None # redis cache used for tracking spend, tpm/rpm limits-)+redis_usage_cache: Optional[+ RedisCache+] = None # redis cache used for tracking spend, tpm/rpm limitspolling_via_cache_enabled: Union[Literal["all"], List[str], bool] = Falsepolling_cache_ttl: int = 3600 # Default 1 hour TTL for polling cacheuser_custom_auth = None@@ -1522,9 +1520,9 @@ async def update_cache( # noqa: PLR0915_id = "team_id:{}".format(team_id)try:# Fetch the existing cost for the given user- existing_spend_obj: Optional[LiteLLM_TeamTable] = (- await user_api_key_cache.async_get_cache(key=_id)- )+ existing_spend_obj: Optional[+ LiteLLM_TeamTable+ ] = await user_api_key_cache.async_get_cache(key=_id)if existing_spend_obj is None:# do nothing if team not in api key cachereturn@@ -1876,7 +1874,6 @@ class ProxyConfig:"environment_variables" in config_to_saveand config_to_save["environment_variables"]):-# decrypt the environment_variables - in case a caller function has already encrypted the environment_variablesdecrypted_env_vars = self._decrypt_and_set_db_env_variables(environment_variables=config_to_save["environment_variables"],@@ -2794,21 +2791,21 @@ class ProxyConfig:verbose_proxy_logger.debug(f"_alerting_callbacks: {general_settings}")if _alerting_callbacks is None:return-+# Ensure proxy_logging_obj.alerting is set for all alerting types_alerting_value = general_settings.get("alerting", None)- verbose_proxy_logger.debug(f"_load_alerting_settings: Calling update_values with alerting={_alerting_value}")+ verbose_proxy_logger.debug(+ f"_load_alerting_settings: Calling update_values with alerting={_alerting_value}"+ )proxy_logging_obj.update_values(alerting=_alerting_value,alerting_threshold=general_settings.get("alerting_threshold", 600),alert_types=general_settings.get("alert_types", None),- alert_to_webhook_url=general_settings.get(- "alert_to_webhook_url", None- ),+ alert_to_webhook_url=general_settings.get("alert_to_webhook_url", None),alerting_args=general_settings.get("alerting_args", None),redis_cache=redis_usage_cache,)-+for _alert in _alerting_callbacks:if _alert == "slack":# [OLD] v0 implementation - already handled by update_values above@@ -3279,7 +3276,7 @@ class ProxyConfig:proxy_logging_obj: ProxyLogging"""_general_settings = config_data.get("general_settings", {})-+if _general_settings is not None and "alerting" in _general_settings:if (general_settings is not None@@ -3294,7 +3291,8 @@ class ProxyConfig:_merged_alerting = list(_yaml_alerting.union(_db_alerting))# Preserve order: YAML values first, then DB values_merged_alerting = list(general_settings["alerting"]) + [- item for item in _general_settings["alerting"]+ item+ for item in _general_settings["alerting"]if item not in general_settings["alerting"]]verbose_proxy_logger.debug(@@ -3605,7 +3603,6 @@ class ProxyConfig:await self._init_vector_stores_in_db(prisma_client=prisma_client)if self._should_load_db_object(object_type="vector_store_indexes"):-await self._init_vector_store_indexes_in_db(prisma_client=prisma_client)if self._should_load_db_object(object_type="mcp"):@@ -3804,10 +3801,10 @@ class ProxyConfig:)try:- guardrails_in_db: List[Guardrail] = (- await GuardrailRegistry.get_all_guardrails_from_db(- prisma_client=prisma_client- )+ guardrails_in_db: List[+ Guardrail+ ] = await GuardrailRegistry.get_all_guardrails_from_db(+ prisma_client=prisma_client)verbose_proxy_logger.debug("guardrails from the DB %s", str(guardrails_in_db)@@ -4134,9 +4131,9 @@ async def initialize( # noqa: PLR0915user_api_base = api_basedynamic_config[user_model]["api_base"] = api_baseif api_version:- os.environ["AZURE_API_VERSION"] = (- api_version # set this for azure - litellm can read this from the env- )+ os.environ[+ "AZURE_API_VERSION"+ ] = api_version # set this for azure - litellm can read this from the envif max_tokens: # model-specific paramdynamic_config[user_model]["max_tokens"] = max_tokensif temperature: # model-specific param@@ -4654,10 +4651,14 @@ class ProxyStartupEvent:replace_existing=True,misfire_grace_time=APSCHEDULER_MISFIRE_GRACE_TIME,)- verbose_proxy_logger.info("Responses cost check job scheduled successfully")+ verbose_proxy_logger.info(+ "Responses cost check job scheduled successfully"+ )except Exception as e:- verbose_proxy_logger.debug(f"Failed to setup responses cost checking: {e}")+ verbose_proxy_logger.debug(+ f"Failed to setup responses cost checking: {e}"+ )verbose_proxy_logger.debug("Checking responses cost for LiteLLM Managed Files is an Enterprise Feature. Skipping...")@@ -5944,7 +5945,6 @@ async def realtime_websocket_endpoint(),user_api_key_dict=Depends(user_api_key_auth_websocket),):-await websocket.accept()# Only use explicit parameters, not all query params@@ -9532,9 +9532,9 @@ async def get_config_list(hasattr(sub_field_info, "description")and sub_field_info.description is not None):- nested_fields[idx].field_description = (- sub_field_info.description- )+ nested_fields[+ idx+ ].field_description = sub_field_info.descriptionidx += 1_stored_in_db = None