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
Merge branch 'main' into litellm_config_read_source
Yuneng Jiang86c4021e839b
diff --cc litellm/proxy/config_resolvers/__init__.pyindex 77da2c413c2,eee760df458..f031a8d74b9--- a/litellm/proxy/config_resolvers/__init__.py+++ b/litellm/proxy/config_resolvers/__init__.py@@@ -5,13 -5,6 +5,17 @@@ from litellm.proxy.config_resolvers._deFieldSource,resolve_fields,)- from litellm.proxy.config_resolvers.settings_store import SettingsSource, SettingsStore, source_for-from litellm.proxy.config_resolvers.settings_store import SettingsStore, config_ownership_message++from litellm.proxy.config_resolvers.settings_store import (++ SettingsStore,++ config_ownership_message,++ source_for,++)-__all__ = ("FieldDescriptor", "FieldSource", "SettingsStore", "config_ownership_message", "resolve_fields")+__all__ = (+ "FieldDescriptor",+ "FieldSource",- "SettingsSource",+ "SettingsStore",++ "config_ownership_message",+ "resolve_fields",+ "source_for",+)diff --cc litellm/proxy/config_resolvers/settings_store.pyindex 73bca3222ea,291000b3b6a..f05af3de03a--- a/litellm/proxy/config_resolvers/settings_store.py+++ b/litellm/proxy/config_resolvers/settings_store.py@@@ -125,17 -160,19 +160,26 @@@ class SettingsStore(MutableMapping[str))- def _resolution_for(self, key: str) -> Resolved:+ def _db_value(self, key: str) -> SettingValue:rule: Final = rule_for(self._section, key)+ return self._database_rows.get(rule.db_row, _EMPTY_VALUES).get(key, ABSENT)++ def _db_value_is_shadowed(self, key: str) -> bool:+ db_value: Final = self._db_value(key)+ return (+ not isinstance(db_value, Absent)+ and db_value is not None+ and db_value != self.get(key)+ and db_value != self.config_value(key)+ )++ def _resolution_for(self, key: str) -> Resolved:yaml_value: Final[SettingValue] = self._yaml_values.get(key, ABSENT)- db_value: Final[SettingValue] = self._database_rows.get(rule.db_row, _EMPTY_VALUES).get(key, ABSENT)- return resolve(rule, yaml_value, db_value)+ return resolve(yaml_value, self._db_value(key))++- def source_for(settings: SettingsStore, key: str, default: object = None) -> SettingsSource:++def source_for(settings: SettingsStore, key: str, default: object = None) -> FieldSource:+ source: Final = settings.source(key)+ if source == "unset":+ return "default" if default is not None else "unset"- if source in ("config", "db", "default"):- return source- return "unset"++ return sourcediff --cc litellm/proxy/management_endpoints/router_settings_endpoints.pyindex 1869be88d1b,fc000b1638b..019ac68ae23--- a/litellm/proxy/management_endpoints/router_settings_endpoints.py+++ b/litellm/proxy/management_endpoints/router_settings_endpoints.py@@@ -16,7 -16,6 +16,7 @@@ from pydantic import BaseModel, Fielfrom litellm._logging import verbose_proxy_loggerfrom litellm.proxy._types import UserAPIKeyAuthfrom litellm.proxy.auth.user_api_key_auth import user_api_key_auth- from litellm.proxy.config_resolvers import SettingsSource, SettingsStore, source_for++from litellm.proxy.config_resolvers import FieldSource, SettingsStore, source_forfrom litellm.router import Routerfrom litellm.types.management_endpoints import (ROUTER_SETTINGS_FIELDS,@@@ -31,7 -30,6 +31,7 @@@ class RouterSettingsResponse(BaseModel)fields: list[RouterSettingsField] = Field(description="List of all configurable router settings with metadata")current_values: dict[str, Any] = Field(description="Current values of router settings")routing_strategy_descriptions: dict[str, str] = Field(description="Descriptions for each routing strategy option")- source: dict[str, SettingsSource] = Field(description="Source of each current router setting")++ source: dict[str, FieldSource] = Field(description="Source of each current router setting")class RouterFieldsResponse(BaseModel):@@@ -41,18 -39,6 +41,18 @@@routing_strategy_descriptions: dict[str, str] = Field(description="Descriptions for each routing strategy option")+def _router_setting_source(+ settings: SettingsStore,+ key: str,+ current_value: object,+ field_default: object,- ) -> SettingsSource:++) -> FieldSource:+ source: Final = source_for(settings, key, field_default)+ if source != "unset":+ return source+ return "default" if current_value is not None else "unset"++def _get_routing_strategies_from_router_class() -> list[str]:"""Dynamically extract routing strategies from the Router class __init__ method.@@@ -127,19 -114,6 +127,19 @@@ async def get_router_settingsif field.field_name in current_values:field.field_value = current_values[field.field_name]+ field_defaults: Final[dict[str, object]] = {+ field.field_name: cast(object, field.field_default) # cast-ok: Pydantic field defaults are untyped+ for field in router_fields+ }- source: Final[dict[str, SettingsSource]] = {++ source: Final[dict[str, FieldSource]] = {+ key: _router_setting_source(+ proxy_config.router_settings,+ key,+ cast(object, current_values[key]), # cast-ok: current values are stored in a typed response map+ field_defaults.get(key),+ )+ for key in current_values+ }return RouterSettingsResponse(fields=router_fields,current_values=current_values,diff --cc litellm/proxy/proxy_server.pyindex 3898f522feb,3a06753834a..4b2781e031b--- a/litellm/proxy/proxy_server.py+++ b/litellm/proxy/proxy_server.py@@@ -430,9 -452,11 +453,17 @@@ from litellm.proxy.common_utils.user_apget_management_object_ttl,model_access_group_cache_key,model_access_group_spend_counter_key,+ project_cache_key,+ project_spend_counter_key,tag_cache_key,)- from litellm.proxy.config_resolvers import SettingsSource, SettingsStore, resolve_fields, source_for-from litellm.proxy.config_resolvers import SettingsStore, config_ownership_message, resolve_fields++from litellm.proxy.config_resolvers import (++ FieldSource,++ SettingsStore,++ config_ownership_message,++ resolve_fields,++ source_for,++)from litellm.proxy.config_resolvers.alerting import (EMAIL_DESCRIPTORS,MS_TEAMS_DESCRIPTORS,@@@ -15605,22 -15970,6 +15983,22 @@@ async def model_settings()#### ALERTING MANAGEMENT ENDPOINTS ####+def _nested_setting_source(+ settings: SettingsStore,+ db_values: Mapping[str, JsonValue],+ parent_key: str,+ field_name: str,+ field_default: JsonValue,- ) -> SettingsSource:++) -> FieldSource:+ db_value: Final = db_values.get(field_name)+ if db_value is not None and db_value != []:+ return "db"- parent_value: Final = settings.without_db().get(parent_key)++ parent_value: Final = settings.config_value(parent_key)+ if isinstance(parent_value, Mapping) and field_name in parent_value:+ return "config"+ return "default" if field_default is not None else "unset"++@router.get("/alerting/settings",description="Return the configurable alerting param, description, and current value",diff --cc litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.pyindex aba65719f9b,7bdadeadf86..4505f3144ee--- a/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py+++ b/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py@@@ -24,20 -25,17 +25,21 @@@ from litellm.litellm_core_utils.sensitifrom litellm.proxy._experimental.mcp_server.tool_search import MCP_TOOL_SEARCH_SETTINGS_KEYfrom litellm.proxy._types import *from litellm.proxy.auth.user_api_key_auth import user_api_key_auth- from litellm.proxy.config_resolvers import SettingsSource, SettingsStore, source_for++from litellm.proxy.config_resolvers import FieldSource, SettingsStore, source_for+ from litellm.proxy.config_resolvers.settings_store import ConfigOwnedKeyErrorfrom litellm.proxy.config_resolvers.sso import (SSO_FIELD_ENV_VARS,SSO_SECRET_FIELDS,resolve_sso_config,)from litellm.proxy.management_endpoints.team_admin_field_permissions import (- SUPPORTED_TEAM_ADMIN_EDITABLE_TEAM_FIELDS,+ SUPPORTED_TEAM_ADMIN_PERMISSIONS,TEAM_ADMIN_EDITABLE_TEAM_FIELDS_SETTING,)-from litellm.proxy.spend_tracking.ptu_feature_flag import is_ptu_cost_attribution_enabled+from litellm.proxy.spend_tracking.ptu_feature_flag import (+ PTU_COST_ATTRIBUTION_ENV_VAR,+ is_ptu_cost_attribution_enabled,+)from litellm.proxy.utils import invalidate_config_paramfrom litellm.repositories.config_repository import ConfigRepositoryfrom litellm.repositories.organization_repository import OrganizationRepository@@@ -337,8 -330,6 +340,8 @@@ class UISettings(BaseModel)class UISettingsResponse(SettingsResponse):"""Response model for UI settings"""- source: dict[str, SettingsSource]++ source: dict[str, FieldSource]+# Allowlist of UI settings that can be storedALLOWED_UI_SETTINGS_FIELDS: Final = {@@@ -670,25 -748,6 +760,25 @@@ def _root_schema(settings_class: type[B)+def _model_field_default(settings_class: type[BaseModel], field_name: str) -> object:+ field_info: Final = settings_class.model_fields.get(field_name)+ if field_info is None or field_info.default is PydanticUndefined:+ return None+ return cast(object, field_info.default) # cast-ok: Pydantic field defaults are untyped+++def _ui_setting_source(+ key: str,+ value: object,+ settings: SettingsStore,+ settings_class: type[BaseModel],- ) -> SettingsSource:++) -> FieldSource:+ if key == ENABLE_PTU_COST_ATTRIBUTION_UI_SETTING:+ configured_value: Final = get_secret(PTU_COST_ATTRIBUTION_ENV_VAR, None)+ return "config" if configured_value is not None or value is True else "default"+ return source_for(settings, key, _model_field_default(settings_class, key))++async def _get_settings_with_schema(settings_key: str,settings_class: type[BaseModel],@@@ -1584,33 -1730,20 +1762,33 @@@ async def get_ui_settings()await user_api_key_cache.async_set_cache(key=UI_SETTINGS_CACHE_KEY, value=ui_settings, ttl=UI_SETTINGS_CACHE_TTL)- # Build config-like object for schema helper- config: Final[dict[str, object]] = {"litellm_settings": {"ui_settings": ui_settings}}-- settings: Final = await _get_settings_with_schema(- settings_key="ui_settings",- settings_class=_get_effective_ui_settings_class(),- config=config,+ effective_ui_settings: Final = {+ **{key: proxy_config.settings[key] for key in ALLOWED_UI_SETTINGS_FIELDS if key in proxy_config.settings},+ **ui_settings,+ }+ config: Final[dict[str, object]] = {"litellm_settings": {"ui_settings": effective_ui_settings}}+ settings_class: Final = _get_effective_ui_settings_class()+ resolved_settings: Final = _SettingsWithSchema.model_validate(+ await _get_settings_with_schema(+ settings_key="ui_settings",+ settings_class=settings_class,+ config=config,+ ))+ values: Final = {+ **resolved_settings.values,+ ENABLE_PTU_COST_ATTRIBUTION_UI_SETTING: is_ptu_cost_attribution_enabled(),+ }- source: Final[dict[str, SettingsSource]] = {++ source: Final[dict[str, FieldSource]] = {+ key: (+ "db" if key in ui_settings else _ui_setting_source(key, values[key], proxy_config.settings, settings_class)+ )+ for key in values+ }return UISettingsResponse(- values={- **settings["values"],- ENABLE_PTU_COST_ATTRIBUTION_UI_SETTING: is_ptu_cost_attribution_enabled(),- },- field_schema=settings["field_schema"],+ values=values,+ field_schema=resolved_settings.field_schema,+ source=source,)