diff --git a/enterprise/litellm_enterprise/proxy/liteadmin.py b/enterprise/litellm_enterprise/proxy/liteadmin.py index 6a9110f1460..e89bf11bd6e 100644 --- a/enterprise/litellm_enterprise/proxy/liteadmin.py +++ b/enterprise/litellm_enterprise/proxy/liteadmin.py @@ -15,11 +15,12 @@ from urllib.parse import urlencode, urlsplit import httpx from fastapi import APIRouter, Depends, HTTPException, Request from fastapi.responses import HTMLResponse, RedirectResponse, Response -from pydantic import BaseModel, ConfigDict, Field, SecretStr, TypeAdapter, ValidationError +from pydantic import ConfigDict, Field, SecretStr, TypeAdapter, ValidationError from litellm.llms.custom_httpx.http_handler import get_async_httpx_client from litellm.proxy._experimental.mcp_server.oauth_utils import get_request_base_url from litellm.proxy._types import LiteLLM_UserTable, LitellmUserRoles, UserAPIKeyAuth +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.auth.auth_checks import UserNotFoundError router: Final = APIRouter() @@ -34,14 +35,14 @@ _HEADERS: Final = { } -class LinkDetails(BaseModel): +class LinkDetails(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, strict=True, extra="forbid") workspace_id: str = Field(min_length=1, max_length=64) slack_user_id: str = Field(min_length=1, max_length=64) email: str = Field(min_length=1, max_length=320) -class AdminSession(BaseModel): +class AdminSession(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) user_id: str credential: SecretStr diff --git a/enterprise/litellm_enterprise/types/enterprise_callbacks/send_emails.py b/enterprise/litellm_enterprise/types/enterprise_callbacks/send_emails.py index 380b0a6facb..a2322d7f650 100644 --- a/enterprise/litellm_enterprise/types/enterprise_callbacks/send_emails.py +++ b/enterprise/litellm_enterprise/types/enterprise_callbacks/send_emails.py @@ -1,12 +1,13 @@ import enum from typing import Dict, List, Optional -from pydantic import BaseModel, Field +from pydantic import Field from litellm.proxy._types import WebhookEvent +from litellm.types.llms.base import LiteLLMBaseModel -class EmailParams(BaseModel): +class EmailParams(LiteLLMBaseModel): logo_url: str support_contact: str base_url: str @@ -39,14 +40,14 @@ class EmailEvent(str, enum.Enum): soft_budget_crossed = "Soft Budget Crossed" max_budget_alert = "Max Budget Alert" -class EmailEventSettings(BaseModel): +class EmailEventSettings(LiteLLMBaseModel): event: EmailEvent enabled: bool -class EmailEventSettingsUpdateRequest(BaseModel): +class EmailEventSettingsUpdateRequest(LiteLLMBaseModel): settings: List[EmailEventSettings] -class EmailEventSettingsResponse(BaseModel): +class EmailEventSettingsResponse(LiteLLMBaseModel): settings: List[EmailEventSettings] -class DefaultEmailSettings(BaseModel): +class DefaultEmailSettings(LiteLLMBaseModel): """Default settings for email events""" settings: Dict[EmailEvent, bool] = Field( default_factory=lambda: { diff --git a/enterprise/litellm_enterprise/types/proxy/audit_logging_endpoints.py b/enterprise/litellm_enterprise/types/proxy/audit_logging_endpoints.py index 4615bde2b15..3676cf2a7a2 100644 --- a/enterprise/litellm_enterprise/types/proxy/audit_logging_endpoints.py +++ b/enterprise/litellm_enterprise/types/proxy/audit_logging_endpoints.py @@ -1,10 +1,12 @@ from datetime import datetime from typing import Any, Dict, List, Optional -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel -class AuditLogResponse(BaseModel): +class AuditLogResponse(LiteLLMBaseModel): """Response model for a single audit log entry""" id: str @@ -18,7 +20,7 @@ class AuditLogResponse(BaseModel): updated_values: Optional[Dict[str, Any]] = None -class PaginatedAuditLogResponse(BaseModel): +class PaginatedAuditLogResponse(LiteLLMBaseModel): """Response model for paginated audit logs""" audit_logs: List[AuditLogResponse] diff --git a/litellm/caching/caching_handler.py b/litellm/caching/caching_handler.py index f04ff8b6e78..9d02c84f6e8 100644 --- a/litellm/caching/caching_handler.py +++ b/litellm/caching/caching_handler.py @@ -21,7 +21,7 @@ import time from collections.abc import AsyncGenerator, AsyncIterator, Awaitable, Callable, Generator, Mapping from typing import TYPE_CHECKING, Any, Final, Optional, TypeVar -from pydantic import BaseModel, ConfigDict, ValidationError +from pydantic import ConfigDict, ValidationError import litellm from litellm._internal_context import post_response_phase @@ -37,6 +37,7 @@ from litellm.litellm_core_utils.logging_utils import ( ) from litellm.types.caching import EMBEDDING_CACHE_FORMAT_VERSION, CachedEmbedding from litellm.types.integrations.custom_logger import converted_stream_requested +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import ResponsesAPIResponse from litellm.types.rerank import RerankResponse from litellm.types.utils import ( @@ -68,7 +69,7 @@ from litellm.litellm_core_utils.core_helpers import ( from litellm.litellm_core_utils.streaming_handler import CustomStreamWrapper -class CachingHandlerResponse(BaseModel): +class CachingHandlerResponse(LiteLLMBaseModel): """ This is the response object for the caching handler. We need to separate embedding cached responses and (completion / text_completion / transcription) cached responses @@ -172,7 +173,7 @@ def _request_cache_key(request_kwargs: Mapping[str, Any]) -> str | None: return request_kwargs.get("cache_key", None) -class _CachedEmbeddingRecord(BaseModel): +class _CachedEmbeddingRecord(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) embedding: list[float] | str | None diff --git a/litellm/constants.py b/litellm/constants.py index a268f00775a..938a3c85c29 100644 --- a/litellm/constants.py +++ b/litellm/constants.py @@ -5,6 +5,7 @@ from typing import Final, Literal from litellm.litellm_core_utils.env_utils import get_env_int, get_env_int_in_range, get_env_int_or_none +DEFER_PYDANTIC_BUILD: Final = os.getenv("DEFER_PYDANTIC_BUILD", "true") in ("true", "1", "on") DEFAULT_HEALTH_CHECK_PROMPT: Final = str(os.getenv("DEFAULT_HEALTH_CHECK_PROMPT", "test from litellm")) AZURE_DEFAULT_RESPONSES_API_VERSION: Final = str(os.getenv("AZURE_DEFAULT_RESPONSES_API_VERSION", "preview")) AZURE_OPENAI_AUDIO_PROVIDERS: Final = frozenset({"azure", "azure_ai"}) diff --git a/litellm/cost_calculator.py b/litellm/cost_calculator.py index 0443faabe59..8971b958c1c 100644 --- a/litellm/cost_calculator.py +++ b/litellm/cost_calculator.py @@ -100,7 +100,7 @@ from litellm.llms.xai.cost_calculator import cost_per_token as xai_cost_per_toke from litellm.responses.utils import ResponseAPILoggingUtils from litellm.types.agents import LiteLLMSendMessageResponse from litellm.types.decisions import DecisionsResponse, DecisionsUsage -from litellm.types.llms.base import CachedTokensDetails +from litellm.types.llms.base import CachedTokensDetails, LiteLLMBaseModel from litellm.types.llms.openai import ( HttpxBinaryResponseContent, ImageGenerationRequestQuality, @@ -2839,12 +2839,12 @@ class RealtimeAPITokenUsageProcessor(BaseTokenUsageProcessor): _RESPONSES_WS_BILLABLE_EVENT_TYPES: Final = frozenset({"response.completed", "response.incomplete"}) -class _ResponsesWsEventResponse(BaseModel): +class _ResponsesWsEventResponse(LiteLLMBaseModel): usage: Mapping[str, object] | None = None service_tier: str | None = None -class _ResponsesWsEvent(BaseModel): +class _ResponsesWsEvent(LiteLLMBaseModel): type: str = "" response: _ResponsesWsEventResponse | None = None diff --git a/litellm/google_genai/main.py b/litellm/google_genai/main.py index c1822e4720d..9ab3d78471c 100644 --- a/litellm/google_genai/main.py +++ b/litellm/google_genai/main.py @@ -5,7 +5,7 @@ from functools import partial from typing import TYPE_CHECKING, Any, ClassVar, Final import httpx -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict import litellm from litellm.constants import request_timeout @@ -17,6 +17,7 @@ from litellm.llms.base_llm.google_genai.transformation import ( BaseGoogleGenAIGenerateContentConfig, ) from litellm.llms.custom_httpx.llm_http_handler import BaseLLMHTTPHandler +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.router import GenericLiteLLMParams from litellm.types.utils import CallTypes from litellm.utils import ProviderConfigManager, client @@ -46,7 +47,7 @@ def _mark_async_entrypoint(logging_obj: LiteLLMLoggingObj | None, marker: str, i logging_obj.model_call_details.setdefault("litellm_params", {})[marker] = is_async -class GenerateContentSetupResult(BaseModel): +class GenerateContentSetupResult(LiteLLMBaseModel): """Internal Type - Result of setting up a generate content call""" model_config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True) diff --git a/litellm/harness/handlers/tool_loop_handler.py b/litellm/harness/handlers/tool_loop_handler.py index d3acb50eadb..e3276793fcb 100644 --- a/litellm/harness/handlers/tool_loop_handler.py +++ b/litellm/harness/handlers/tool_loop_handler.py @@ -12,7 +12,7 @@ from dataclasses import dataclass from types import MappingProxyType from typing import Final, Protocol, TypeAlias -from pydantic import BaseModel, ConfigDict, TypeAdapter, ValidationError +from pydantic import ConfigDict, TypeAdapter, ValidationError import litellm from litellm.harness.context import SessionContext @@ -28,6 +28,7 @@ from litellm.llms.tool_loop.harness.transformation import ( function_tool, ) from litellm.types.completion import ChatCompletionMessageParam +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import ( ChatCompletionMessageCustomToolCall, ChatCompletionMessageToolCall, @@ -52,7 +53,7 @@ _JSON_DECODER: Final = json.JSONDecoder() _HISTORY_ADAPTER: Final = TypeAdapter(list[dict[str, object]]) -class _Usage(BaseModel): +class _Usage(LiteLLMBaseModel): model_config = ConfigDict(from_attributes=True) prompt_tokens: int | None = None diff --git a/litellm/integrations/deepeval/types.py b/litellm/integrations/deepeval/types.py index c86d01d0468..eb4bb1f9b2a 100644 --- a/litellm/integrations/deepeval/types.py +++ b/litellm/integrations/deepeval/types.py @@ -2,7 +2,9 @@ from enum import Enum from typing import Any, ClassVar, Literal -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field + +from litellm.types.llms.base import LiteLLMBaseModel class SpanApiType(Enum): @@ -21,7 +23,7 @@ class TraceSpanApiStatus(Enum): ERRORED = "ERRORED" -class BaseApiSpan(BaseModel): +class BaseApiSpan(LiteLLMBaseModel): model_config: ClassVar[ConfigDict] = ConfigDict(use_enum_values=True) uuid: str @@ -44,7 +46,7 @@ class BaseApiSpan(BaseModel): cost_per_output_token: float | None = Field(None, alias="costPerOutputToken") -class TraceApi(BaseModel): +class TraceApi(LiteLLMBaseModel): uuid: str base_spans: list[BaseApiSpan] = Field(alias="baseSpans") agent_spans: list[BaseApiSpan] = Field(alias="agentSpans") diff --git a/litellm/integrations/galileo.py b/litellm/integrations/galileo.py index 9bc324256fb..56147cd720d 100644 --- a/litellm/integrations/galileo.py +++ b/litellm/integrations/galileo.py @@ -9,7 +9,7 @@ from datetime import datetime, timezone, tzinfo from typing import Any, Final, Protocol, cast import httpx -from pydantic import BaseModel, ConfigDict, Field, TypeAdapter +from pydantic import ConfigDict, Field, TypeAdapter from typing_extensions import ReadOnly, TypedDict import litellm @@ -24,6 +24,7 @@ from litellm.llms.custom_httpx.http_handler import ( httpxSpecialProvider, ) from litellm.types.integrations.base_health_check import IntegrationHealthCheckStatus +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import ( AllMessageValues, HttpxBinaryResponseContent, @@ -80,7 +81,7 @@ class GalileoStandardLoggingFields(TypedDict, total=False): endTime: float -class LLMResponse(BaseModel): +class LLMResponse(LiteLLMBaseModel): latency_ms: int status_code: int input_text: str diff --git a/litellm/integrations/langfuse/langfuse_sdk.py b/litellm/integrations/langfuse/langfuse_sdk.py index 986f35297d2..d117120dd70 100644 --- a/litellm/integrations/langfuse/langfuse_sdk.py +++ b/litellm/integrations/langfuse/langfuse_sdk.py @@ -34,13 +34,14 @@ from opentelemetry.sdk.trace.id_generator import RandomIdGenerator from opentelemetry.sdk.trace.sampling import ALWAYS_ON, Decision, Sampler, SamplingResult from opentelemetry.trace import Link, NonRecordingSpan, Span, SpanContext, SpanKind, TraceFlags, Tracer, TraceState from opentelemetry.util.types import Attributes, AttributeValue -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict import litellm from litellm._logging import verbose_logger from litellm.integrations.langfuse.langfuse import PROMPT_CACHE_TTL_ENV, parse_langfuse_debug, whole_number from litellm.litellm_core_utils.safe_json_dumps import safe_dumps from litellm.llms.custom_httpx.http_handler import HTTPHandler, _get_httpx_client +from litellm.types.llms.base import LiteLLMBaseModel __all__ = ( "AuthCheckFailure", @@ -1063,7 +1064,7 @@ def _auth_check_failure(reason: str) -> AuthCheckFailure: return AuthCheckFailure(reason) -class _ApiErrorDetail(BaseModel): +class _ApiErrorDetail(LiteLLMBaseModel): """The status and body of an ``ApiError``, whose own ``str`` also dumps every response header.""" model_config = ConfigDict(frozen=True, from_attributes=True) diff --git a/litellm/integrations/otel/model/config.py b/litellm/integrations/otel/model/config.py index 6e9038c0cad..3cf49ea2f11 100644 --- a/litellm/integrations/otel/model/config.py +++ b/litellm/integrations/otel/model/config.py @@ -4,7 +4,7 @@ from enum import Enum from functools import lru_cache from typing import Annotated, Final -from pydantic import AliasChoices, BaseModel, Field, TypeAdapter, ValidationError, field_validator, model_validator +from pydantic import AliasChoices, ConfigDict, Field, TypeAdapter, ValidationError, field_validator, model_validator from pydantic.fields import FieldInfo from pydantic_settings import BaseSettings, NoDecode, PydanticBaseSettingsSource, SettingsConfigDict @@ -15,6 +15,7 @@ from litellm.integrations.otel.model.baggage import ( DEFAULT_BAGGAGE_TEAM_METADATA_KEYS, ) from litellm.integrations.otel.model.spans import POSTGRESQL, db_system +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import OtelSpanScope #: Master feature-flag env var. The logger is inert until this is truthy. @@ -62,7 +63,7 @@ def is_otel_v2_enabled() -> bool: return _OTelV2Flag().enabled -class ExporterSpec(BaseModel): +class ExporterSpec(LiteLLMBaseModel): """One span-export destination. The shared ``TracerProvider`` attaches one ``SpanProcessor`` per spec, so @@ -70,7 +71,7 @@ class ExporterSpec(BaseModel): Phoenix + your own Honeycomb). """ - model_config = {"extra": "forbid"} + model_config = ConfigDict(extra="forbid") kind: str = Field( default="console", diff --git a/litellm/integrations/otel/model/destination.py b/litellm/integrations/otel/model/destination.py index c9c035f24a1..2b25ef16347 100644 --- a/litellm/integrations/otel/model/destination.py +++ b/litellm/integrations/otel/model/destination.py @@ -8,12 +8,13 @@ from collections.abc import Mapping from typing import Final from urllib.parse import quote -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import OtelSpanScope -class OtelDestination(BaseModel): +class OtelDestination(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) endpoint: str diff --git a/litellm/integrations/otel/model/request_io.py b/litellm/integrations/otel/model/request_io.py index a315dadba2d..4131f3de6da 100644 --- a/litellm/integrations/otel/model/request_io.py +++ b/litellm/integrations/otel/model/request_io.py @@ -1,12 +1,13 @@ from collections.abc import Mapping, Sequence from typing import Final, Literal -from pydantic import BaseModel, ConfigDict, Field, TypeAdapter, ValidationError +from pydantic import ConfigDict, Field, TypeAdapter, ValidationError from typing_extensions import ReadOnly, TypedDict import litellm from litellm.integrations.otel.mappers.utils import json_or_none from litellm.proxy.guardrails.anthropic_sse import assemble_anthropic_sse_stream, is_raw_sse_stream +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import ResponseCompletedEvent, ResponsesAPIResponse from litellm.types.utils import ModelResponse, ModelResponseStream @@ -20,7 +21,7 @@ class _Turn(TypedDict): content: ReadOnly[object] -class _AnthropicMessage(BaseModel): +class _AnthropicMessage(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) type: Literal["message"] = Field(exclude=True) diff --git a/litellm/integrations/pointfive/upload_client.py b/litellm/integrations/pointfive/upload_client.py index d3708d48661..8c4a281d04b 100644 --- a/litellm/integrations/pointfive/upload_client.py +++ b/litellm/integrations/pointfive/upload_client.py @@ -24,6 +24,7 @@ from litellm.types.integrations.pointfive import ( PointFiveUploadFailure, PointFiveUploadTarget, ) +from litellm.types.llms.base import LiteLLMBaseModel UPLOAD_KIND: Final = "LITELLM" UPLOAD_URL_PATH: Final = "/upload-url" @@ -31,21 +32,21 @@ PING_PATH: Final = "/ping" PUT_HEADERS: Final = MappingProxyType({"Content-Type": "application/x-ndjson", "Content-Encoding": "gzip"}) -class _PresignRequest(BaseModel): +class _PresignRequest(LiteLLMBaseModel): kind: str = UPLOAD_KIND byte_count: int = Field(serialization_alias="byteCount") -class _PingRequest(BaseModel): +class _PingRequest(LiteLLMBaseModel): kind: str = UPLOAD_KIND -class _TargetPayload(BaseModel): +class _TargetPayload(LiteLLMBaseModel): upload_url: str = Field(alias="uploadUrl") object_key: str = Field(alias="objectKey") -class _ErrorPayload(BaseModel): +class _ErrorPayload(LiteLLMBaseModel): error: str = "" diff --git a/litellm/integrations/prometheus_helpers/prometheus_api.py b/litellm/integrations/prometheus_helpers/prometheus_api.py index e111474bd4d..f8cdb2353b6 100644 --- a/litellm/integrations/prometheus_helpers/prometheus_api.py +++ b/litellm/integrations/prometheus_helpers/prometheus_api.py @@ -7,7 +7,7 @@ import time from datetime import datetime, timedelta from typing import Final -from pydantic import BaseModel, TypeAdapter +from pydantic import TypeAdapter from typing_extensions import ReadOnly, TypedDict from litellm import get_secret @@ -16,6 +16,7 @@ from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, httpxSpecialProvider, ) +from litellm.types.llms.base import LiteLLMBaseModel PROMETHEUS_URL: Final[str | None] = get_secret("PROMETHEUS_URL") PROMETHEUS_SELECTED_INSTANCE: Final[str | None] = get_secret("PROMETHEUS_SELECTED_INSTANCE") @@ -24,18 +25,18 @@ async_http_handler: Final = get_async_httpx_client(llm_provider=httpxSpecialProv _RAW_JSON_PAYLOAD: Final = TypeAdapter(object) -class PrometheusRangeSample(BaseModel): +class PrometheusRangeSample(LiteLLMBaseModel): """One ``matrix`` series of the Prometheus HTTP query API.""" metric: dict[str, object] values: list[tuple[float, str]] -class PrometheusQueryData(BaseModel): +class PrometheusQueryData(LiteLLMBaseModel): result: list[PrometheusRangeSample] -class PrometheusQueryResponse(BaseModel): +class PrometheusQueryResponse(LiteLLMBaseModel): data: PrometheusQueryData diff --git a/litellm/integrations/shadow_eval_logger.py b/litellm/integrations/shadow_eval_logger.py index 7f5d9fedd3d..76ba1d80841 100644 --- a/litellm/integrations/shadow_eval_logger.py +++ b/litellm/integrations/shadow_eval_logger.py @@ -40,6 +40,7 @@ from litellm.litellm_core_utils.llm_judge import ( from litellm.litellm_core_utils.redact_messages import should_redact_message_logging from litellm.llms.base_llm.base_utils import type_to_response_format_param from litellm.router_utils.common_utils import resolve_model_group_alias +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.management_endpoints.auto_router_endpoints import ShadowEvalDirection from litellm.types.utils import SHADOW_EVAL_JUDGE_CALL_ORIGIN, SHADOW_EVAL_ROUTER_CALL_ORIGIN @@ -467,7 +468,7 @@ Return ONLY valid JSON in this exact format, no other text: }""" -class PairwiseVerdict(BaseModel): +class PairwiseVerdict(LiteLLMBaseModel): """The judge's blind A/B verdict: the response_format schema sent with the judge call and the validation contract on its reply. Both fields are required and preference is closed over the prompt's labels, so a malformed or truncated reply is an @@ -731,7 +732,7 @@ class _JudgeVerdict: cost: float -class ActiveShadowEvalJob(BaseModel): +class ActiveShadowEvalJob(LiteLLMBaseModel): """One active job as the sampling path needs it, validated straight off the untyped job row: immutable config plus the attempt count as of the cache fill (the turn budget's staleness is bounded by the cache TTL). Every way a row can be unsamplable diff --git a/litellm/integrations/zerobus/client.py b/litellm/integrations/zerobus/client.py index bf3a9e3e269..b803b9d63bb 100644 --- a/litellm/integrations/zerobus/client.py +++ b/litellm/integrations/zerobus/client.py @@ -14,7 +14,7 @@ from collections.abc import Callable, Mapping, Sequence from typing import Final import httpx -from pydantic import BaseModel, ValidationError +from pydantic import ValidationError import litellm from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler @@ -25,12 +25,13 @@ from litellm.types.integrations.zerobus import ( ZerobusConnection, ZerobusIngestFailure, ) +from litellm.types.llms.base import LiteLLMBaseModel TOKEN_PATH: Final = "/oidc/v1/token" OAUTH_SCOPE: Final = "all-apis" -class _TokenResponse(BaseModel): +class _TokenResponse(LiteLLMBaseModel): access_token: str expires_in: float = 3600 diff --git a/litellm/interactions/background_cost_polling.py b/litellm/interactions/background_cost_polling.py index ca93436490d..21d438d9621 100644 --- a/litellm/interactions/background_cost_polling.py +++ b/litellm/interactions/background_cost_polling.py @@ -45,7 +45,7 @@ from datetime import datetime, timezone from types import MappingProxyType from typing import TYPE_CHECKING, Final, Literal, Protocol, TypeAlias -from pydantic import BaseModel, ConfigDict, JsonValue, TypeAdapter, ValidationError +from pydantic import ConfigDict, JsonValue, TypeAdapter, ValidationError from pydantic_core import PydanticSerializationError, to_jsonable_python from litellm._logging import verbose_logger @@ -57,6 +57,7 @@ from litellm.constants import ( ) from litellm.litellm_core_utils.core_helpers import get_litellm_metadata_from_kwargs from litellm.types.interactions import InteractionsAPIResponse +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import CustomPricingLiteLLMParams if TYPE_CHECKING: @@ -73,7 +74,7 @@ _STATUSES_THAT_PRODUCED_OUTPUT: Final = frozenset({"completed", "requires_action SettlementOutcome: TypeAlias = Literal["billed", "released", "unsettled"] -class BackgroundInteractionCreateContext(BaseModel): +class BackgroundInteractionCreateContext(LiteLLMBaseModel): """ The part of a create's logging state that billing its settled result needs, in a shape any replica can store and rebuild a logging object from. Provider diff --git a/litellm/litellm_core_utils/audio_utils/subtitle_utils.py b/litellm/litellm_core_utils/audio_utils/subtitle_utils.py index 91427ba09ad..34eee885911 100644 --- a/litellm/litellm_core_utils/audio_utils/subtitle_utils.py +++ b/litellm/litellm_core_utils/audio_utils/subtitle_utils.py @@ -6,7 +6,9 @@ from dataclasses import dataclass from itertools import accumulate, groupby from typing import Final -from pydantic import BaseModel, ConfigDict, TypeAdapter, ValidationError +from pydantic import ConfigDict, TypeAdapter, ValidationError + +from litellm.types.llms.base import LiteLLMBaseModel CUE_MAX_CHARS: Final = 84 CUE_MAX_DURATION_MS: Final = 7000 @@ -230,7 +232,7 @@ def render_subtitle_tokens_as_vtt(tokens: Sequence[SubtitleToken]) -> str: return _render_vtt(group_subtitle_tokens_into_cues(tokens)) -class TranscriptionWordTiming(BaseModel): +class TranscriptionWordTiming(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") word: str = "" diff --git a/litellm/litellm_core_utils/cli_token_utils.py b/litellm/litellm_core_utils/cli_token_utils.py index ee506a69ef9..ab386e10951 100644 --- a/litellm/litellm_core_utils/cli_token_utils.py +++ b/litellm/litellm_core_utils/cli_token_utils.py @@ -20,7 +20,7 @@ from pathlib import Path from types import MappingProxyType from typing import Final, TypeAlias -from pydantic import BaseModel, ConfigDict, ValidationError +from pydantic import ConfigDict, ValidationError from litellm.litellm_core_utils.cli_keyring import ( SYSTEM_KEYRING, @@ -44,6 +44,7 @@ from litellm.litellm_core_utils.private_json import ( stage_private_json, write_private_json, ) +from litellm.types.llms.base import LiteLLMBaseModel @dataclass(frozen=True, slots=True) @@ -83,7 +84,7 @@ SecretSave: TypeAlias = SecretWrite | CredentialNotSaved | CredentialNotRecorded SecretClear: TypeAlias = SecretErase | CredentialNotCleared -class CliTokenRecord(BaseModel): +class CliTokenRecord(LiteLLMBaseModel): """A stored CLI credential. `key is None` means the metadata was found but the secret could not be @@ -104,7 +105,7 @@ class CliTokenRecord(BaseModel): refresh_token: str | None = None -class CliTokenSecret(BaseModel): +class CliTokenSecret(LiteLLMBaseModel): """The secret material as stored in the OS keychain. `base_url` is duplicated from the metadata file purely as a pairing tag: a diff --git a/litellm/litellm_core_utils/get_blog_posts.py b/litellm/litellm_core_utils/get_blog_posts.py index 25a5c7cd9ab..276d2a968a1 100644 --- a/litellm/litellm_core_utils/get_blog_posts.py +++ b/litellm/litellm_core_utils/get_blog_posts.py @@ -17,21 +17,21 @@ from importlib.resources import files from typing import Final import httpx -from pydantic import BaseModel from litellm import verbose_logger +from litellm.types.llms.base import LiteLLMBaseModel BLOG_POSTS_TTL_SECONDS: Final[int] = 3600 # 1 hour -class BlogPost(BaseModel): +class BlogPost(LiteLLMBaseModel): title: str description: str date: str url: str -class BlogPostsResponse(BaseModel): +class BlogPostsResponse(LiteLLMBaseModel): posts: list[BlogPost] diff --git a/litellm/litellm_core_utils/llm_cost_calc/guardrail_cost.py b/litellm/litellm_core_utils/llm_cost_calc/guardrail_cost.py index 19adf1a30a7..61ec2fc39c1 100644 --- a/litellm/litellm_core_utils/llm_cost_calc/guardrail_cost.py +++ b/litellm/litellm_core_utils/llm_cost_calc/guardrail_cost.py @@ -2,22 +2,23 @@ import math from collections.abc import Mapping from typing import Annotated, Final -from pydantic import BaseModel, ConfigDict, Field, TypeAdapter, ValidationError +from pydantic import ConfigDict, Field, TypeAdapter, ValidationError import litellm from litellm._logging import verbose_logger +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import CostBreakdown BEDROCK_GUARDRAIL_PRICING_KEY: Final = "bedrock/guardrails" -class GuardrailPricing(BaseModel): +class GuardrailPricing(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", frozen=True) guardrail_cost_per_unit: Mapping[str, float] -class GuardrailCostEntry(BaseModel): +class GuardrailCostEntry(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", frozen=True) guardrail_cost: float | None = None @@ -30,7 +31,7 @@ class GuardrailCostEntry(BaseModel): _GUARDRAIL_COST_ENTRY_ADAPTER: Final[TypeAdapter[GuardrailCostEntry]] = TypeAdapter(GuardrailCostEntry) -class GuardrailCostByUnitEntry(BaseModel): +class GuardrailCostByUnitEntry(LiteLLMBaseModel): """The rollup-side view of a ``guardrail_information`` entry, validated apart from ``GuardrailCostEntry`` so a forged per-counter map can never zero the spend path.""" diff --git a/litellm/litellm_core_utils/prompt_templates/factory.py b/litellm/litellm_core_utils/prompt_templates/factory.py index 90a60a9e46c..4f6d9af487b 100644 --- a/litellm/litellm_core_utils/prompt_templates/factory.py +++ b/litellm/litellm_core_utils/prompt_templates/factory.py @@ -12,6 +12,7 @@ from types import MappingProxyType from typing import Any, Final, TypeAlias, TypedDict, cast, overload from jinja2.sandbox import ImmutableSandboxedEnvironment +from pydantic import BaseModel import litellm import litellm.types diff --git a/litellm/litellm_core_utils/served_output_texts.py b/litellm/litellm_core_utils/served_output_texts.py index 323561a3dd2..2788720448b 100644 --- a/litellm/litellm_core_utils/served_output_texts.py +++ b/litellm/litellm_core_utils/served_output_texts.py @@ -6,8 +6,9 @@ from __future__ import annotations from collections.abc import Sequence from typing import Final, Literal -from pydantic import BaseModel, TypeAdapter, ValidationError +from pydantic import BaseModel, Field, TypeAdapter, ValidationError +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import ModelResponse, ModelResponseStream SERVED_OUTPUT_TEXTS_KEY: Final = "served_output_texts" @@ -19,27 +20,27 @@ _TEXTS: Final = TypeAdapter(tuple[str | None, ...]) ServedTexts = tuple[str | None, ...] -class _TextBlock(BaseModel): +class _TextBlock(LiteLLMBaseModel): type: str text: str | None = None -class _AnthropicMessage(BaseModel): +class _AnthropicMessage(LiteLLMBaseModel): type: Literal["message"] content: list[_TextBlock] -class _ResponsesOutputItem(BaseModel): +class _ResponsesOutputItem(LiteLLMBaseModel): type: str - content: list[_TextBlock] = [] + content: list[_TextBlock] = Field(default=[]) -class _ResponsesResponse(BaseModel): +class _ResponsesResponse(LiteLLMBaseModel): object: Literal["response"] output: list[_ResponsesOutputItem] -class _ChatChoices(BaseModel): +class _ChatChoices(LiteLLMBaseModel): choices: list[object] diff --git a/litellm/litellm_core_utils/streaming_handler.py b/litellm/litellm_core_utils/streaming_handler.py index 9d33f86d841..6080d52ea89 100644 --- a/litellm/litellm_core_utils/streaming_handler.py +++ b/litellm/litellm_core_utils/streaming_handler.py @@ -25,6 +25,7 @@ from litellm.litellm_core_utils.model_response_utils import ( ) from litellm.litellm_core_utils.redact_messages import LiteLLMLoggingObject from litellm.litellm_core_utils.thread_pool_executor import executor +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import OpenAIChatCompletionChunk from litellm.types.router import GenericLiteLLMParams from litellm.types.utils import ( @@ -164,7 +165,7 @@ class _VertexChunkLike(Protocol): candidates: Sequence[_VertexCandidateLike] -class _ParsedChunkHiddenParams(BaseModel): +class _ParsedChunkHiddenParams(LiteLLMBaseModel): provider_specific_fields: Mapping[str, object] | None = None diff --git a/litellm/llms/anthropic/cache_aware_routing.py b/litellm/llms/anthropic/cache_aware_routing.py index e1a50781ace..024631c961a 100644 --- a/litellm/llms/anthropic/cache_aware_routing.py +++ b/litellm/llms/anthropic/cache_aware_routing.py @@ -7,7 +7,7 @@ from types import MappingProxyType from typing import Final from urllib.parse import urlparse -from pydantic import BaseModel, JsonValue, TypeAdapter +from pydantic import JsonValue, TypeAdapter import litellm from litellm._internal_context import current_billing_time, pinned_billing_time @@ -25,6 +25,7 @@ from litellm.llms.anthropic.prompt_cache_prediction import ( ) from litellm.proxy.common_utils.prompt_cache_pricing import price_cache_tokens from litellm.proxy.hooks.prompt_cache_prediction import lookup +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.management_endpoints.prompt_cache_prediction import ( CacheCostScenario, CacheEvidence, @@ -57,7 +58,7 @@ _NATIVE_OPTIONS: Final = frozenset( ) -class _ModelLimits(BaseModel): +class _ModelLimits(LiteLLMBaseModel): max_input_tokens: int | None = None max_output_tokens: int | None = None diff --git a/litellm/llms/anthropic/common_utils.py b/litellm/llms/anthropic/common_utils.py index 476e154ed0f..049f474032c 100644 --- a/litellm/llms/anthropic/common_utils.py +++ b/litellm/llms/anthropic/common_utils.py @@ -12,7 +12,7 @@ from typing import Any, ClassVar, Final, Literal, TypeVar from urllib.parse import quote import httpx -from pydantic import BaseModel, ConfigDict, Field, StrictBool, TypeAdapter, ValidationError +from pydantic import ConfigDict, Field, StrictBool, TypeAdapter, ValidationError import litellm from litellm.constants import ( @@ -51,6 +51,7 @@ from litellm.types.llms.anthropic import ( AnthropicMessagesToolChoice, AnthropicThinkingParam, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import AllMessageValues from litellm.types.proxy.auth.special_headers import SpecialHeaders from litellm.types.proxy.model_listing import ModelInfoResponse @@ -349,11 +350,11 @@ def optionally_handle_anthropic_oauth(headers: dict, api_key: str | None) -> tup return headers, api_key -class _EagerInputStreamingFunction(BaseModel): +class _EagerInputStreamingFunction(LiteLLMBaseModel): eager_input_streaming: StrictBool | None = None -class _EagerInputStreamingTool(BaseModel): +class _EagerInputStreamingTool(LiteLLMBaseModel): eager_input_streaming: StrictBool | None = None function: _EagerInputStreamingFunction | None = None @@ -388,11 +389,11 @@ def _litellm_params_str(litellm_params: Mapping[str, object] | None, key: str) - return value if isinstance(value, str) else None -class _AnthropicModelListEntry(BaseModel): +class _AnthropicModelListEntry(LiteLLMBaseModel): id: str -class _AnthropicModelsPage(BaseModel): +class _AnthropicModelsPage(LiteLLMBaseModel): data: Sequence[_AnthropicModelListEntry] = Field(default_factory=tuple) has_more: bool = False last_id: str | None = None @@ -1784,13 +1785,13 @@ def sanitize_tool_use_ids_in_anthropic_messages(messages: list[Any]) -> list[Any return out -class _ReplayedSearchQuery(BaseModel): +class _ReplayedSearchQuery(LiteLLMBaseModel): model_config = ConfigDict(extra="allow") query: str = "" -class _ReplayedWebSearchResult(BaseModel): +class _ReplayedWebSearchResult(LiteLLMBaseModel): model_config = ConfigDict(extra="allow") type: Literal["web_search_result"] @@ -1800,14 +1801,14 @@ class _ReplayedWebSearchResult(BaseModel): encrypted_content: str = "" -class _ReplayedWebSearchToolResultError(BaseModel): +class _ReplayedWebSearchToolResultError(LiteLLMBaseModel): model_config = ConfigDict(extra="allow") type: Literal["web_search_tool_result_error"] error_code: str = "" -class _ReplayedWebSearchToolResult(BaseModel): +class _ReplayedWebSearchToolResult(LiteLLMBaseModel): model_config = ConfigDict(extra="allow") type: Literal["web_search_tool_result"] @@ -1815,7 +1816,7 @@ class _ReplayedWebSearchToolResult(BaseModel): content: tuple[_ReplayedWebSearchResult, ...] | _ReplayedWebSearchToolResultError -class _ReplayedServerToolUse(BaseModel): +class _ReplayedServerToolUse(LiteLLMBaseModel): model_config = ConfigDict(extra="allow") type: Literal["server_tool_use"] @@ -1823,7 +1824,7 @@ class _ReplayedServerToolUse(BaseModel): input: _ReplayedSearchQuery = _ReplayedSearchQuery() -class _TextBlock(BaseModel): +class _TextBlock(LiteLLMBaseModel): type: Literal["text"] = "text" text: str diff --git a/litellm/llms/anthropic/cost_calculation.py b/litellm/llms/anthropic/cost_calculation.py index 4a935ac18b4..88805df2b08 100644 --- a/litellm/llms/anthropic/cost_calculation.py +++ b/litellm/llms/anthropic/cost_calculation.py @@ -5,13 +5,14 @@ Helper util for handling anthropic-specific cost calculation from typing import TYPE_CHECKING, Final, Optional -from pydantic import BaseModel, ValidationError +from pydantic import ValidationError from litellm.litellm_core_utils.llm_cost_calc.utils import ( generic_cost_per_token, get_provider_specific_geo_multiplier, get_web_search_requests_from_usage, ) +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: from litellm.types.utils import ModelInfo, Usage @@ -71,15 +72,15 @@ def cost_per_token( return prompt_cost, completion_cost -class _AnthropicServerToolUseProbe(BaseModel): +class _AnthropicServerToolUseProbe(LiteLLMBaseModel): web_search_requests: int | None = None -class _AnthropicUsageProbe(BaseModel): +class _AnthropicUsageProbe(LiteLLMBaseModel): server_tool_use: _AnthropicServerToolUseProbe | None = None -class _AnthropicResponseProbe(BaseModel): +class _AnthropicResponseProbe(LiteLLMBaseModel): usage: _AnthropicUsageProbe | None = None diff --git a/litellm/llms/anthropic/pass_through/responses_adapters/streaming_iterator.py b/litellm/llms/anthropic/pass_through/responses_adapters/streaming_iterator.py index cc6f4da3403..450640f47b9 100644 --- a/litellm/llms/anthropic/pass_through/responses_adapters/streaming_iterator.py +++ b/litellm/llms/anthropic/pass_through/responses_adapters/streaming_iterator.py @@ -6,7 +6,7 @@ from collections import deque from collections.abc import AsyncIterator, Iterator, Mapping from typing import TYPE_CHECKING, Any, Final -from pydantic import BaseModel, ConfigDict, field_validator +from pydantic import ConfigDict, field_validator from litellm import verbose_logger from litellm._logging import redact_internal_details_from_client_message @@ -22,6 +22,7 @@ from litellm.llms.anthropic.pass_through.messages.utils import ( ) from litellm.responses.streaming_iterator import stream_error_status_and_message from litellm.types.llms.anthropic_messages.anthropic_response import AnthropicUsage +from litellm.types.llms.base import LiteLLMBaseModel from .transformation import ( REASONING_SUMMARY_PART_SEPARATOR, @@ -32,7 +33,7 @@ if TYPE_CHECKING: from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObject -class _UpstreamFailure(BaseModel): +class _UpstreamFailure(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) status_code: int | None = None @@ -56,13 +57,13 @@ class _UpstreamFailure(BaseModel): return value if isinstance(value, str) else None -class _FailedResponse(BaseModel): +class _FailedResponse(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, from_attributes=True) error: object | None = None -class _FailedResponseEvent(BaseModel): +class _FailedResponseEvent(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, from_attributes=True) response: _FailedResponse | None = None diff --git a/litellm/llms/anthropic/pass_through/utils.py b/litellm/llms/anthropic/pass_through/utils.py index 335a0e5641d..95baecbfbfe 100644 --- a/litellm/llms/anthropic/pass_through/utils.py +++ b/litellm/llms/anthropic/pass_through/utils.py @@ -3,9 +3,10 @@ from collections.abc import Mapping from types import MappingProxyType from typing import TYPE_CHECKING, Final -from pydantic import BaseModel, ConfigDict, ValidationError +from pydantic import ConfigDict, ValidationError import litellm +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import ModelInfo if TYPE_CHECKING: @@ -23,7 +24,7 @@ _EFFORT_DEGRADATION_CHAIN: Final[Mapping[str, tuple[str, ...]]] = MappingProxyTy _THINKING_OFF: Final = "none" -class _ClaudeCodeUserId(BaseModel): +class _ClaudeCodeUserId(LiteLLMBaseModel): """The JSON Claude Code packs into ``metadata.user_id``; only ``session_id`` is per conversation.""" model_config = ConfigDict(frozen=True) diff --git a/litellm/llms/anthropic/prompt_cache_prediction.py b/litellm/llms/anthropic/prompt_cache_prediction.py index ff304e845f7..00fe56a5e39 100644 --- a/litellm/llms/anthropic/prompt_cache_prediction.py +++ b/litellm/llms/anthropic/prompt_cache_prediction.py @@ -10,7 +10,7 @@ from types import MappingProxyType from typing import Annotated, Final, Literal, Protocol, TypeAlias import httpx -from pydantic import BaseModel, ConfigDict, Field, JsonValue, StrictInt, TypeAdapter, ValidationError +from pydantic import ConfigDict, Field, JsonValue, StrictInt, TypeAdapter, ValidationError import litellm from litellm.llms.anthropic.common_utils import AnthropicModelInfo, is_anthropic_oauth_key @@ -20,6 +20,7 @@ from litellm.llms.anthropic.pass_through.messages.transformation import ( DEFAULT_ANTHROPIC_API_VERSION, AnthropicMessagesConfig, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.router import LiteLLM_Params from litellm.types.utils import ModelResponse from litellm.utils import supports_thinking_cache_preservation @@ -65,7 +66,7 @@ _DEPLOYMENT_OPTIONS: Final = frozenset( ) -class _StrictModel(BaseModel): +class _StrictModel(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True, strict=True) @@ -455,37 +456,37 @@ def cache_scope( return _digest((caller_key_hash, deployment_id, provider_key, model, anthropic_version)) -class _TTLUsage(BaseModel): +class _TTLUsage(LiteLLMBaseModel): model_config = ConfigDict(strict=True) ephemeral_5m_input_tokens: int = Field(default=0, ge=0) ephemeral_1h_input_tokens: int = Field(default=0, ge=0) -class _CacheUsage(BaseModel): +class _CacheUsage(LiteLLMBaseModel): model_config = ConfigDict(strict=True) cached_tokens: int = Field(default=0, ge=0) cache_creation_tokens: int = Field(default=0, ge=0) cache_creation_token_details: _TTLUsage | None = None -class _Usage(BaseModel): +class _Usage(LiteLLMBaseModel): model_config = ConfigDict(strict=True) prompt_tokens: int = Field(ge=0) prompt_tokens_details: _CacheUsage -class _Choice(BaseModel): +class _Choice(LiteLLMBaseModel): finish_reason: str = Field(min_length=1) -class _Response(BaseModel): +class _Response(LiteLLMBaseModel): model_config = ConfigDict(strict=True) model: str usage: _Usage choices: tuple[_Choice, ...] = Field(min_length=1, strict=False) -class _CountBody(BaseModel): +class _CountBody(LiteLLMBaseModel): messages: Sequence[Mapping[str, JsonValue]] tools: Sequence[Mapping[str, JsonValue]] | None = None system: str | Sequence[Mapping[str, JsonValue]] | None = None @@ -494,7 +495,7 @@ class _CountBody(BaseModel): output_config: Mapping[str, JsonValue] | None = None -class _CountResult(BaseModel): +class _CountResult(LiteLLMBaseModel): input_tokens: Annotated[StrictInt, Field(ge=0)] diff --git a/litellm/llms/anthropic/wif.py b/litellm/llms/anthropic/wif.py index b096a11ace4..2444a8f833e 100644 --- a/litellm/llms/anthropic/wif.py +++ b/litellm/llms/anthropic/wif.py @@ -10,7 +10,7 @@ from types import MappingProxyType from typing import Final, NoReturn, TypeVar from urllib.parse import urlsplit, urlunsplit -from pydantic import BaseModel, ConfigDict, ValidationError +from pydantic import ConfigDict, ValidationError from typing_extensions import assert_never import litellm @@ -42,6 +42,7 @@ from litellm.llms.base_llm.auth.types import ( TokenTransportError, ) from litellm.types.llms.anthropic import ANTHROPIC_TOKEN_EXCHANGE_PATH +from litellm.types.llms.base import LiteLLMBaseModel _JWT_BEARER_GRANT_TYPE: Final = "urn:ietf:params:oauth:grant-type:jwt-bearer" _DEFAULT_API_BASE: Final = "https://api.anthropic.com" @@ -119,7 +120,7 @@ _EMPTY_PARAMS: Final[Mapping[str, object]] = MappingProxyType({}) _IdentitySourceVariant = TypeVar("_IdentitySourceVariant", bound="InternalIssuerSource | KeycloakSource") -class AnthropicWifParams(BaseModel): +class AnthropicWifParams(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) federation_rule_id: str diff --git a/litellm/llms/azure/passthrough/transformation.py b/litellm/llms/azure/passthrough/transformation.py index 8ea0ead2e91..ff83151626a 100644 --- a/litellm/llms/azure/passthrough/transformation.py +++ b/litellm/llms/azure/passthrough/transformation.py @@ -5,7 +5,7 @@ from typing import TYPE_CHECKING, Final, Optional import httpx from httpx import Response -from pydantic import BaseModel, ValidationError +from pydantic import ValidationError from litellm.litellm_core_utils.litellm_logging import Logging from litellm.llms.azure.common_utils import BaseAzureLLM @@ -17,6 +17,7 @@ from litellm.llms.base_llm.passthrough.transformation import ( strip_leading_model_segment, ) from litellm.secret_managers.main import get_secret_str +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import AllMessageValues, ResponsesAPIResponse, ResponsesTerminalEvent from litellm.types.router import GenericLiteLLMParams from litellm.types.utils import CallTypes, EmbeddingResponse, ImageResponse @@ -27,11 +28,11 @@ if TYPE_CHECKING: from litellm.llms.base_llm.passthrough.transformation import LoggedRelayResponse -class RelayedChatRequest(BaseModel): +class RelayedChatRequest(LiteLLMBaseModel): messages: Sequence[Mapping[str, object]] | None = None -class RelayedCallDetails(BaseModel): +class RelayedCallDetails(LiteLLMBaseModel): request_data: RelayedChatRequest | None = None diff --git a/litellm/llms/azure/search/transformation.py b/litellm/llms/azure/search/transformation.py index 45ad78df687..185aedc4ad6 100644 --- a/litellm/llms/azure/search/transformation.py +++ b/litellm/llms/azure/search/transformation.py @@ -33,7 +33,7 @@ from types import MappingProxyType from typing import TYPE_CHECKING, Final, Literal import httpx -from pydantic import BaseModel, ConfigDict, ValidationError +from pydantic import ConfigDict, ValidationError from litellm.llms.base_llm.chat.transformation import BaseLLMException from litellm.llms.base_llm.search.transformation import ( @@ -42,6 +42,7 @@ from litellm.llms.base_llm.search.transformation import ( SearchResult, ) from litellm.secret_managers.main import get_secret_str +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj @@ -61,7 +62,7 @@ _UPSTREAM_ERROR_STATUS: Final = 502 _RESPONSE_COST_HEADER: Final = "llm_provider-x-litellm-response-cost" -class _Annotation(BaseModel): +class _Annotation(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", frozen=True) type: str = "" @@ -71,7 +72,7 @@ class _Annotation(BaseModel): end_index: int | None = None -class _ContentPart(BaseModel): +class _ContentPart(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", frozen=True) type: str = "" @@ -79,26 +80,26 @@ class _ContentPart(BaseModel): annotations: tuple[_Annotation, ...] = () -class _OutputItem(BaseModel): +class _OutputItem(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", frozen=True) type: str = "" content: tuple[_ContentPart, ...] = () -class _ErrorBody(BaseModel): +class _ErrorBody(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", frozen=True) message: str | None = None -class _IncompleteDetails(BaseModel): +class _IncompleteDetails(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", frozen=True) reason: str | None = None -class _ResponsesEnvelope(BaseModel): +class _ResponsesEnvelope(LiteLLMBaseModel): """A Foundry Responses API body. `output` is required: a body without it is not a Responses API response and must not be reported as a successful empty search. @@ -113,7 +114,7 @@ class _ResponsesEnvelope(BaseModel): incomplete_details: _IncompleteDetails | None = None -class _ErrorEnvelope(BaseModel): +class _ErrorEnvelope(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", frozen=True) error: _ErrorBody | None = None @@ -205,41 +206,41 @@ def _capped(results: tuple[SearchResult, ...], max_results: int | None) -> tuple return results[:max_results] if max_results is not None else results -class _SearchConfiguration(BaseModel): +class _SearchConfiguration(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) project_connection_id: str count: int | None = None -class _BingGroundingParams(BaseModel): +class _BingGroundingParams(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) search_configurations: tuple[_SearchConfiguration, ...] -class _BingGroundingTool(BaseModel): +class _BingGroundingTool(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) type: Literal["bing_grounding"] = "bing_grounding" bing_grounding: _BingGroundingParams -class _UserLocation(BaseModel): +class _UserLocation(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) type: Literal["approximate"] = "approximate" country: str -class _WebSearchTool(BaseModel): +class _WebSearchTool(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) type: Literal["web_search"] = "web_search" user_location: _UserLocation | None = None -class _ResponsesRequest(BaseModel): +class _ResponsesRequest(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) model: str diff --git a/litellm/llms/base_llm/auth/client_credentials.py b/litellm/llms/base_llm/auth/client_credentials.py index bf86dc6508f..715eda7db89 100644 --- a/litellm/llms/base_llm/auth/client_credentials.py +++ b/litellm/llms/base_llm/auth/client_credentials.py @@ -18,7 +18,7 @@ from typing import TYPE_CHECKING, Final, TypeAlias from urllib.parse import quote, quote_plus, urlencode import httpx -from pydantic import BaseModel, SecretStr, ValidationError +from pydantic import SecretStr, ValidationError from typing_extensions import assert_never from litellm.llms.base_llm.auth.identity_source import KeycloakSource, ref_for_error_message @@ -30,6 +30,7 @@ from litellm.llms.base_llm.auth.token_exchange import ( validate_token_endpoint_url, ) from litellm.llms.base_llm.auth.types import InsecureTokenUrl, SyncTokenPoster +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: from litellm.llms.custom_httpx.http_handler import HTTPHandler @@ -41,7 +42,7 @@ _TIMEOUT_SECONDS: Final = 30.0 _FORM_CONTENT_TYPE: Final = "application/x-www-form-urlencoded" -class _ClientCredentialsResponse(BaseModel): +class _ClientCredentialsResponse(LiteLLMBaseModel): access_token: str diff --git a/litellm/llms/base_llm/auth/identity_source.py b/litellm/llms/base_llm/auth/identity_source.py index f8f02249b3c..0898b7b0b8b 100644 --- a/litellm/llms/base_llm/auth/identity_source.py +++ b/litellm/llms/base_llm/auth/identity_source.py @@ -11,7 +11,9 @@ import hashlib from enum import Enum from typing import Annotated, Final, Literal, TypeAlias -from pydantic import BaseModel, ConfigDict, Field, TypeAdapter +from pydantic import ConfigDict, Field, TypeAdapter + +from litellm.types.llms.base import LiteLLMBaseModel _REF_HASH_HEX_LENGTH: Final = 16 _MAX_TTL_SECONDS: Final = 3600 @@ -23,7 +25,7 @@ class AnthropicIdentitySourceKind(str, Enum): keycloak = "keycloak" -class InternalIssuerSource(BaseModel): +class InternalIssuerSource(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="forbid", hide_input_in_errors=True) kind: Literal[AnthropicIdentitySourceKind.internal_issuer] = AnthropicIdentitySourceKind.internal_issuer @@ -34,7 +36,7 @@ class InternalIssuerSource(BaseModel): signing_key_ref: str -class KeycloakSource(BaseModel): +class KeycloakSource(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="forbid", hide_input_in_errors=True) kind: Literal[AnthropicIdentitySourceKind.keycloak] = AnthropicIdentitySourceKind.keycloak diff --git a/litellm/llms/base_llm/auth/shared_token_store.py b/litellm/llms/base_llm/auth/shared_token_store.py index 878df1dc6fb..772a9a2ad9e 100644 --- a/litellm/llms/base_llm/auth/shared_token_store.py +++ b/litellm/llms/base_llm/auth/shared_token_store.py @@ -16,9 +16,10 @@ from dataclasses import dataclass from pathlib import Path from typing import Final, Protocol -from pydantic import BaseModel, SecretStr, ValidationError +from pydantic import SecretStr, ValidationError from litellm._logging import verbose_logger +from litellm.types.llms.base import LiteLLMBaseModel CACHE_DIR_ENV: Final = "LITELLM_TOKEN_EXCHANGE_CACHE_DIR" @@ -43,7 +44,7 @@ class SharedTokenStore(Protocol): def lock(self, key: str) -> contextlib.AbstractContextManager[None]: ... -class _StoredTokenFile(BaseModel): +class _StoredTokenFile(LiteLLMBaseModel): access_token: str expires_at_epoch: float | None assertion_sha256: str diff --git a/litellm/llms/base_llm/auth/token_exchange.py b/litellm/llms/base_llm/auth/token_exchange.py index 5f4b8c00bba..5bf1f4dd0db 100644 --- a/litellm/llms/base_llm/auth/token_exchange.py +++ b/litellm/llms/base_llm/auth/token_exchange.py @@ -23,7 +23,7 @@ from typing import TYPE_CHECKING, Final, Protocol, TypeAlias from urllib.parse import unquote, unquote_plus, urlencode, urlsplit, urlunsplit import httpx -from pydantic import BaseModel, SecretStr, TypeAdapter, ValidationError +from pydantic import SecretStr, TypeAdapter, ValidationError from typing_extensions import assert_never from litellm._logging import verbose_logger @@ -44,6 +44,7 @@ from litellm.llms.base_llm.auth.types import ( TokenExchangeSpec, TokenTransportError, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.services import ServiceTypes if TYPE_CHECKING: @@ -86,7 +87,7 @@ _CREDENTIAL_CHARS: Final = re.compile(r"[^A-Za-z0-9._~+/=-]") _SENTINEL_BODY_MESSAGES: Final = frozenset({_OVERSIZED_BODY_MESSAGE, _NON_OBJECT_BODY_MESSAGE}) -class _TokenExchangeResponse(BaseModel): +class _TokenExchangeResponse(LiteLLMBaseModel): access_token: str expires_in: int | None = None token_type: str | None = None diff --git a/litellm/llms/base_llm/passthrough/transformation.py b/litellm/llms/base_llm/passthrough/transformation.py index 84cbd4204e3..f75f9159070 100644 --- a/litellm/llms/base_llm/passthrough/transformation.py +++ b/litellm/llms/base_llm/passthrough/transformation.py @@ -6,8 +6,9 @@ from collections.abc import Callable, Mapping, Sequence from dataclasses import dataclass from typing import TYPE_CHECKING, Final, Protocol, TypeAlias -from pydantic import BaseModel, ConfigDict, TypeAdapter, ValidationError +from pydantic import ConfigDict, TypeAdapter, ValidationError +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import CallTypes from ..base_utils import BaseLLMModelInfo @@ -29,7 +30,7 @@ if TYPE_CHECKING: RELAYED_JSON_OBJECT: Final = TypeAdapter(Mapping[str, object]) -class PassthroughMetadata(BaseModel): +class PassthroughMetadata(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") model_group: str = "" diff --git a/litellm/llms/bedrock/base_aws_llm.py b/litellm/llms/bedrock/base_aws_llm.py index badb76d00c7..626b0d78589 100644 --- a/litellm/llms/bedrock/base_aws_llm.py +++ b/litellm/llms/bedrock/base_aws_llm.py @@ -15,7 +15,7 @@ from types import MappingProxyType from typing import TYPE_CHECKING, Any, ClassVar, Final, Literal, ParamSpec, TypeVar, cast, get_args, overload import httpx -from pydantic import BaseModel, TypeAdapter, ValidationError +from pydantic import TypeAdapter, ValidationError from typing_extensions import NotRequired, ReadOnly, TypedDict from litellm._logging import verbose_logger @@ -33,6 +33,7 @@ from litellm.constants import ( from litellm.litellm_core_utils.aws_partition import contains_bedrock_arn, get_aws_dns_suffix from litellm.litellm_core_utils.dd_tracing import tracer from litellm.secret_managers.main import get_secret, get_secret_str +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.bedrock import AWS_AUTH_PARAM_KEYS, AwsAuthParams, AwsSessionTag if TYPE_CHECKING: @@ -176,7 +177,7 @@ def pop_aws_auth_params( ) -class BedrockRequestTarget(BaseModel): +class BedrockRequestTarget(LiteLLMBaseModel): aws_region_name: str aws_bedrock_runtime_endpoint: str | None @@ -194,7 +195,7 @@ def bedrock_bearer_token(api_key: str | None) -> str | None: return token or None -class _WebIdentityTokenClaims(BaseModel): +class _WebIdentityTokenClaims(LiteLLMBaseModel): aud: str | list[str] | None = None iss: str | None = None diff --git a/litellm/llms/bedrock/embed/twelvelabs_marengo_3_transformation.py b/litellm/llms/bedrock/embed/twelvelabs_marengo_3_transformation.py index 4aac6f22bae..44084e30961 100644 --- a/litellm/llms/bedrock/embed/twelvelabs_marengo_3_transformation.py +++ b/litellm/llms/bedrock/embed/twelvelabs_marengo_3_transformation.py @@ -9,10 +9,11 @@ from collections.abc import Mapping from types import MappingProxyType from typing import Final -from pydantic import BaseModel, ConfigDict, TypeAdapter, ValidationError +from pydantic import ConfigDict, TypeAdapter, ValidationError from typing_extensions import assert_never from litellm.llms.bedrock.common_utils import BedrockError +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.bedrock import ( TWELVELABS_MARENGO_3_EMBEDDING_OPTIONS, TWELVELABS_MARENGO_3_EMBEDDING_SCOPES, @@ -57,7 +58,7 @@ def is_marengo_3_model(model: str | None) -> bool: return MARENGO_3_MODEL_MARKER in (model or "") -class Marengo3Params(BaseModel): +class Marengo3Params(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", frozen=True) inputType: TWELVELABS_MARENGO_3_INPUT_TYPES | None = None diff --git a/litellm/llms/bedrock/embed/twelvelabs_marengo_transformation.py b/litellm/llms/bedrock/embed/twelvelabs_marengo_transformation.py index 65ca2be191f..9391068b8aa 100644 --- a/litellm/llms/bedrock/embed/twelvelabs_marengo_transformation.py +++ b/litellm/llms/bedrock/embed/twelvelabs_marengo_transformation.py @@ -10,7 +10,7 @@ Marengo 3.0 docs - https://docs.aws.amazon.com/bedrock/latest/userguide/model-pa from collections.abc import Mapping from typing import Final, cast -from pydantic import BaseModel, ConfigDict, TypeAdapter +from pydantic import ConfigDict, TypeAdapter from typing_extensions import assert_never import litellm @@ -19,6 +19,7 @@ from litellm.llms.bedrock.embed.twelvelabs_marengo_3_transformation import ( build_marengo_3_request, is_marengo_3_model, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.bedrock import ( TWELVELABS_EMBEDDING_INPUT_TYPES, TWELVELABS_MARENGO_3_INPUT_TYPES, @@ -32,13 +33,13 @@ from litellm.types.llms.bedrock import ( from litellm.types.utils import Embedding, EmbeddingResponse, PromptTokensDetailsWrapper, Usage -class MarengoEmbeddingItem(BaseModel): +class MarengoEmbeddingItem(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", frozen=True) embedding: tuple[float, ...] | None = None -class MarengoInvokeResponse(BaseModel): +class MarengoInvokeResponse(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", frozen=True) data: tuple[MarengoEmbeddingItem, ...] = () @@ -53,14 +54,14 @@ class MarengoInvokeResponse(BaseModel): return tuple(item.embedding for item in self.embeddings if item.embedding is not None) -class MarengoBilledMultiInput(BaseModel): +class MarengoBilledMultiInput(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", frozen=True) inputText: str | None = None mediaSources: tuple[Mapping[str, object], ...] = () -class MarengoBilledRequest(BaseModel): +class MarengoBilledRequest(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", frozen=True) inputType: TWELVELABS_MARENGO_3_INPUT_TYPES | None = None diff --git a/litellm/llms/bedrock/files/transformation.py b/litellm/llms/bedrock/files/transformation.py index be6fbf6c53a..04969027638 100644 --- a/litellm/llms/bedrock/files/transformation.py +++ b/litellm/llms/bedrock/files/transformation.py @@ -16,7 +16,7 @@ from urllib.parse import quote, unquote, urlencode import httpx from httpx import Headers, Response from openai.types.file_deleted import FileDeleted -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field from typing_extensions import ReadOnly from litellm._logging import verbose_logger @@ -47,6 +47,7 @@ from litellm.llms.base_llm.files.transformation import ( BaseFilesConfig, LiteLLMLoggingObj, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.bedrock import AwsAuthParams, BedrockBatchRecordKind from litellm.types.llms.openai import ( AllMessageValues, @@ -75,7 +76,7 @@ LIST_FILES_PURPOSE_PARAM: Final = "_s3_list_files_purpose" LIST_FILES_LOCATION_PARAM: Final = "_s3_list_files_location" -class _S3DeleteContext(BaseModel): +class _S3DeleteContext(LiteLLMBaseModel): file_id: str = Field(min_length=1) @@ -154,7 +155,7 @@ class _S3RequestTarget: request_params: _BedrockS3RequestParams -class _TrustedS3ModelCredentials(BaseModel): +class _TrustedS3ModelCredentials(LiteLLMBaseModel): """The S3 buckets the server trusts file ids against, from the deployment snapshot.""" model_config = ConfigDict(extra="ignore") diff --git a/litellm/llms/bedrock/image_edit/handler.py b/litellm/llms/bedrock/image_edit/handler.py index be6489f20ae..58de67107f4 100644 --- a/litellm/llms/bedrock/image_edit/handler.py +++ b/litellm/llms/bedrock/image_edit/handler.py @@ -10,7 +10,6 @@ import json from typing import TYPE_CHECKING, Any, Final import httpx -from pydantic import BaseModel import litellm from litellm._logging import verbose_logger @@ -27,6 +26,7 @@ from litellm.llms.custom_httpx.http_handler import ( _get_httpx_client, get_async_httpx_client, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import ImageResponse from ..base_aws_llm import BaseAWSLLM, bedrock_bearer_token @@ -38,7 +38,7 @@ else: AWSPreparedRequest = Any -class BedrockImageEditPreparedRequest(BaseModel): +class BedrockImageEditPreparedRequest(LiteLLMBaseModel): """ Internal/Helper class for preparing the request for bedrock image edit """ diff --git a/litellm/llms/bedrock/image_generation/image_handler.py b/litellm/llms/bedrock/image_generation/image_handler.py index 87762b648e0..bdf9f596053 100644 --- a/litellm/llms/bedrock/image_generation/image_handler.py +++ b/litellm/llms/bedrock/image_generation/image_handler.py @@ -4,7 +4,6 @@ import json from typing import TYPE_CHECKING, Any, Final import httpx -from pydantic import BaseModel import litellm from litellm._logging import verbose_logger @@ -27,6 +26,7 @@ from litellm.llms.custom_httpx.http_handler import ( _get_httpx_client, get_async_httpx_client, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import ImageResponse from ..base_aws_llm import BaseAWSLLM, bedrock_bearer_token @@ -38,7 +38,7 @@ else: AWSPreparedRequest = Any -class BedrockImagePreparedRequest(BaseModel): +class BedrockImagePreparedRequest(LiteLLMBaseModel): """ Internal/Helper class for preparing the request for bedrock image generation """ diff --git a/litellm/llms/bedrock/realtime/transformation.py b/litellm/llms/bedrock/realtime/transformation.py index 6ecbddbc558..03228fc43ef 100644 --- a/litellm/llms/bedrock/realtime/transformation.py +++ b/litellm/llms/bedrock/realtime/transformation.py @@ -10,7 +10,6 @@ import uuid as uuid_lib from typing import Final, cast import httpx -from pydantic import BaseModel from litellm._logging import verbose_logger from litellm._uuid import uuid @@ -18,6 +17,7 @@ from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLogging from litellm.llms.base_llm.realtime.transformation import BaseRealtimeConfig from litellm.llms.bedrock.common_utils import BedrockError from litellm.llms.bedrock.realtime.trigger_audio import ready_trigger_pcm +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import ( OpenAIRealtimeContentPartDone, OpenAIRealtimeDoneEvent, @@ -45,25 +45,25 @@ from litellm.types.realtime import ( ) -class BedrockContentEnd(BaseModel): +class BedrockContentEnd(LiteLLMBaseModel): stopReason: str | None = None -class BedrockUsageTokenDetails(BaseModel): +class BedrockUsageTokenDetails(LiteLLMBaseModel): speechTokens: int = 0 textTokens: int = 0 -class BedrockUsageDetailsTotal(BaseModel): +class BedrockUsageDetailsTotal(LiteLLMBaseModel): input: BedrockUsageTokenDetails = BedrockUsageTokenDetails() output: BedrockUsageTokenDetails = BedrockUsageTokenDetails() -class BedrockUsageDetails(BaseModel): +class BedrockUsageDetails(LiteLLMBaseModel): total: BedrockUsageDetailsTotal = BedrockUsageDetailsTotal() -class BedrockUsageEvent(BaseModel): +class BedrockUsageEvent(LiteLLMBaseModel): totalInputTokens: int = 0 totalOutputTokens: int = 0 totalTokens: int = 0 diff --git a/litellm/llms/custom_httpx/aiohttp_transport.py b/litellm/llms/custom_httpx/aiohttp_transport.py index 73adf9c7455..b5e2f73c4cd 100644 --- a/litellm/llms/custom_httpx/aiohttp_transport.py +++ b/litellm/llms/custom_httpx/aiohttp_transport.py @@ -14,15 +14,16 @@ import aiohttp.client_exceptions import aiohttp.http_exceptions import httpx from aiohttp.client import ClientResponse, ClientSession -from pydantic import BaseModel, TypeAdapter +from pydantic import TypeAdapter from typing_extensions import ReadOnly, TypedDict import litellm from litellm._logging import verbose_logger from litellm.secret_managers.main import str_to_bool +from litellm.types.llms.base import LiteLLMBaseModel -class HttpxTimeoutExtension(BaseModel): +class HttpxTimeoutExtension(LiteLLMBaseModel): connect: float | None = None read: float | None = None write: float | None = None diff --git a/litellm/llms/edenai/chat/transformation.py b/litellm/llms/edenai/chat/transformation.py index 84866044103..ae5da5d1cfd 100644 --- a/litellm/llms/edenai/chat/transformation.py +++ b/litellm/llms/edenai/chat/transformation.py @@ -13,12 +13,13 @@ from types import MappingProxyType from typing import TYPE_CHECKING, Final import httpx -from pydantic import BaseModel, TypeAdapter +from pydantic import TypeAdapter import litellm from litellm.litellm_core_utils.core_helpers import set_response_cost_in_hidden_params from litellm.llms.base_llm.chat.transformation import BaseLLMException from litellm.llms.openai.chat.gpt_transformation import OpenAIChatCompletionStreamingHandler, OpenAIGPTConfig +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import AllMessageValues from litellm.types.utils import ModelResponse, ModelResponseStream, Usage @@ -31,11 +32,11 @@ if TYPE_CHECKING: _OPTIONAL_MAPPING: Final[TypeAdapter[Mapping[str, object] | None]] = TypeAdapter(Mapping[str, object] | None) -class _EdenAIModel(BaseModel): +class _EdenAIModel(LiteLLMBaseModel): id: str -class _EdenAIModelCatalog(BaseModel): +class _EdenAIModelCatalog(LiteLLMBaseModel): data: tuple[_EdenAIModel, ...] diff --git a/litellm/llms/edenai/common_utils.py b/litellm/llms/edenai/common_utils.py index ab7ee9b1c9d..3216f798fbe 100644 --- a/litellm/llms/edenai/common_utils.py +++ b/litellm/llms/edenai/common_utils.py @@ -7,12 +7,13 @@ from collections.abc import Container, Mapping from types import MappingProxyType from typing import Final -from pydantic import AliasChoices, BaseModel, Field, ValidationError +from pydantic import AliasChoices, Field, ValidationError import litellm from litellm.exceptions import AuthenticationError from litellm.llms.base_llm.chat.transformation import BaseLLMException from litellm.secret_managers.main import get_secret_str +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import LlmProviders EDENAI_API_BASE: Final = "https://api.edenai.run/v3" @@ -23,7 +24,7 @@ class EdenAIException(BaseLLMException): pass -class _EdenAIExtras(BaseModel): +class _EdenAIExtras(LiteLLMBaseModel): cost: float | None = Field(default=None, validation_alias=AliasChoices("cost", EDENAI_COST_HEADER)) diff --git a/litellm/llms/fal_ai/chat/transformation.py b/litellm/llms/fal_ai/chat/transformation.py index d107426d793..115b1f840de 100644 --- a/litellm/llms/fal_ai/chat/transformation.py +++ b/litellm/llms/fal_ai/chat/transformation.py @@ -10,11 +10,12 @@ from collections.abc import Mapping, Sequence from typing import TYPE_CHECKING, Final import httpx -from pydantic import BaseModel, ConfigDict, TypeAdapter +from pydantic import ConfigDict, TypeAdapter from litellm.litellm_core_utils.core_helpers import map_finish_reason from litellm.llms.base_llm.chat.transformation import BaseConfig, BaseLLMException from litellm.secret_managers.main import get_secret_str +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import AllMessageValues from litellm.types.utils import Message, ModelResponse, Usage @@ -30,14 +31,14 @@ REASONING_DISABLED_EFFORTS: Final[frozenset[str]] = frozenset(("none", "minimal" REASONING_ENABLED_EFFORTS: Final[frozenset[str]] = frozenset(("low", "medium", "high")) -class _FalUsage(BaseModel): +class _FalUsage(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") input_tokens: int output_tokens: int -class _FalChatResponse(BaseModel): +class _FalChatResponse(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") output: str diff --git a/litellm/llms/fireworks_ai/rerank/transformation.py b/litellm/llms/fireworks_ai/rerank/transformation.py index 3d9d813c6e9..4eff64e351f 100644 --- a/litellm/llms/fireworks_ai/rerank/transformation.py +++ b/litellm/llms/fireworks_ai/rerank/transformation.py @@ -8,12 +8,13 @@ from collections.abc import Iterable, Mapping, Sequence from typing import Final import httpx -from pydantic import BaseModel, ConfigDict, TypeAdapter +from pydantic import ConfigDict, TypeAdapter from litellm._uuid import uuid from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj from litellm.llms.base_llm.rerank.transformation import BaseRerankConfig from litellm.llms.fireworks_ai.common_utils import FireworksAIMixin +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.rerank import ( RerankBilledUnits, RerankResponse, @@ -24,7 +25,7 @@ from litellm.types.rerank import ( ) -class _FireworksAIUsageFields(BaseModel): +class _FireworksAIUsageFields(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", frozen=True) total_tokens: int | None = 0 @@ -32,7 +33,7 @@ class _FireworksAIUsageFields(BaseModel): completion_tokens: int | None = 0 -class _FireworksAIResultFields(BaseModel): +class _FireworksAIResultFields(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", frozen=True, hide_input_in_errors=True) index: int | float | str diff --git a/litellm/llms/groq/chat/transformation.py b/litellm/llms/groq/chat/transformation.py index f60947714a5..cb3f1ac2d0c 100644 --- a/litellm/llms/groq/chat/transformation.py +++ b/litellm/llms/groq/chat/transformation.py @@ -16,6 +16,7 @@ from litellm.llms.openai.chat.gpt_transformation import ( ) from litellm.llms.openai.common_utils import OpenAIError from litellm.secret_managers.main import get_secret_str +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import ( AllMessageValues, ChatCompletionAssistantMessage, @@ -32,7 +33,7 @@ if TYPE_CHECKING: GROQ_COMPOUND_MODELS: Final = frozenset({"compound", "compound-mini"}) -class GroqExecutedToolIdentity(BaseModel): +class GroqExecutedToolIdentity(LiteLLMBaseModel): name: str | None = None type: str | None = None diff --git a/litellm/llms/laya/common_utils.py b/litellm/llms/laya/common_utils.py index 3e423a9e742..ff6343b06db 100644 --- a/litellm/llms/laya/common_utils.py +++ b/litellm/llms/laya/common_utils.py @@ -1,10 +1,12 @@ from collections.abc import Mapping from typing import Final -from pydantic import BaseModel, TypeAdapter, ValidationError +from pydantic import TypeAdapter, ValidationError + +from litellm.types.llms.base import LiteLLMBaseModel -class _LayaRouting(BaseModel): +class _LayaRouting(LiteLLMBaseModel): model: str | None = None diff --git a/litellm/llms/litellm_proxy/skills/skill_search.py b/litellm/llms/litellm_proxy/skills/skill_search.py index f975c6c4cab..adfd45b7d11 100644 --- a/litellm/llms/litellm_proxy/skills/skill_search.py +++ b/litellm/llms/litellm_proxy/skills/skill_search.py @@ -6,7 +6,7 @@ from collections.abc import Sequence from dataclasses import dataclass from typing import TYPE_CHECKING, Final, TypeAlias -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict from litellm.llms.litellm_proxy.skills.constants import MAX_SKILLS_PER_SEARCH from litellm.llms.litellm_proxy.skills.handler import LiteLLMSkillsHandler @@ -16,6 +16,7 @@ from litellm.proxy.common_utils.semantic_text_index import ( SemanticTextIndex, router_embedder, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import LlmProviders if TYPE_CHECKING: @@ -63,7 +64,7 @@ SkillSearchOutcome: TypeAlias = SkillSearchHits | SkillSearchNotConfigured | Ski HostedSkillSearchOutcome: TypeAlias = SkillSearchOutcome | SkillSearchUnsupportedProvider -class SkillSearchResult(BaseModel): +class SkillSearchResult(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) skill_id: str diff --git a/litellm/llms/mistral/batches/transformation.py b/litellm/llms/mistral/batches/transformation.py index 3496feed585..86de2836048 100644 --- a/litellm/llms/mistral/batches/transformation.py +++ b/litellm/llms/mistral/batches/transformation.py @@ -15,12 +15,13 @@ import httpx from openai.types.batch import BatchRequestCounts from openai.types.batch import Errors as BatchErrors from openai.types.batch_error import BatchError -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict from typing_extensions import NotRequired, ReadOnly, TypedDict from litellm.litellm_core_utils.url_utils import encode_url_path_segment from litellm.llms.base_llm.batches.transformation import BaseBatchesConfig from litellm.llms.base_llm.chat.transformation import BaseLLMException +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import AllMessageValues, CreateBatchRequest from litellm.types.utils import LiteLLMBatch, LlmProviders @@ -64,14 +65,14 @@ class MistralPresignedRequest(TypedDict): headers: ReadOnly[Mapping[str, str]] -class MistralBatchError(BaseModel): +class MistralBatchError(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") message: str count: int = 1 -class MistralBatchJob(BaseModel): +class MistralBatchJob(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") id: str diff --git a/litellm/llms/mistral/files/transformation.py b/litellm/llms/mistral/files/transformation.py index c1e3f50c379..86bce763917 100644 --- a/litellm/llms/mistral/files/transformation.py +++ b/litellm/llms/mistral/files/transformation.py @@ -14,13 +14,14 @@ from typing import Final, Literal, TypeAlias import httpx from openai.types.file_deleted import FileDeleted -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict from typing_extensions import ReadOnly, TypedDict from litellm.litellm_core_utils.prompt_templates.common_utils import extract_file_data from litellm.litellm_core_utils.url_utils import encode_url_path_segment from litellm.llms.base_llm.chat.transformation import BaseLLMException from litellm.llms.base_llm.files.transformation import BaseFilesConfig, LiteLLMLoggingObj +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import ( CreateFileRequest, FileContentRequest, @@ -54,7 +55,7 @@ class MistralMultipartUpload(TypedDict): purpose: ReadOnly[tuple[None, MistralFilePurpose]] -class MistralFile(BaseModel): +class MistralFile(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") id: str @@ -65,13 +66,13 @@ class MistralFile(BaseModel): expires_at: int | None = None -class MistralFileList(BaseModel): +class MistralFileList(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") data: tuple[MistralFile, ...] = () -class MistralFileDeleted(BaseModel): +class MistralFileDeleted(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") id: str diff --git a/litellm/llms/mongodb/vector_stores/transformation.py b/litellm/llms/mongodb/vector_stores/transformation.py index c6d3a2db3b4..0d931ee78cb 100644 --- a/litellm/llms/mongodb/vector_stores/transformation.py +++ b/litellm/llms/mongodb/vector_stores/transformation.py @@ -6,7 +6,7 @@ from typing import TYPE_CHECKING, Final, Literal, NoReturn from urllib.parse import quote, urlsplit import httpx -from pydantic import BaseModel, ConfigDict, TypeAdapter, ValidationError +from pydantic import ConfigDict, TypeAdapter, ValidationError from litellm.exceptions import AuthenticationError, BadRequestError, ServiceUnavailableError, Timeout from litellm.llms.base_llm.chat.transformation import BaseLLMException @@ -16,6 +16,7 @@ from litellm.llms.base_llm.vector_store.transformation import ( VectorStoreEmbeddingExecutor, ) from litellm.secret_managers.main import get_secret_str +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.router import GenericLiteLLMParams from litellm.types.utils import EmbeddingResponse from litellm.types.vector_stores import ( @@ -49,13 +50,13 @@ def config_error(message: str) -> BadRequestError: return BadRequestError(message=message, model=None, llm_provider="mongodb") -class _Content(BaseModel): +class _Content(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, strict=True) type: Literal["text"] text: str -class _Result(BaseModel): +class _Result(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, strict=True, allow_inf_nan=False) score: float | None content: Sequence[_Content] @@ -63,14 +64,14 @@ class _Result(BaseModel): filename: str | None -class _SearchResponse(BaseModel): +class _SearchResponse(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, strict=True) object: Literal["vector_store.search_results.page"] search_query: str data: Sequence[_Result] -class _MongoDBSearchParams(BaseModel): +class _MongoDBSearchParams(LiteLLMBaseModel): """Typed view over the vector store's litellm_params; unrelated keys are ignored.""" model_config = ConfigDict(frozen=True, extra="ignore") diff --git a/litellm/llms/nimble/search/transformation.py b/litellm/llms/nimble/search/transformation.py index f40ca60fb6c..30cfc38eb87 100644 --- a/litellm/llms/nimble/search/transformation.py +++ b/litellm/llms/nimble/search/transformation.py @@ -11,7 +11,7 @@ from types import MappingProxyType from typing import TYPE_CHECKING, Final import httpx -from pydantic import BaseModel, ConfigDict, TypeAdapter, ValidationError +from pydantic import ConfigDict, TypeAdapter, ValidationError from litellm.llms.base_llm.chat.transformation import BaseLLMException from litellm.llms.base_llm.search.transformation import ( @@ -20,6 +20,7 @@ from litellm.llms.base_llm.search.transformation import ( SearchResult, ) from litellm.secret_managers.main import get_secret_str +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj @@ -27,7 +28,7 @@ if TYPE_CHECKING: _NIMBLE_DOCS_URL: Final = "https://docs.nimbleway.com/api-reference/search/search" -class _NimbleResult(BaseModel): +class _NimbleResult(LiteLLMBaseModel): """One entry of Nimble's `results` array. Every field is optional so a single degraded result degrades to empty strings instead of failing the whole call.""" @@ -41,7 +42,7 @@ class _NimbleResult(BaseModel): additional_data: object = None -class _NimbleSearchResponse(BaseModel): +class _NimbleSearchResponse(LiteLLMBaseModel): """Nimble's /v2/search response envelope.""" model_config = ConfigDict(extra="ignore", frozen=True) @@ -51,7 +52,7 @@ class _NimbleSearchResponse(BaseModel): results: tuple[_NimbleResult, ...] -class _AdditionalData(BaseModel): +class _AdditionalData(LiteLLMBaseModel): """The slice of a result's free-form `additional_data` that maps onto SearchResult.""" model_config = ConfigDict(extra="ignore", frozen=True) @@ -59,7 +60,7 @@ class _AdditionalData(BaseModel): publish_date: str | None = None -class _ErrorEnvelope(BaseModel): +class _ErrorEnvelope(LiteLLMBaseModel): """Nimble reports errors as either `{"detail": ...}` (validation) or `{"success": "false", "task_id": ..., "message": ...}` (collection).""" diff --git a/litellm/llms/oci/common_utils.py b/litellm/llms/oci/common_utils.py index 679a9c21e43..fe8d0e1c1e7 100644 --- a/litellm/llms/oci/common_utils.py +++ b/litellm/llms/oci/common_utils.py @@ -13,10 +13,11 @@ from typing import Final, Protocol, runtime_checkable from urllib.parse import urlparse import httpx -from pydantic import BaseModel, ConfigDict, Field, JsonValue, TypeAdapter, ValidationError, field_validator +from pydantic import ConfigDict, Field, JsonValue, TypeAdapter, ValidationError, field_validator from litellm._logging import verbose_logger from litellm.llms.base_llm.chat.transformation import BaseLLMException +from litellm.types.llms.base import LiteLLMBaseModel try: from cryptography.hazmat.primitives import hashes, serialization @@ -214,7 +215,7 @@ _OCI_REALM_DOMAINS: Final = MappingProxyType( ) -class OCIRegionMetadata(BaseModel): +class OCIRegionMetadata(LiteLLMBaseModel): """One entry of the OCI SDK's region metadata schema, as found in ``~/.oci/regions-config.json`` (a JSON array) or ``OCI_REGION_METADATA`` (one object). Values are lowercased before validation, as the SDK does.""" diff --git a/litellm/llms/ollama/completion/transformation.py b/litellm/llms/ollama/completion/transformation.py index b1f69220de7..9687378e5c3 100644 --- a/litellm/llms/ollama/completion/transformation.py +++ b/litellm/llms/ollama/completion/transformation.py @@ -4,7 +4,7 @@ from collections.abc import AsyncIterator, Iterator from typing import TYPE_CHECKING, Any, Final from httpx._models import Headers, Response -from pydantic import BaseModel, ConfigDict, ValidationError +from pydantic import ConfigDict, ValidationError import litellm from litellm._logging import verbose_proxy_logger @@ -23,6 +23,7 @@ from litellm.litellm_core_utils.prompt_templates.image_handling import ( ) from litellm.llms.base_llm.base_model_iterator import BaseModelResponseIterator from litellm.llms.base_llm.chat.transformation import BaseConfig, BaseLLMException +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import AllMessageValues, ChatCompletionUsageBlock from litellm.types.utils import ( Delta, @@ -44,7 +45,7 @@ else: LiteLLMLoggingObj = Any -class _OllamaGenerateReasoning(BaseModel): +class _OllamaGenerateReasoning(LiteLLMBaseModel): """The two `/api/generate` fields a reply's reasoning can arrive in.""" model_config = ConfigDict(extra="ignore") diff --git a/litellm/llms/openai/organization_costs.py b/litellm/llms/openai/organization_costs.py index 8e7f02cca96..4f1d4798e99 100644 --- a/litellm/llms/openai/organization_costs.py +++ b/litellm/llms/openai/organization_costs.py @@ -8,7 +8,7 @@ from types import MappingProxyType from typing import Final, Literal, TypeAlias import httpx -from pydantic import BaseModel, ConfigDict, ValidationError +from pydantic import ConfigDict, ValidationError from litellm.constants import ( OPENAI_ORGANIZATION_COSTS_PAGE_LIMIT, @@ -16,6 +16,7 @@ from litellm.constants import ( PROVIDER_BILLING_TIMEOUT_SECONDS, ) from litellm.llms.custom_httpx.http_handler import get_async_httpx_client +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.custom_http import httpxSpecialProvider OPENAI_ADMIN_KEY_ENV_VAR: Final = "OPENAI_ADMIN_KEY" @@ -31,27 +32,27 @@ class OpenAICostsRequestFailed: detail: str -class _OpenAICostAmount(BaseModel): +class _OpenAICostAmount(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") value: float currency: Literal["usd"] -class _OpenAICostResult(BaseModel): +class _OpenAICostResult(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") amount: _OpenAICostAmount -class _OpenAICostBucket(BaseModel): +class _OpenAICostBucket(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") start_time: int results: tuple[_OpenAICostResult, ...] = () -class _OpenAICostsPage(BaseModel): +class _OpenAICostsPage(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") data: tuple[_OpenAICostBucket, ...] diff --git a/litellm/llms/openai/responses/guardrail_translation/handler.py b/litellm/llms/openai/responses/guardrail_translation/handler.py index ad68924ce20..a267b66bb22 100644 --- a/litellm/llms/openai/responses/guardrail_translation/handler.py +++ b/litellm/llms/openai/responses/guardrail_translation/handler.py @@ -66,6 +66,7 @@ from litellm.llms.openai.responses.guardrail_translation.tool_merge import merge from litellm.responses.litellm_completion_transformation.transformation import ( LiteLLMCompletionResponsesConfig, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import ( AllMessageValues, BaseLiteLLMOpenAIResponseObject, @@ -110,14 +111,14 @@ class _ToolCallShape(NamedTuple): arguments: str -class _ToolCallFunctionFields(BaseModel): +class _ToolCallFunctionFields(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) name: str | None = None arguments: str = "" -class _ToolCallFields(BaseModel): +class _ToolCallFields(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) function: _ToolCallFunctionFields diff --git a/litellm/llms/openai/responses/transformation.py b/litellm/llms/openai/responses/transformation.py index 1452ecebca9..e4928868699 100644 --- a/litellm/llms/openai/responses/transformation.py +++ b/litellm/llms/openai/responses/transformation.py @@ -26,6 +26,7 @@ from litellm.llms.openai.chat.gpt_5_transformation import is_gpt_reasoning_serie from litellm.responses.litellm_completion_transformation.custom_tools import TOOL_CALL_ITEM_ID_PREFIX_BY_TYPE from litellm.responses.litellm_completion_transformation.reasoning_items import is_litellm_minted_reasoning_item from litellm.secret_managers.main import get_secret_str +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import * from litellm.types.responses.main import * from litellm.types.router import GenericLiteLLMParams @@ -51,7 +52,7 @@ _PROVIDERS_VALIDATING_TOOL_CALL_ITEM_IDS: Final = frozenset({LlmProviders.AZURE, _PROVIDERS_REPLAYING_ONLY_THEIR_OWN_REASONING: Final = _PROVIDERS_VALIDATING_TOOL_CALL_ITEM_IDS -class _ReasoningSupportEntry(BaseModel): +class _ReasoningSupportEntry(LiteLLMBaseModel): litellm_provider: str | None = None supports_reasoning: bool | None = None diff --git a/litellm/llms/openai_like/model_info.py b/litellm/llms/openai_like/model_info.py index 101be58d197..24135287ae9 100644 --- a/litellm/llms/openai_like/model_info.py +++ b/litellm/llms/openai_like/model_info.py @@ -5,11 +5,12 @@ from types import MappingProxyType from typing import Annotated, Final, TypeAlias import httpx -from pydantic import BaseModel, BeforeValidator, ConfigDict +from pydantic import BeforeValidator, ConfigDict from litellm._logging import verbose_logger from litellm.caching.in_memory_cache import InMemoryCache from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler +from litellm.types.llms.base import LiteLLMBaseModel from litellm.utils import _add_path_to_api_base # pyright: ignore[reportPrivateUsage] # shared provider URL helper MODEL_INFO_REFRESH_SECONDS: Final = 300 @@ -25,7 +26,7 @@ def _positive_limit(value: object) -> int | None: _TokenLimit: TypeAlias = Annotated[int | None, BeforeValidator(_positive_limit)] -class _ModelCard(BaseModel): +class _ModelCard(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) id: str @@ -51,7 +52,7 @@ class _ModelCard(BaseModel): ) -class _ModelList(BaseModel): +class _ModelList(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) data: tuple[_ModelCard, ...] = () diff --git a/litellm/llms/parallel_ai/search/transformation.py b/litellm/llms/parallel_ai/search/transformation.py index d91e532a2cf..c627cb001dc 100644 --- a/litellm/llms/parallel_ai/search/transformation.py +++ b/litellm/llms/parallel_ai/search/transformation.py @@ -9,7 +9,7 @@ from types import MappingProxyType from typing import Final, TypedDict import httpx -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict from typing_extensions import ReadOnly from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj @@ -20,9 +20,10 @@ from litellm.llms.base_llm.search.transformation import ( ) from litellm.llms.parallel_ai.search.cost_calculator import PARALLEL_AI_USAGE_PARAM from litellm.secret_managers.main import get_secret_str +from litellm.types.llms.base import LiteLLMBaseModel -class _ParallelAIV1SearchResult(BaseModel): +class _ParallelAIV1SearchResult(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") url: str | None = None @@ -31,7 +32,7 @@ class _ParallelAIV1SearchResult(BaseModel): excerpts: Sequence[str] | None = None -class _ParallelAIV1SearchResponse(BaseModel): +class _ParallelAIV1SearchResponse(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") search_id: str | None = None diff --git a/litellm/llms/sap/chat/models.py b/litellm/llms/sap/chat/models.py index 5f65c7f715d..afdd7a2f356 100644 --- a/litellm/llms/sap/chat/models.py +++ b/litellm/llms/sap/chat/models.py @@ -2,7 +2,9 @@ import warnings from enum import Enum from typing import Final, Literal -from pydantic import BaseModel, Field, field_validator, model_validator +from pydantic import Field, field_validator, model_validator + +from litellm.types.llms.base import LiteLLMBaseModel def validate_different_content(v: str | dict | list) -> str: @@ -24,30 +26,30 @@ def validate_different_content(v: str | dict | list) -> str: raise ValueError("Content must be a string") -class TextContent(BaseModel): +class TextContent(LiteLLMBaseModel): type_: Literal["text"] = Field(default="text", alias="type") text: str -class ImageURLContent(BaseModel): +class ImageURLContent(LiteLLMBaseModel): url: str detail: str = "auto" -class ImageContent(BaseModel): +class ImageContent(LiteLLMBaseModel): type_: Literal["image_url"] = Field(default="image_url", alias="type") image_url: ImageURLContent -class FunctionObj(BaseModel): +class FunctionObj(LiteLLMBaseModel): name: str arguments: str -class FunctionTool(BaseModel): +class FunctionTool(LiteLLMBaseModel): description: str = "" name: str - parameters: dict = {"type": "object", "properties": {}} + parameters: dict = Field(default={"type": "object", "properties": {}}) strict: bool = False def model_dump(self, **kwargs) -> dict: @@ -67,7 +69,7 @@ class FunctionTool(BaseModel): return v -class ChatCompletionTool(BaseModel): +class ChatCompletionTool(LiteLLMBaseModel): type_: Literal["function"] = Field(default="function", alias="type") function: FunctionTool @@ -76,13 +78,13 @@ class ChatCompletionTool(BaseModel): return super().model_dump(**kwargs) -class MessageToolCall(BaseModel): +class MessageToolCall(LiteLLMBaseModel): id: str type_: Literal["function"] = Field(default="function", alias="type") function: FunctionObj -class SAPMessage(BaseModel): +class SAPMessage(LiteLLMBaseModel): """ Model for SystemChatMessage and DeveloperChatMessage """ @@ -93,21 +95,21 @@ class SAPMessage(BaseModel): _content_validator = field_validator("content", mode="before")(validate_different_content) -class SAPUserMessage(BaseModel): +class SAPUserMessage(LiteLLMBaseModel): role: Literal["user"] = "user" content: str | TextContent | ImageContent | list[TextContent | ImageContent] -class SAPAssistantMessage(BaseModel): +class SAPAssistantMessage(LiteLLMBaseModel): role: Literal["assistant"] = "assistant" content: str = "" refusal: str = "" - tool_calls: list[MessageToolCall] = [] + tool_calls: list[MessageToolCall] = Field(default=[]) _content_validator = field_validator("content", mode="before")(validate_different_content) -class SAPToolChatMessage(BaseModel): +class SAPToolChatMessage(LiteLLMBaseModel): role: Literal["tool"] = "tool" tool_call_id: str content: str @@ -118,23 +120,23 @@ class SAPToolChatMessage(BaseModel): ChatMessage = SAPMessage | SAPUserMessage | SAPAssistantMessage | SAPToolChatMessage -class ResponseFormat(BaseModel): +class ResponseFormat(LiteLLMBaseModel): type_: Literal["text", "json_object"] = Field(default="text", alias="type") -class JSONResponseSchema(BaseModel): +class JSONResponseSchema(LiteLLMBaseModel): description: str = "" name: str schema_: dict = Field(default_factory=dict, alias="schema") strict: bool = False -class ResponseFormatJSONSchema(BaseModel): +class ResponseFormatJSONSchema(LiteLLMBaseModel): type_: Literal["json_schema"] = Field(default="json_schema", alias="type") json_schema: JSONResponseSchema -class KeyValueListPair(BaseModel): +class KeyValueListPair(LiteLLMBaseModel): key: str value: list[str] @@ -143,7 +145,7 @@ class DocumentMetadataKeyValueListPairs(KeyValueListPair): select_mode: list[Literal["ignoreIfKeyAbsent"]] | None = None -class GroundingSearchConfig(BaseModel): +class GroundingSearchConfig(LiteLLMBaseModel): max_chunk_count: int | None = Field(default=None, ge=0) max_document_count: int | None = Field(default=None, ge=0) @@ -154,7 +156,7 @@ class GroundingSearchConfig(BaseModel): return self -class DocumentGroundingFilter(BaseModel): +class DocumentGroundingFilter(LiteLLMBaseModel): id_: str | None = Field(default=None, alias="id") data_repository_type: Literal["vector", "help.sap.com"] search_config: GroundingSearchConfig | None = None @@ -164,36 +166,36 @@ class DocumentGroundingFilter(BaseModel): chunk_metadata: list[KeyValueListPair] | None = None -class DocumentGroundingPlaceholders(BaseModel): +class DocumentGroundingPlaceholders(LiteLLMBaseModel): input: list[str] = Field(min_length=1) output: str -class DocumentGroundingConfig(BaseModel): +class DocumentGroundingConfig(LiteLLMBaseModel): filters: list[DocumentGroundingFilter] | None = None placeholders: DocumentGroundingPlaceholders metadata_params: list[str] | None = None -class GroundingModuleConfig(BaseModel): +class GroundingModuleConfig(LiteLLMBaseModel): type_: Literal["document_grounding_service"] = Field(default="document_grounding_service", alias="type") config: DocumentGroundingConfig -class Template(BaseModel): +class Template(LiteLLMBaseModel): template: list[ChatMessage] defaults: dict[str, str] | None = None response_format: ResponseFormat | ResponseFormatJSONSchema | None = None tools: list[ChatCompletionTool] | None = None -class LLMModelDetails(BaseModel): +class LLMModelDetails(LiteLLMBaseModel): name: str version: str = "latest" params: dict | None = None -class PromptTemplatingModuleConfig(BaseModel): +class PromptTemplatingModuleConfig(LiteLLMBaseModel): prompt: Template model: LLMModelDetails @@ -285,7 +287,7 @@ class SAPMaskingProfileEntity(str, Enum): ETHNICITY = "profile-ethnicity" -class DPIMethodConstant(BaseModel): +class DPIMethodConstant(LiteLLMBaseModel): """ Replaces the entity with the specified value followed by an incrementing number """ @@ -294,7 +296,7 @@ class DPIMethodConstant(BaseModel): value: str -class DPIMethodFabricatedData(BaseModel): +class DPIMethodFabricatedData(LiteLLMBaseModel): """ Replaces the entity with a randomly generated value appropriate to its type. """ @@ -302,7 +304,7 @@ class DPIMethodFabricatedData(BaseModel): method: Literal["fabricated_data"] = "fabricated_data" -class DPICustomEntity(BaseModel): +class DPICustomEntity(LiteLLMBaseModel): """ regex: Regular expression to match the entity replacement_strategy: Replacement strategy to be used for the entity @@ -312,7 +314,7 @@ class DPICustomEntity(BaseModel): replacement_strategy: DPIMethodConstant -class DPIStandardEntity(BaseModel): +class DPIStandardEntity(LiteLLMBaseModel): """ type: Standard entity type to be masked replacement_strategy: Replacement strategy to be used for the entity @@ -322,7 +324,7 @@ class DPIStandardEntity(BaseModel): replacement_strategy: DPIMethodConstant | DPIMethodFabricatedData | None = None -class MaskGroundingInput(BaseModel): +class MaskGroundingInput(LiteLLMBaseModel): """ Controls whether the input to the grounding module will be masked with the configuration supplied in the masking module @@ -331,7 +333,7 @@ class MaskGroundingInput(BaseModel): enabled: bool = False -class MaskingProviderConfig(BaseModel): +class MaskingProviderConfig(LiteLLMBaseModel): """ SAP Data Privacy Integration provider for data masking. @@ -356,7 +358,7 @@ class MaskingProviderConfig(BaseModel): mask_grounding_input: MaskGroundingInput | None = None -class MaskingModuleConfig(BaseModel): +class MaskingModuleConfig(LiteLLMBaseModel): """ Configuration for the data masking module. @@ -417,7 +419,7 @@ class AzureThreshold(int, Enum): ALLOW_ALL = 6 -class AzureContentFilter(BaseModel): +class AzureContentFilter(LiteLLMBaseModel): """ Specific filter configuration for Azure Content Safety. @@ -481,7 +483,7 @@ class AzureContentSafetyOutput(AzureContentFilter): protected_material_code: bool | None = False -class LlamaGuard38bFilter(BaseModel): +class LlamaGuard38bFilter(LiteLLMBaseModel): """ Specific implementation of ContentFilter for Llama Guard 3. Llama Guard 3 is a Llama-3.1-8B pretrained model, fine-tuned for content safety classification. @@ -532,22 +534,22 @@ class LlamaGuard38bFilter(BaseModel): code_interpreter_abuse: bool = Field(default=False) -class LlamaGuard38bFilterConfig(BaseModel): +class LlamaGuard38bFilterConfig(LiteLLMBaseModel): type_: Literal["llama_guard_3_8b"] = Field(default="llama_guard_3_8b", alias="type") config: LlamaGuard38bFilter -class AzureContentSafetyInputFilterConfig(BaseModel): +class AzureContentSafetyInputFilterConfig(LiteLLMBaseModel): type_: Literal["azure_content_safety"] = Field(default="azure_content_safety", alias="type") config: AzureContentSafetyInput | None = None -class AzureContentSafetyOutputFilterConfig(BaseModel): +class AzureContentSafetyOutputFilterConfig(LiteLLMBaseModel): type_: Literal["azure_content_safety"] = Field(default="azure_content_safety", alias="type") config: AzureContentSafetyOutput | None = None -class FilteringStreamOptions(BaseModel): +class FilteringStreamOptions(LiteLLMBaseModel): """ overlap: Number of characters that should be additionally sent to content filtering services from previous chunks as additional context. @@ -556,7 +558,7 @@ class FilteringStreamOptions(BaseModel): overlap: int | None = Field(default=0, ge=0, le=10000) -class InputFiltering(BaseModel): +class InputFiltering(LiteLLMBaseModel): """Module for managing and applying input content filters. Args: @@ -566,7 +568,7 @@ class InputFiltering(BaseModel): filters: list[AzureContentSafetyInputFilterConfig | LlamaGuard38bFilterConfig] = Field(min_length=1) -class OutputFiltering(BaseModel): +class OutputFiltering(LiteLLMBaseModel): """Module for managing and applying output content filters. Args: @@ -579,7 +581,7 @@ class OutputFiltering(BaseModel): stream_options: FilteringStreamOptions | None = None -class FilteringModuleConfig(BaseModel): +class FilteringModuleConfig(LiteLLMBaseModel): """Module for managing and applying content filters. Args: @@ -603,7 +605,7 @@ class FilteringModuleConfig(BaseModel): return self -class SAPDocumentTranslationApplyToSelector(BaseModel): +class SAPDocumentTranslationApplyToSelector(LiteLLMBaseModel): """ This selector allows you to define the scope of translation, such as specific placeholders or messages with specific roles. @@ -619,7 +621,7 @@ class SAPDocumentTranslationApplyToSelector(BaseModel): source_language: str -class InputTranslationConfig(BaseModel): +class InputTranslationConfig(LiteLLMBaseModel): """ Configuration for input translation. @@ -634,12 +636,12 @@ class InputTranslationConfig(BaseModel): apply_to: list[SAPDocumentTranslationApplyToSelector] | None = None -class OutputTranslationConfig(BaseModel): +class OutputTranslationConfig(LiteLLMBaseModel): source_language: str | None = None target_language: str | SAPDocumentTranslationApplyToSelector -class SAPDocumentTranslationInput(BaseModel): +class SAPDocumentTranslationInput(LiteLLMBaseModel): """ Configuration for input translation @@ -656,7 +658,7 @@ class SAPDocumentTranslationInput(BaseModel): config: InputTranslationConfig -class SAPDocumentTranslationOutput(BaseModel): +class SAPDocumentTranslationOutput(LiteLLMBaseModel): """ Configuration for output translation @@ -670,7 +672,7 @@ class SAPDocumentTranslationOutput(BaseModel): config: OutputTranslationConfig -class TranslationModuleConfig(BaseModel): +class TranslationModuleConfig(LiteLLMBaseModel): """ Configuration for translation module @@ -690,7 +692,7 @@ class TranslationModuleConfig(BaseModel): return self -class ModuleConfig(BaseModel): +class ModuleConfig(LiteLLMBaseModel): prompt_templating: PromptTemplatingModuleConfig filtering: FilteringModuleConfig | None = None masking: MaskingModuleConfig | None = None @@ -698,17 +700,17 @@ class ModuleConfig(BaseModel): translation: TranslationModuleConfig | None = None -class GlobalStreamOptions(BaseModel): +class GlobalStreamOptions(LiteLLMBaseModel): enabled: bool = False chunk_size: int | None = Field(default=None, ge=1) delimiters: list[str] | None = None -class OrchestrationConfig(BaseModel): +class OrchestrationConfig(LiteLLMBaseModel): modules: ModuleConfig | list[ModuleConfig] stream: GlobalStreamOptions | None = None -class OrchestrationRequest(BaseModel): +class OrchestrationRequest(LiteLLMBaseModel): config: OrchestrationConfig placeholder_values: dict[str, str] | None = None diff --git a/litellm/llms/sap/embed/transformation.py b/litellm/llms/sap/embed/transformation.py index 4a3062c8cbc..e91dfb91081 100644 --- a/litellm/llms/sap/embed/transformation.py +++ b/litellm/llms/sap/embed/transformation.py @@ -6,13 +6,14 @@ from functools import cached_property from typing import Final, Literal import httpx -from pydantic import BaseModel, Field +from pydantic import Field from litellm.llms.base_llm.embedding.transformation import ( BaseEmbeddingConfig, LiteLLMLoggingObj, ) from litellm.llms.sap.chat.models import MaskingModuleConfig +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import AllEmbeddingInputValues from litellm.types.utils import EmbeddingResponse @@ -20,30 +21,30 @@ from ..chat.handler import GenAIHubOrchestrationError from ..credentials import get_token_creator -class Usage(BaseModel): +class Usage(LiteLLMBaseModel): prompt_tokens: int total_tokens: int -class EmbeddingItem(BaseModel): +class EmbeddingItem(LiteLLMBaseModel): object: Literal["embedding"] embedding: list[float] = Field(..., description="Vector of floats (length varies by model).") index: int -class FinalResult(BaseModel): +class FinalResult(LiteLLMBaseModel): object: Literal["list"] data: list[EmbeddingItem] model: str usage: Usage -class EmbeddingsResponse(BaseModel): +class EmbeddingsResponse(LiteLLMBaseModel): request_id: str final_result: FinalResult -class EmbeddingModel(BaseModel): +class EmbeddingModel(LiteLLMBaseModel): name: str version: str = "latest" params: dict = Field(default_factory=dict) @@ -51,25 +52,25 @@ class EmbeddingModel(BaseModel): max_retries: int | None = Field(default=None, ge=0, le=5) -class EmbeddingsModelConfig(BaseModel): +class EmbeddingsModelConfig(LiteLLMBaseModel): model: EmbeddingModel -class EmbeddingsModules(BaseModel): +class EmbeddingsModules(LiteLLMBaseModel): embeddings: EmbeddingsModelConfig masking: MaskingModuleConfig | None = None -class EmbeddingInput(BaseModel): +class EmbeddingInput(LiteLLMBaseModel): text: str | list[str] type: Literal["text", "document", "query"] | None = None -class EmbeddingConfig(BaseModel): +class EmbeddingConfig(LiteLLMBaseModel): modules: EmbeddingsModules -class EmbeddingRequest(BaseModel): +class EmbeddingRequest(LiteLLMBaseModel): config: EmbeddingConfig input: EmbeddingInput diff --git a/litellm/llms/valkey/vector_stores/transformation.py b/litellm/llms/valkey/vector_stores/transformation.py index 50485899818..cd95d9c95b7 100644 --- a/litellm/llms/valkey/vector_stores/transformation.py +++ b/litellm/llms/valkey/vector_stores/transformation.py @@ -12,7 +12,7 @@ from types import MappingProxyType from typing import TYPE_CHECKING, Final, NoReturn import httpx -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict import litellm from litellm.llms.base_llm.vector_store.transformation import ( @@ -20,6 +20,7 @@ from litellm.llms.base_llm.vector_store.transformation import ( VectorStoreEmbeddingExecutor, ) from litellm.llms.valkey.common_utils import build_valkey_url, pack_vector +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import EmbeddingResponse from litellm.types.vector_stores import ( VectorStoreCreateOptionalRequestParams, @@ -79,7 +80,7 @@ def _import_query() -> "type[Query]": return RedisQuery -class _ValkeySearchParams(BaseModel): +class _ValkeySearchParams(LiteLLMBaseModel): """Typed view over the vector store's litellm_params; unrelated keys are ignored.""" model_config = ConfigDict(frozen=True, extra="ignore") diff --git a/litellm/llms/vertex_ai/vertex_embeddings/transformation.py b/litellm/llms/vertex_ai/vertex_embeddings/transformation.py index e4bbdd1bd0d..cab2bed8a60 100644 --- a/litellm/llms/vertex_ai/vertex_embeddings/transformation.py +++ b/litellm/llms/vertex_ai/vertex_embeddings/transformation.py @@ -1,15 +1,14 @@ import types from typing import Final, Literal -from pydantic import BaseModel - from litellm.llms.vertex_ai.common_utils import pop_vertex_request_labels +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import EmbeddingResponse, Usage from .types import * -class VertexAITextEmbeddingConfig(BaseModel): +class VertexAITextEmbeddingConfig(LiteLLMBaseModel): """ Reference: https://cloud.google.com/vertex-ai/generative-ai/docs/model-reference/text-embeddings-api#TextEmbeddingInput diff --git a/litellm/llms/xai/audio_transcription/transformation.py b/litellm/llms/xai/audio_transcription/transformation.py index 5d810712634..e34034b5ae9 100644 --- a/litellm/llms/xai/audio_transcription/transformation.py +++ b/litellm/llms/xai/audio_transcription/transformation.py @@ -6,11 +6,12 @@ from collections.abc import Mapping, Sequence from typing import Final from httpx import Headers, Response -from pydantic import BaseModel, ConfigDict, TypeAdapter, ValidationError +from pydantic import ConfigDict, TypeAdapter, ValidationError import litellm from litellm.litellm_core_utils.audio_utils.utils import process_audio_file from litellm.llms.base_llm.chat.transformation import BaseLLMException +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import ( AllMessageValues, OpenAIAudioTranscriptionOptionalParams, @@ -28,7 +29,7 @@ class XAIAudioTranscriptionError(BaseLLMException): pass -class _XAISttWord(BaseModel): +class _XAISttWord(LiteLLMBaseModel): model_config = ConfigDict(extra="allow") text: str = "" start: float = 0.0 @@ -36,7 +37,7 @@ class _XAISttWord(BaseModel): speaker: int | None = None -class _XAISttResponse(BaseModel): +class _XAISttResponse(LiteLLMBaseModel): model_config = ConfigDict(extra="allow") text: str = "" language: str = "unknown" diff --git a/litellm/llms/xai/batches/transformation.py b/litellm/llms/xai/batches/transformation.py index 2d986ab99df..44a13ff9c84 100644 --- a/litellm/llms/xai/batches/transformation.py +++ b/litellm/llms/xai/batches/transformation.py @@ -15,7 +15,7 @@ import httpx from openai.types.batch import BatchRequestCounts from openai.types.batch import Errors as BatchErrors from openai.types.batch_error import BatchError -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict from typing_extensions import NotRequired, ReadOnly, TypedDict from litellm.constants import XAI_API_BASE @@ -23,6 +23,7 @@ from litellm.litellm_core_utils.url_utils import encode_url_path_segment from litellm.llms.base_llm.chat.transformation import BaseLLMException from litellm.llms.xai.common_utils import XAIModelInfo from litellm.secret_managers.main import get_secret_str +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import CreateBatchRequest from litellm.types.utils import LiteLLMBatch @@ -89,7 +90,7 @@ class XAICreateBatchRequest(TypedDict): input_file_id: NotRequired[ReadOnly[str]] -class XAIBatchState(BaseModel): +class XAIBatchState(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") num_requests: int = 0 @@ -99,7 +100,7 @@ class XAIBatchState(BaseModel): num_cancelled: int = 0 -class XAIBatch(BaseModel): +class XAIBatch(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") batch_id: str @@ -112,35 +113,35 @@ class XAIBatch(BaseModel): input_file_id: str | None = None -class XAIBatchList(BaseModel): +class XAIBatchList(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") batches: tuple[XAIBatch, ...] = () pagination_token: str | None = None -class XAIBatchResultError(BaseModel): +class XAIBatchResultError(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") code: int | str | None = None message: str = "" -class XAIBatchResultData(BaseModel): +class XAIBatchResultData(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") response: Mapping[str, Mapping[str, object]] | None = None error: XAIBatchResultError | None = None -class XAIBatchResult(BaseModel): +class XAIBatchResult(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") batch_request_id: str batch_result: XAIBatchResultData = XAIBatchResultData() -class XAIBatchResultsPage(BaseModel): +class XAIBatchResultsPage(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") results: tuple[XAIBatchResult, ...] = () @@ -202,7 +203,7 @@ def to_litellm_batch(batch: XAIBatch, endpoint: str = DEFAULT_BATCH_ENDPOINT) -> ) -class OpenAIBatchListResponse(BaseModel): +class OpenAIBatchListResponse(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) object: Literal["list"] = "list" diff --git a/litellm/llms/xai/files/transformation.py b/litellm/llms/xai/files/transformation.py index 94fa681d319..33baca79005 100644 --- a/litellm/llms/xai/files/transformation.py +++ b/litellm/llms/xai/files/transformation.py @@ -10,13 +10,14 @@ from typing import Final import httpx from openai.types.file_deleted import FileDeleted -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict from typing_extensions import ReadOnly, TypedDict from litellm.litellm_core_utils.prompt_templates.common_utils import extract_file_data from litellm.litellm_core_utils.url_utils import encode_url_path_segment from litellm.llms.base_llm.chat.transformation import BaseLLMException from litellm.llms.base_llm.files.transformation import BaseFilesConfig, LiteLLMLoggingObj +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import ( CreateFileRequest, FileContentRequest, @@ -43,7 +44,7 @@ class XAIMultipartUpload(TypedDict): purpose: ReadOnly[tuple[None, str]] -class XAIFile(BaseModel): +class XAIFile(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") id: str @@ -54,14 +55,14 @@ class XAIFile(BaseModel): expires_at: int | None = None -class XAIFileList(BaseModel): +class XAIFileList(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") data: tuple[XAIFile, ...] = () pagination_token: str | None = None -class XAIFileDeleted(BaseModel): +class XAIFileDeleted(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") id: str diff --git a/litellm/main.py b/litellm/main.py index d81bb75bc46..5b0af2e479c 100644 --- a/litellm/main.py +++ b/litellm/main.py @@ -44,6 +44,7 @@ import litellm # client must be imported from litellm as it's a decorator used at function definition time from litellm import client +from litellm.types.llms.base import LiteLLMBaseModel # Other utils are imported directly to avoid circular imports from litellm.utils import ( @@ -862,11 +863,11 @@ async def _sleep_for_timeout_async(timeout: float | str | httpx.Timeout): await asyncio.sleep(timeout.connect) -class _AdmissionReservation(BaseModel): +class _AdmissionReservation(LiteLLMBaseModel): input_tokens: int | None = None -class _AdmissionMetadata(BaseModel): +class _AdmissionMetadata(LiteLLMBaseModel): user_api_key_budget_reservation: _AdmissionReservation | None = None diff --git a/litellm/models/base.py b/litellm/models/base.py index 8125bfd0205..3105fc9b91d 100644 --- a/litellm/models/base.py +++ b/litellm/models/base.py @@ -5,10 +5,12 @@ Base model class for domain models. from datetime import datetime from typing import Any -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict + +from litellm.types.llms.base import LiteLLMBaseModel -class DomainModel(BaseModel): +class DomainModel(LiteLLMBaseModel): """Base class for all domain models.""" model_config = ConfigDict( diff --git a/litellm/models/credentials.py b/litellm/models/credentials.py index e96e406d98e..b91ced275ff 100644 --- a/litellm/models/credentials.py +++ b/litellm/models/credentials.py @@ -7,10 +7,12 @@ layer; ``litellm.types.utils`` re-exports them for backwards compatibility. from collections.abc import Mapping -from pydantic import BaseModel, Field, model_validator +from pydantic import Field, model_validator + +from litellm.types.llms.base import LiteLLMBaseModel -class CredentialBase(BaseModel): +class CredentialBase(LiteLLMBaseModel): credential_name: str credential_info: dict @@ -35,7 +37,7 @@ class CreateCredentialItem(CredentialBase): return values -class UpdateCredentialItem(BaseModel): +class UpdateCredentialItem(LiteLLMBaseModel): credential_name: str credential_info: Mapping[str, object] credential_values: Mapping[str, object] | None = None diff --git a/litellm/models/user.py b/litellm/models/user.py index 92aca87d303..7dcaed9f77f 100644 --- a/litellm/models/user.py +++ b/litellm/models/user.py @@ -7,13 +7,13 @@ Canonical definition for ``litellm_usertable``. Re-exported from from datetime import datetime -from pydantic import BaseModel, ConfigDict, Field, model_validator +from pydantic import ConfigDict, Field, model_validator from litellm.models.object_permission import LiteLLM_ObjectPermissionTable from litellm.models.organization_membership import ( LiteLLM_OrganizationMembershipTable, ) -from litellm.types.llms.base import LiteLLMPydanticObjectBase +from litellm.types.llms.base import LiteLLMBaseModel, LiteLLMPydanticObjectBase class LiteLLM_UserTable(LiteLLMPydanticObjectBase): @@ -71,7 +71,7 @@ class LiteLLM_UserTable(LiteLLMPydanticObjectBase): return model_name in self.models -class SCIMPlaceholder(BaseModel): +class SCIMPlaceholder(LiteLLMBaseModel): """A user row keyed by a value that names another account by SSO identity or email.""" placeholder_user_id: str diff --git a/litellm/proxy/_experimental/mcp_server/discoverable_endpoints.py b/litellm/proxy/_experimental/mcp_server/discoverable_endpoints.py index 342c650d2a6..26b2d296713 100644 --- a/litellm/proxy/_experimental/mcp_server/discoverable_endpoints.py +++ b/litellm/proxy/_experimental/mcp_server/discoverable_endpoints.py @@ -12,7 +12,7 @@ from urllib.parse import parse_qsl, urlencode, urlparse, urlunparse import httpx from fastapi import APIRouter, Depends, Form, HTTPException, Request from fastapi.responses import HTMLResponse, JSONResponse, RedirectResponse, Response -from pydantic import BaseModel, ConfigDict, Field, SecretStr, TypeAdapter, ValidationError +from pydantic import ConfigDict, Field, SecretStr, TypeAdapter, ValidationError from litellm._logging import verbose_logger from litellm.caching.in_memory_cache import InMemoryCache @@ -91,6 +91,7 @@ from litellm.proxy.common_utils.encrypt_decrypt_utils import ( encrypt_value_helper, ) from litellm.proxy.common_utils.http_parsing_utils import _read_request_body +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.mcp import MCPAuth, MCPCredentials from litellm.types.mcp_server.mcp_server_manager import MCPServer, MCPTokenEndpointAuthMethod @@ -278,7 +279,7 @@ def decode_state_hash(encrypted_state: str) -> dict: _BRIDGE_AUTH_CODE_PREFIX: Final = "llm_bcode_" -class _BridgeAuthorizationCode(BaseModel): +class _BridgeAuthorizationCode(LiteLLMBaseModel): """Authenticated caller and upstream code sealed for bridge or identity-bound per-user OAuth.""" model_config = ConfigDict(frozen=True) @@ -340,7 +341,7 @@ def open_bridge_authorization_code(code: str) -> _BridgeAuthorizationCode | None _PASSTHROUGH_AUTH_CODE_PREFIX: Final = "llm_ptcode_" -class PassthroughAuthorizationCode(BaseModel): +class PassthroughAuthorizationCode(LiteLLMBaseModel): """The ephemeral DCR client and upstream code the gateway seals into the authorization code it forwards for a client-forwarded-token server (``true_passthrough`` / ``oauth_delegate``) whose authorize fell through to gateway-side registration. These modes forbid the gateway from storing @@ -1380,7 +1381,7 @@ async def exchange_token_with_server( return JSONResponse(result, headers=TOKEN_NO_CACHE_HEADERS) -class _DcrClientRegistration(BaseModel): +class _DcrClientRegistration(LiteLLMBaseModel): """RFC 7591 dynamic client registration response, narrowed to the fields the gateway must persist to authenticate later token-endpoint calls. Extra members are ignored.""" @@ -1389,7 +1390,7 @@ class _DcrClientRegistration(BaseModel): token_endpoint_auth_method: str | None = None -class _PersistedDcrCredentials(BaseModel): +class _PersistedDcrCredentials(LiteLLMBaseModel): dcr_issuer: str | None = None dcr_server_url: str | None = None client_id: str | None = None @@ -1784,7 +1785,7 @@ async def _post_dcr_registration( return response -class EphemeralDcrClient(BaseModel): +class EphemeralDcrClient(LiteLLMBaseModel): """A DCR client minted for a single authorize round trip and never stored by the gateway.""" model_config = ConfigDict(frozen=True) diff --git a/litellm/proxy/_experimental/mcp_server/faults/list_outcomes.py b/litellm/proxy/_experimental/mcp_server/faults/list_outcomes.py index b96a7a74e4a..06bf56f6f96 100644 --- a/litellm/proxy/_experimental/mcp_server/faults/list_outcomes.py +++ b/litellm/proxy/_experimental/mcp_server/faults/list_outcomes.py @@ -16,7 +16,7 @@ from typing import Final, Literal, NamedTuple, NoReturn, TypeAlias import httpx import httpx2 from mcp.types import Tool as MCPTool -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict from typing_extensions import assert_never from litellm.proxy._experimental.mcp_server.exceptions import ( @@ -24,6 +24,7 @@ from litellm.proxy._experimental.mcp_server.exceptions import ( MCPUpstreamAuthError, ) from litellm.proxy._experimental.mcp_server.faults.traversal import iter_exception_tree +from litellm.types.llms.base import LiteLLMBaseModel ListFaultCategory: TypeAlias = Literal[ "auth_required", @@ -35,13 +36,13 @@ ListFaultCategory: TypeAlias = Literal[ ] -class ServerListOk(BaseModel): +class ServerListOk(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) tag: Literal["ok"] = "ok" tool_count: int -class ServerListFault(BaseModel): +class ServerListFault(LiteLLMBaseModel): """Why a server contributed nothing to a listing: the caller must authenticate upstream (``auth_required``/``forbidden``), the upstream did not answer (``timeout``/``unreachable``), the upstream answered outside its contract (``upstream_error``), or the gateway itself failed diff --git a/litellm/proxy/_experimental/mcp_server/faults/types.py b/litellm/proxy/_experimental/mcp_server/faults/types.py index d081d9d735e..e6a52edcf2c 100644 --- a/litellm/proxy/_experimental/mcp_server/faults/types.py +++ b/litellm/proxy/_experimental/mcp_server/faults/types.py @@ -9,7 +9,9 @@ from __future__ import annotations from typing import Final, Literal, TypeAlias -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict + +from litellm.types.llms.base import LiteLLMBaseModel MAX_WIRE_FIELD_CHARS: Final = 500 """Bound on every upstream-derived string that crosses to a caller or into a log line.""" @@ -35,7 +37,7 @@ UPSTREAM_FAULT_CODES: Final[frozenset[str]] = frozenset({"server_error", "tempor they classify as upstream-reported faults and render on the 5xx their meaning implies.""" -class CallerRejected(BaseModel): +class CallerRejected(LiteLLMBaseModel): """The upstream spoke the OAuth error contract and the failure is actionable by our caller (e.g. ``invalid_grant``: re-run authorization). The code and its bounded prose relay on the 4xx status the code itself implies.""" @@ -47,7 +49,7 @@ class CallerRejected(BaseModel): error_uri: str | None = None -class GatewayRejected(BaseModel): +class GatewayRejected(LiteLLMBaseModel): """The upstream rejected the request for a cause only the gateway operator can address: the server's stored client credentials or a gateway capability gap. Not actionable by the caller: rendered as 502 with gateway-authored prose naming the code; the upstream's prose goes to @@ -58,7 +60,7 @@ class GatewayRejected(BaseModel): code: str -class UpstreamReportedFault(BaseModel): +class UpstreamReportedFault(LiteLLMBaseModel): """The upstream blamed itself in the OAuth vocabulary. Rendered on the 5xx the code implies (``server_error`` 502, ``temporarily_unavailable`` 503) so blame and status agree.""" @@ -67,7 +69,7 @@ class UpstreamReportedFault(BaseModel): code: Literal["server_error", "temporarily_unavailable"] -class UpstreamProtocolFault(BaseModel): +class UpstreamProtocolFault(LiteLLMBaseModel): """The upstream broke the error contract: no JSON ``error`` field, an undecodable body, or a success response without a usable token. Rendered as 502 with a gateway-authored note; the upstream body never crosses to the caller.""" @@ -77,7 +79,7 @@ class UpstreamProtocolFault(BaseModel): note: str -class UpstreamRegistrationRefused(BaseModel): +class UpstreamRegistrationRefused(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) tag: Literal["upstream_registration_refused"] = "upstream_registration_refused" status_code: Literal[401, 403] diff --git a/litellm/proxy/_experimental/mcp_server/gateway_dcr_flow.py b/litellm/proxy/_experimental/mcp_server/gateway_dcr_flow.py index 1136410fd18..c4777179256 100644 --- a/litellm/proxy/_experimental/mcp_server/gateway_dcr_flow.py +++ b/litellm/proxy/_experimental/mcp_server/gateway_dcr_flow.py @@ -92,6 +92,7 @@ from litellm.proxy.common_utils.encrypt_decrypt_utils import ( from litellm.proxy.common_utils.html_forms.native_client_consent import ( render_native_client_consent_page, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.mcp_server.mcp_server_manager import MCPServer _DCR_CLAIMS_TARGET: Final = "mcp_dcr_claims" @@ -172,7 +173,7 @@ credential that LLM routes accept, instead of the MCP-only session pair.""" ProxyCredentialMintFailure = Literal[ReloadUserFailure, "not_a_member", "team_required"] -class MintedProxyCredential(BaseModel): +class MintedProxyCredential(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) key: str = Field(min_length=1) expires_in: int = Field(gt=0) @@ -216,13 +217,13 @@ SUBJECT_TOKEN_TYPES: Final = frozenset( ) -class SubjectIdentity(BaseModel): +class SubjectIdentity(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) user_id: str = Field(min_length=1) team_id: str | None = None -class SubjectTokenRefusal(BaseModel): +class SubjectTokenRefusal(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) error: Literal["unsupported_grant_type", "invalid_request", "temporarily_unavailable"] description: str = Field(min_length=1) @@ -236,7 +237,7 @@ class ExchangeSubjectToken(Protocol): def __call__(self, subject_token: str, request: Request, /) -> Awaitable[SubjectIdentity | SubjectTokenRefusal]: ... -class ConsentTeam(BaseModel): +class ConsentTeam(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) team_id: str = Field(min_length=1) team_alias: str | None = None @@ -276,7 +277,7 @@ async def _unreachable_server(user_id: str, server_id: str) -> bool: return False -class GatewayDcrClient(BaseModel): +class GatewayDcrClient(LiteLLMBaseModel): """The registration record sealed into a gateway DCR ``client_id``. ``extra="forbid"`` so a sealed value of another type (an auth code, a connect flow) @@ -289,7 +290,7 @@ class GatewayDcrClient(BaseModel): iat: int -class _ConnectFlow(BaseModel): +class _ConnectFlow(LiteLLMBaseModel): """One in-flight authorize: the SSO user it belongs to and the client parameters needed to mint the code at the finish step. Sealed into the per-flow cookie. ``jti`` makes the flow single-use at complete; ``extra="forbid"`` rejects cross-type @@ -307,7 +308,7 @@ class _ConnectFlow(BaseModel): audience: SessionAudience | None = None -class _GatewayAuthCode(BaseModel): +class _GatewayAuthCode(LiteLLMBaseModel): """The gateway-sealed authorization code: the user consent it represents and the bindings the token endpoint must verify (client, redirect URI, PKCE challenge), plus a ``jti`` for the single-use guard. ``extra="forbid"`` rejects cross-type diff --git a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py index abfb9dc56fe..4e7054cab98 100644 --- a/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py +++ b/litellm/proxy/_experimental/mcp_server/mcp_server_manager.py @@ -48,7 +48,7 @@ from mcp.types import ( ResourceTemplate, ) from mcp.types import Tool as MCPTool -from pydantic import AnyUrl, BaseModel, TypeAdapter +from pydantic import AnyUrl, BaseModel, Field, TypeAdapter from typing_extensions import ReadOnly import litellm @@ -197,6 +197,7 @@ from litellm.proxy.middleware.per_request_root_path_middleware import ( from litellm.proxy.utils import PrismaClient, ProxyLogging from litellm.repositories.table_repositories import MCPServerRepository from litellm.types.integrations.slack_alerting import AlertType +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.custom_http import httpxSpecialProvider from litellm.types.mcp import ( DEFAULT_SUBJECT_TOKEN_TYPE, @@ -223,13 +224,11 @@ try: validate_tool_name, # pyright: ignore[reportAssignmentType] ) except ImportError: - from pydantic import BaseModel - SEP_986_URL = "https://github.com/modelcontextprotocol/protocol/blob/main/proposals/0001-tool-name-validation.md" - class _ToolNameValidationResult(BaseModel): + class _ToolNameValidationResult(LiteLLMBaseModel): is_valid: bool = True - warnings: list = [] + warnings: list = Field(default=[]) def validate_tool_name(name: str) -> _ToolNameValidationResult: return _ToolNameValidationResult() diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/bridge_credentials.py b/litellm/proxy/_experimental/mcp_server/outbound_credentials/bridge_credentials.py index ab5fa65480e..1441d9662be 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/bridge_credentials.py +++ b/litellm/proxy/_experimental/mcp_server/outbound_credentials/bridge_credentials.py @@ -14,7 +14,7 @@ from datetime import datetime from functools import lru_cache from typing import Final, Literal, TypeAlias -from pydantic import BaseModel, ConfigDict, SecretStr +from pydantic import ConfigDict, SecretStr from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import ( EnvelopeIdentity, @@ -32,6 +32,7 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.envelope import open_envelope, open_refresh_envelope, ) +from litellm.types.llms.base import LiteLLMBaseModel _SIGNING_KEY_DOMAIN: Final = b"litellm-mcp-bridge:envelope-signing:" _ENCRYPTION_KEY_DOMAIN: Final = b"litellm-mcp-bridge:envelope-encryption:" @@ -110,7 +111,7 @@ def build_bridge_refresh_token_response( return mint_refresh_envelope(identity, refresh, keys, now) -class BridgeRefreshOpened(BaseModel): +class BridgeRefreshOpened(LiteLLMBaseModel): """A valid refresh envelope presented to the token endpoint: the identity to re-validate and renew under, and the upstream refresh grant to exchange.""" @@ -120,7 +121,7 @@ class BridgeRefreshOpened(BaseModel): refresh: RefreshCredential -class BridgeRefreshInvalid(BaseModel): +class BridgeRefreshInvalid(LiteLLMBaseModel): """The presented refresh grant is not a valid refresh envelope for this server (not refresh-shaped, will not open, or minted for a different server); the token endpoint fails the refresh closed.""" @@ -158,14 +159,14 @@ def open_bridge_refresh_envelope( return BridgeRefreshOpened(identity=opened.identity, refresh=opened.refresh) -class NotBridgeEnvelope(BaseModel): +class NotBridgeEnvelope(LiteLLMBaseModel): """The bearer is not an envelope; admission continues on its normal path.""" model_config = ConfigDict(frozen=True) tag: Literal["not_bridge_envelope"] = "not_bridge_envelope" -class BridgeEnvelopeAdmitted(BaseModel): +class BridgeEnvelopeAdmitted(LiteLLMBaseModel): """A valid envelope: the identity to admit under and the full upstream ``Authorization`` value (``token_type access_token``) to forward to the upstream MCP server.""" @@ -175,7 +176,7 @@ class BridgeEnvelopeAdmitted(BaseModel): upstream_authorization: SecretStr -class BridgeEnvelopeInvalid(BaseModel): +class BridgeEnvelopeInvalid(LiteLLMBaseModel): """The bearer is envelope-shaped but did not open (expired, tampered, wrong key); admission must fail closed rather than fall through to normal validation.""" diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/client_credentials.py b/litellm/proxy/_experimental/mcp_server/outbound_credentials/client_credentials.py index 3a8e2b3840a..e628b3880b3 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/client_credentials.py +++ b/litellm/proxy/_experimental/mcp_server/outbound_credentials/client_credentials.py @@ -35,7 +35,7 @@ from typing import Annotated, Final, Literal import httpx import httpx2 -from pydantic import BaseModel, ConfigDict, Field, SecretStr, TypeAdapter, ValidationError +from pydantic import ConfigDict, Field, SecretStr, TypeAdapter, ValidationError from typing_extensions import assert_never from litellm._logging import verbose_logger @@ -54,9 +54,10 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( CredError, HeaderCarrier, ) +from litellm.types.llms.base import LiteLLMBaseModel -class TokenEndpointSuccess(BaseModel): +class TokenEndpointSuccess(LiteLLMBaseModel): """The endpoint returned a JSON object; field validation is the caller's job.""" model_config = ConfigDict(frozen=True) @@ -64,7 +65,7 @@ class TokenEndpointSuccess(BaseModel): body: dict[str, object] -class TokenEndpointDenied(BaseModel): +class TokenEndpointDenied(LiteLLMBaseModel): """The endpoint answered but did not grant a token (an HTTP error or a non-JSON body).""" model_config = ConfigDict(frozen=True) @@ -73,7 +74,7 @@ class TokenEndpointDenied(BaseModel): detail: str -class TokenEndpointUnreachable(BaseModel): +class TokenEndpointUnreachable(LiteLLMBaseModel): """The endpoint could not be reached (DNS, TLS, connect/read failure).""" model_config = ConfigDict(frozen=True) diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/envelope.py b/litellm/proxy/_experimental/mcp_server/outbound_credentials/envelope.py index df883d5a208..7dc5c69994b 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/envelope.py +++ b/litellm/proxy/_experimental/mcp_server/outbound_credentials/envelope.py @@ -38,9 +38,10 @@ from datetime import datetime, timedelta from typing import Final, Literal, TypeAlias import jwt -from pydantic import BaseModel, ConfigDict, Field, SecretStr, ValidationError +from pydantic import ConfigDict, Field, SecretStr, ValidationError from litellm.proxy.common_utils.encrypt_decrypt_utils import decrypt_value, encrypt_value +from litellm.types.llms.base import LiteLLMBaseModel ENVELOPE_PREFIX: Final = "llm_env_" """Marker prefix on every serialized ACCESS envelope so the edge can cheaply tell an envelope @@ -98,7 +99,7 @@ runs both through the same live-policy gate, so team/org/budget/revocation enfor identical either way.""" -class EnvelopeIdentity(BaseModel): +class EnvelopeIdentity(LiteLLMBaseModel): """The litellm principal the envelope binds the inner grant to. ``subject`` is the principal identifier and ``subject_type`` says how to resolve it: a @@ -125,7 +126,7 @@ def user_identity(server_id: str, user_id: str) -> EnvelopeIdentity: return EnvelopeIdentity(server_id=server_id, subject_type="user_id", subject=user_id) -class UpstreamTokenGrant(BaseModel): +class UpstreamTokenGrant(LiteLLMBaseModel): """The upstream OAuth token response fields sealed inside the envelope. ``expires_in`` must be positive when present; a non-positive value is a programmer @@ -141,7 +142,7 @@ class UpstreamTokenGrant(BaseModel): expires_in: int | None = Field(default=None, gt=0) -class RefreshCredential(BaseModel): +class RefreshCredential(LiteLLMBaseModel): """The upstream refresh grant sealed inside a refresh envelope. Only the refresh token (plus the scope to re-request and the refresh token's own lifetime, when the @@ -156,7 +157,7 @@ class RefreshCredential(BaseModel): expires_in: int | None = Field(default=None, gt=0) -class EnvelopeKeys(BaseModel): +class EnvelopeKeys(LiteLLMBaseModel): """Injected key material: the HS256 signing key and the symmetric encryption key. ``signing_key`` must be at least 32 bytes: HS256's HMAC-SHA256 has a 256-bit @@ -169,7 +170,7 @@ class EnvelopeKeys(BaseModel): encryption_key: SecretStr = Field(min_length=1) -class SealedEnvelope(BaseModel): +class SealedEnvelope(LiteLLMBaseModel): """A minted envelope: the client-held bearer value and when it expires.""" model_config = ConfigDict(frozen=True) @@ -177,7 +178,7 @@ class SealedEnvelope(BaseModel): expires_at: datetime -class OpenedEnvelope(BaseModel): +class OpenedEnvelope(LiteLLMBaseModel): """A validated access envelope: the identity it was minted for and the recovered grant.""" model_config = ConfigDict(frozen=True) @@ -185,7 +186,7 @@ class OpenedEnvelope(BaseModel): grant: UpstreamTokenGrant -class OpenedRefreshEnvelope(BaseModel): +class OpenedRefreshEnvelope(LiteLLMBaseModel): """A validated refresh envelope: the identity it was minted for and the recovered refresh grant.""" model_config = ConfigDict(frozen=True) @@ -193,7 +194,7 @@ class OpenedRefreshEnvelope(BaseModel): refresh: RefreshCredential -class EnvelopeTooLarge(BaseModel): +class EnvelopeTooLarge(LiteLLMBaseModel): """The serialized envelope exceeded ``MAX_ENVELOPE_BYTES``; carries sizes only.""" model_config = ConfigDict(frozen=True) @@ -202,7 +203,7 @@ class EnvelopeTooLarge(BaseModel): max_bytes: int -class EnvelopeLifetimeUnrepresentable(BaseModel): +class EnvelopeLifetimeUnrepresentable(LiteLLMBaseModel): """A positive provider lifetime cannot be represented as a Python datetime.""" model_config = ConfigDict(frozen=True) @@ -213,28 +214,28 @@ class EnvelopeLifetimeUnrepresentable(BaseModel): EnvelopeMintError: TypeAlias = EnvelopeTooLarge | EnvelopeLifetimeUnrepresentable -class NotAnEnvelope(BaseModel): +class NotAnEnvelope(LiteLLMBaseModel): """The candidate does not carry the envelope prefix.""" model_config = ConfigDict(frozen=True) tag: Literal["not_an_envelope"] = "not_an_envelope" -class BadSignature(BaseModel): +class BadSignature(LiteLLMBaseModel): """The JWT signature does not verify under the provided signing key.""" model_config = ConfigDict(frozen=True) tag: Literal["bad_signature"] = "bad_signature" -class Expired(BaseModel): +class Expired(LiteLLMBaseModel): """The envelope's ``exp`` is not in the future relative to the provided ``now``.""" model_config = ConfigDict(frozen=True) tag: Literal["expired"] = "expired" -class MalformedPayload(BaseModel): +class MalformedPayload(LiteLLMBaseModel): """The token is not a well-formed envelope: undecodable JWT, wrong issuer, missing or mistyped claims, or a decrypted grant that fails validation.""" @@ -242,7 +243,7 @@ class MalformedPayload(BaseModel): tag: Literal["malformed_payload"] = "malformed_payload" -class DecryptFailed(BaseModel): +class DecryptFailed(LiteLLMBaseModel): """The signed ``grant`` blob could not be decrypted under the provided key.""" model_config = ConfigDict(frozen=True) @@ -252,7 +253,7 @@ class DecryptFailed(BaseModel): EnvelopeOpenError: TypeAlias = NotAnEnvelope | BadSignature | Expired | MalformedPayload | DecryptFailed -class _EnvelopeClaims(BaseModel): +class _EnvelopeClaims(LiteLLMBaseModel): """Decoded-claims boundary that pins the exact shape :func:`mint_envelope` emits. ``server_id``/``key_hash`` mirror the ``min_length`` constraints of @@ -279,7 +280,7 @@ class _EnvelopeClaims(BaseModel): grant: str = Field(min_length=1) -class _GrantWire(BaseModel): +class _GrantWire(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) access_token: str token_type: str @@ -288,7 +289,7 @@ class _GrantWire(BaseModel): expires_in: int | None = None -class _RefreshWire(BaseModel): +class _RefreshWire(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) refresh_token: str scope: str | None = None diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/session_credentials.py b/litellm/proxy/_experimental/mcp_server/outbound_credentials/session_credentials.py index df2bbdba345..b8eda703fa8 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/session_credentials.py +++ b/litellm/proxy/_experimental/mcp_server/outbound_credentials/session_credentials.py @@ -20,7 +20,7 @@ from datetime import datetime from functools import lru_cache from typing import Final, Literal, TypeAlias -from pydantic import BaseModel, ConfigDict, Field, SecretStr, ValidationError +from pydantic import ConfigDict, Field, SecretStr, ValidationError from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token import ( AsymmetricSessionKeys, @@ -35,6 +35,7 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.session_token i open_session_refresh_token, open_session_token, ) +from litellm.types.llms.base import LiteLLMBaseModel _SESSION_SIGNING_KEY_DOMAIN: Final = b"litellm-mcp-gateway:session-signing:" @@ -71,7 +72,7 @@ def session_keys_from_master_key(master_key: str) -> SessionKeys: return SessionKeys(signing_key=SecretStr(signing)) -class SessionSigningPreviousKey(BaseModel): +class SessionSigningPreviousKey(LiteLLMBaseModel): """One retired key in ``mcp_session_token_signing.previous_public_keys``: its ``kid`` and the PEM public half (inline or an ``os.environ/`` reference).""" @@ -80,7 +81,7 @@ class SessionSigningPreviousKey(BaseModel): public_key: str = Field(min_length=1) -class MCPSessionTokenSigningSettings(BaseModel): +class MCPSessionTokenSigningSettings(LiteLLMBaseModel): """The ``general_settings.mcp_session_token_signing`` block: opt-in asymmetric signing for the gateway session tokens. Absent, the gateway keeps the backward-compatible HS256 key derived from ``master_key``. ``private_key`` and each ``public_key`` accept @@ -93,7 +94,7 @@ class MCPSessionTokenSigningSettings(BaseModel): previous_public_keys: tuple[SessionSigningPreviousKey, ...] = () -class SessionSigningConfigError(BaseModel): +class SessionSigningConfigError(LiteLLMBaseModel): """``mcp_session_token_signing`` is present but unusable (bad shape, unresolvable secret reference, or a key that is not a loadable RSA PEM); the caller fails closed with a server error instead of silently falling back to HS256.""" @@ -164,14 +165,14 @@ def active_session_signing_keys(master_key: str) -> SessionSigningKeys | Session return resolve_session_signing_keys(master_key, general_settings.get("mcp_session_token_signing")) -class NotSessionBearer(BaseModel): +class NotSessionBearer(LiteLLMBaseModel): """The bearer is not session-shaped; admission continues on its normal path.""" model_config = ConfigDict(frozen=True) tag: Literal["not_session_bearer"] = "not_session_bearer" -class SessionBearerAdmitted(BaseModel): +class SessionBearerAdmitted(LiteLLMBaseModel): """A valid session access token: the principal to admit under after a live reload.""" model_config = ConfigDict(frozen=True) @@ -179,7 +180,7 @@ class SessionBearerAdmitted(BaseModel): principal: SessionPrincipal -class SessionBearerInvalid(BaseModel): +class SessionBearerInvalid(LiteLLMBaseModel): """The bearer is session-shaped but must not admit (expired, tampered, wrong key, or a refresh token presented at the tool-call edge); admission fails closed with the ``invalid_token`` challenge rather than falling through to another arm. ``expired`` @@ -238,7 +239,7 @@ def resolve_session_bearer( return SessionBearerInvalid(expired=isinstance(opened, SessionExpired)) -class SessionRefreshOpened(BaseModel): +class SessionRefreshOpened(LiteLLMBaseModel): """A valid session refresh token presented to the token endpoint: the principal to re-validate and renew under.""" @@ -248,7 +249,7 @@ class SessionRefreshOpened(BaseModel): jti: str -class SessionRefreshInvalid(BaseModel): +class SessionRefreshInvalid(LiteLLMBaseModel): """The presented refresh grant is not a valid session refresh token for this client (not refresh-shaped, will not open, or bound to a different ``client_id``); the token endpoint fails the refresh closed.""" diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/session_token.py b/litellm/proxy/_experimental/mcp_server/outbound_credentials/session_token.py index 0fa750a4c4a..da91faccadd 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/session_token.py +++ b/litellm/proxy/_experimental/mcp_server/outbound_credentials/session_token.py @@ -43,7 +43,9 @@ import jwt from cryptography.exceptions import UnsupportedAlgorithm from cryptography.hazmat.primitives import serialization from cryptography.hazmat.primitives.asymmetric import rsa -from pydantic import BaseModel, ConfigDict, Field, SecretStr, ValidationError, field_validator, model_validator +from pydantic import ConfigDict, Field, SecretStr, ValidationError, field_validator, model_validator + +from litellm.types.llms.base import LiteLLMBaseModel SESSION_TOKEN_PREFIX: Final = "llm_session_" """Marker prefix on every serialized session ACCESS token so the admission edge can cheaply @@ -97,7 +99,7 @@ is read only from the signed claims, never from the request, so a token of one a never be redeemed as the other.""" -class SessionPrincipal(BaseModel): +class SessionPrincipal(LiteLLMBaseModel): """The litellm user a session token identifies and the DCR client it was issued to. ``user_id`` is the SSO-established litellm user subject, never a credential: admission @@ -121,7 +123,7 @@ class SessionPrincipal(BaseModel): team_id: str | None = None -class SessionKeys(BaseModel): +class SessionKeys(LiteLLMBaseModel): """Injected key material: the HS256 signing key. ``signing_key`` must be at least 32 bytes: HS256's HMAC-SHA256 has a 256-bit security @@ -133,7 +135,7 @@ class SessionKeys(BaseModel): signing_key: SecretStr = Field(min_length=32) -class SessionRotatedPublicKey(BaseModel): +class SessionRotatedPublicKey(LiteLLMBaseModel): """The public half of a retired signing key, kept verifiable under its ``kid`` during a rotation window so tokens minted before the rotation stay valid until they expire.""" @@ -155,7 +157,7 @@ class SessionRotatedPublicKey(BaseModel): return value -class AsymmetricSessionKeys(BaseModel): +class AsymmetricSessionKeys(LiteLLMBaseModel): """Injected RS256 key material: the issuer-held RSA private key and the stable ``kid`` stamped into every minted token's JOSE header, plus the public halves of previously rotated keys that verification still accepts while their tokens age out. Downstream @@ -212,7 +214,7 @@ def session_public_key_pem(keys: AsymmetricSessionKeys) -> str: return _public_key_pem_from_private(keys.private_key_pem.get_secret_value()) -class MintedSessionToken(BaseModel): +class MintedSessionToken(LiteLLMBaseModel): """A minted session token: the client-held bearer value and when it expires.""" model_config = ConfigDict(frozen=True) @@ -220,7 +222,7 @@ class MintedSessionToken(BaseModel): expires_at: datetime -class OpenedSessionToken(BaseModel): +class OpenedSessionToken(LiteLLMBaseModel): """A validated session token of either kind: the principal it was minted for, the ``jti`` so the token endpoint can enforce single-use rotation on a refresh token, and the signed ``kind``/``iat``/``exp`` so an introspection response can report the @@ -234,7 +236,7 @@ class OpenedSessionToken(BaseModel): exp: int -class SessionTokenTooLarge(BaseModel): +class SessionTokenTooLarge(LiteLLMBaseModel): """The serialized token exceeded ``MAX_SESSION_TOKEN_BYTES``; carries sizes only. Only reachable through an oversized ``client_id``, which registration should have bounded.""" @@ -247,28 +249,28 @@ class SessionTokenTooLarge(BaseModel): SessionTokenMintError: TypeAlias = SessionTokenTooLarge -class NotASessionToken(BaseModel): +class NotASessionToken(LiteLLMBaseModel): """The candidate does not carry the expected session prefix.""" model_config = ConfigDict(frozen=True) tag: Literal["not_a_session_token"] = "not_a_session_token" -class SessionBadSignature(BaseModel): +class SessionBadSignature(LiteLLMBaseModel): """The JWT signature does not verify under the provided signing key.""" model_config = ConfigDict(frozen=True) tag: Literal["session_bad_signature"] = "session_bad_signature" -class SessionExpired(BaseModel): +class SessionExpired(LiteLLMBaseModel): """The token's ``exp`` is not in the future relative to the provided ``now``.""" model_config = ConfigDict(frozen=True) tag: Literal["session_expired"] = "session_expired" -class SessionMalformed(BaseModel): +class SessionMalformed(LiteLLMBaseModel): """The token is not a well-formed session token: undecodable JWT, wrong issuer, wrong ``kind``, or missing/mistyped/extra claims.""" @@ -279,7 +281,7 @@ class SessionMalformed(BaseModel): SessionTokenOpenError: TypeAlias = NotASessionToken | SessionBadSignature | SessionExpired | SessionMalformed -class _SessionClaims(BaseModel): +class _SessionClaims(LiteLLMBaseModel): """Decoded-claims boundary that pins the exact shape the mints emit. ``user_id``/``client_id`` mirror the ``min_length`` constraints of @@ -469,7 +471,7 @@ def _open( ) -class _VerificationMaterial(BaseModel): +class _VerificationMaterial(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) key: SecretStr algorithm: Literal["HS256", "RS256"] diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/sso_assertion_store.py b/litellm/proxy/_experimental/mcp_server/outbound_credentials/sso_assertion_store.py index 5503d19211b..0bc17d94165 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/sso_assertion_store.py +++ b/litellm/proxy/_experimental/mcp_server/outbound_credentials/sso_assertion_store.py @@ -23,11 +23,12 @@ from datetime import datetime, timezone from typing import TYPE_CHECKING, Final, Protocol import jwt -from pydantic import BaseModel, ConfigDict, SecretStr, TypeAdapter, ValidationError +from pydantic import ConfigDict, SecretStr, TypeAdapter, ValidationError from litellm._logging import verbose_proxy_logger from litellm.caching.in_memory_cache import InMemoryCache from litellm.constants import MCP_OAUTH2_TOKEN_CACHE_MAX_SIZE, MCP_SSO_ASSERTION_CACHE_TTL_SECONDS +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: from prisma.models import LiteLLM_SSOIdentityAssertion @@ -67,7 +68,7 @@ def _mcp_server_table(prisma_client: PrismaClient) -> _MCPServerTable: return prisma_client.db.litellm_mcpservertable -class SSOIdentityAssertion(BaseModel): +class SSOIdentityAssertion(LiteLLMBaseModel): """The IdP material an EMA exchange needs: ``id_token`` is the RFC 8693 subject token, ``expires_at`` bounds its usefulness, and the refresh token renews it without re-login.""" @@ -119,12 +120,12 @@ class SSOAssertionCache: _ASSERTION_CACHE: Final = SSOAssertionCache() -class _IdTokenClaims(BaseModel): +class _IdTokenClaims(LiteLLMBaseModel): exp: float | None = None iss: str | None = None -class _StoredAssertionPayload(BaseModel): +class _StoredAssertionPayload(LiteLLMBaseModel): id_token: str refresh_token: str | None = None issuer: str | None = None diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/token_endpoint.py b/litellm/proxy/_experimental/mcp_server/outbound_credentials/token_endpoint.py index 6f1e5baa109..1ee1b7ecf2f 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/token_endpoint.py +++ b/litellm/proxy/_experimental/mcp_server/outbound_credentials/token_endpoint.py @@ -24,7 +24,7 @@ from typing import Final import httpx import jwt -from pydantic import BaseModel, TypeAdapter, ValidationError +from pydantic import TypeAdapter, ValidationError from typing_extensions import assert_never from litellm._logging import verbose_proxy_logger @@ -50,6 +50,7 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.types import ( CredError, PrivateKeyJwtAuth, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.custom_http import httpxSpecialProvider # The cache stores (fingerprint, token); anything else in the slot is treated as absent. @@ -65,7 +66,7 @@ class ExchangedToken: expires_in: int | None -class _TokenEndpointResponse(BaseModel): +class _TokenEndpointResponse(LiteLLMBaseModel): access_token: str expires_in: int | None = None diff --git a/litellm/proxy/_experimental/mcp_server/outbound_credentials/types.py b/litellm/proxy/_experimental/mcp_server/outbound_credentials/types.py index 33c3a854058..55a73687b6f 100644 --- a/litellm/proxy/_experimental/mcp_server/outbound_credentials/types.py +++ b/litellm/proxy/_experimental/mcp_server/outbound_credentials/types.py @@ -32,7 +32,7 @@ from typing import Annotated, Final, Literal import httpx2 from expression import case, tag, tagged_union -from pydantic import BaseModel, ConfigDict, Field, SecretStr, field_validator +from pydantic import ConfigDict, Field, SecretStr, field_validator from typing_extensions import assert_never from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( @@ -40,6 +40,7 @@ from litellm.proxy._experimental.mcp_server.outbound_credentials.result import ( Ok, Result, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.mcp import ( DEFAULT_CREDENTIAL_HEADER, DEFAULT_SUBJECT_TOKEN_TYPE, @@ -213,7 +214,7 @@ def validate_header_name(raw: str) -> Result[str, CredError]: return Ok(normalized) -class HeaderCarrier(BaseModel): +class HeaderCarrier(LiteLLMBaseModel): """Where a resolved credential is written upstream, and how its value is formatted. ``Authorization: Bearer`` is only OAuth's *default* conveyance (RFC 6750 section 2.1), not its @@ -319,7 +320,7 @@ class TokenExchangeConfig(HeaderCarrier): scopes: tuple[str, ...] = () -class PrivateKeyJwtAuth(BaseModel): +class PrivateKeyJwtAuth(LiteLLMBaseModel): """RFC 7523 private-key-JWT client authentication: the gateway signs a `client_assertion`.""" model_config = ConfigDict(frozen=True) @@ -329,7 +330,7 @@ class PrivateKeyJwtAuth(BaseModel): signing_alg: str = "RS256" -class ClientSecretAuth(BaseModel): +class ClientSecretAuth(LiteLLMBaseModel): """`client_secret_post` client authentication: the gateway posts `client_id` + `client_secret`.""" model_config = ConfigDict(frozen=True) @@ -362,7 +363,7 @@ class IdJagConfig(HeaderCarrier): scopes: tuple[str, ...] = () -class SharedKey(BaseModel): +class SharedKey(LiteLLMBaseModel): """A fixed key configured on the server, identical for every caller.""" model_config = ConfigDict(frozen=True) @@ -370,7 +371,7 @@ class SharedKey(BaseModel): value: SecretStr -class Byok(BaseModel): +class Byok(LiteLLMBaseModel): """A key the user brings via the entry flow, stored per-user and pulled from the credential store at resolve time. Missing means the user must provide it, a 401 + WWW-Authenticate challenge.""" @@ -393,21 +394,21 @@ class ApiKeyConfig(HeaderCarrier): key_source: ApiKeySource -class PassthroughConfig(BaseModel): +class PassthroughConfig(LiteLLMBaseModel): """Client-driven upstream OAuth; the gateway forwards the client's upstream token.""" model_config = ConfigDict(frozen=True) kind: Literal[AuthSpecKind.passthrough] = AuthSpecKind.passthrough -class NoneConfig(BaseModel): +class NoneConfig(LiteLLMBaseModel): """No upstream credential; the request is sent unauthenticated.""" model_config = ConfigDict(frozen=True) kind: Literal[AuthSpecKind.none] = AuthSpecKind.none -class StaticKeys(BaseModel): +class StaticKeys(LiteLLMBaseModel): """Long-lived AWS access keys configured on the server.""" model_config = ConfigDict(frozen=True) @@ -417,7 +418,7 @@ class StaticKeys(BaseModel): session_token: SecretStr | None = None -class AssumeRole(BaseModel): +class AssumeRole(LiteLLMBaseModel): """An IAM role the gateway assumes via STS for short-lived, auto-refreshed credentials.""" model_config = ConfigDict(frozen=True) @@ -427,7 +428,7 @@ class AssumeRole(BaseModel): external_id: str | None = None -class Ambient(BaseModel): +class Ambient(LiteLLMBaseModel): """The environment's default AWS credential chain (instance profile, IRSA, env vars).""" model_config = ConfigDict(frozen=True) @@ -437,7 +438,7 @@ class Ambient(BaseModel): AwsCredentialSource = Annotated[StaticKeys | AssumeRole | Ambient, Field(discriminator="source")] -class AwsSigV4Config(BaseModel): +class AwsSigV4Config(LiteLLMBaseModel): """AWS SigV4 per-request signing for an AWS-hosted upstream (e.g. Bedrock AgentCore). The gateway signs with its own AWS identity, never the caller's; `credentials` selects how that identity is obtained, defaulting to the ambient credential chain.""" @@ -462,7 +463,7 @@ AuthConfig = Annotated[ ] -class Subject(BaseModel): +class Subject(LiteLLMBaseModel): """The validated inbound principal. NOT the v1 request object and NOT the LiteLLM key.""" model_config = ConfigDict(frozen=True) @@ -474,7 +475,7 @@ class Subject(BaseModel): inbound_token: SecretStr | None = None -class ServerSpec(BaseModel): +class ServerSpec(LiteLLMBaseModel): """The declared upstream. A v2-native type; the v1 -> v2 adapter maps onto this.""" model_config = ConfigDict(frozen=True) diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py index c0f2472a6bd..291e991f6bd 100644 --- a/litellm/proxy/_types.py +++ b/litellm/proxy/_types.py @@ -38,6 +38,7 @@ from litellm.types.integrations.otel_span_attributes import ( SpanAttributes as SpanAttributes, # noqa: PLC0414 # public re-export ) from litellm.types.integrations.slack_alerting import AlertType +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import ( AllMessageValues, ResponsesAPIResponse, @@ -2599,7 +2600,7 @@ class CallbackDelete(LiteLLMPydanticObjectBase): callback_name: str -class FieldDetail(BaseModel): +class FieldDetail(LiteLLMBaseModel): field_name: str field_type: str field_description: str @@ -3834,7 +3835,7 @@ class LiteLLM_ProjectTableCachedObj(LiteLLM_ProjectTable): last_refreshed_at: float | None = None -class LiteLLM_UserTableFiltered(BaseModel): # done to avoid exposing sensitive data +class LiteLLM_UserTableFiltered(LiteLLMBaseModel): # done to avoid exposing sensitive data user_id: str user_email: str | None = None @@ -4750,14 +4751,14 @@ class TeamMemberUpdateResponse(MemberUpdateResponse): temp_budget_expiry: datetime | None = None -class TeamModelAddRequest(BaseModel): +class TeamModelAddRequest(LiteLLMBaseModel): """Request to add models to a team""" team_id: str models: list[str] -class TeamModelDeleteRequest(BaseModel): +class TeamModelDeleteRequest(LiteLLMBaseModel): """Request to delete models from a team""" team_id: str @@ -4812,20 +4813,20 @@ class TeamInfoMember(Member): user_alias: str | None = None -class TeamEditUnrestricted(BaseModel): +class TeamEditUnrestricted(LiteLLMBaseModel): kind: Literal["unrestricted"] = "unrestricted" -class TeamEditAsTeamAdmin(BaseModel): +class TeamEditAsTeamAdmin(LiteLLMBaseModel): kind: Literal["team_admin"] = "team_admin" editable_fields: tuple[str, ...] -class TeamEditAsTeamAdminDisabled(BaseModel): +class TeamEditAsTeamAdminDisabled(LiteLLMBaseModel): kind: Literal["team_admin_disabled"] = "team_admin_disabled" -class TeamEditNone(BaseModel): +class TeamEditNone(LiteLLMBaseModel): kind: Literal["none"] = "none" @@ -4864,7 +4865,7 @@ class TeamInfoResponseObject(TypedDict): team_memberships: ReadOnly[tuple[TeamInfoMembership, ...]] -class TeamMemberResetBudgetResponse(BaseModel): +class TeamMemberResetBudgetResponse(LiteLLMBaseModel): team_id: str user_id: str budget_id: str | None @@ -5150,12 +5151,12 @@ class RoleBasedPermissions(OIDCPermissions): } -class RoleMapping(BaseModel): +class RoleMapping(LiteLLMBaseModel): role: str internal_role: RBAC_ROLES -class JWTLiteLLMRoleMap(BaseModel): +class JWTLiteLLMRoleMap(LiteLLMBaseModel): jwt_role: str litellm_role: LitellmUserRoles @@ -5168,7 +5169,7 @@ class ScopeMapping(OIDCPermissions): } -class JWTRoutingOverride(BaseModel): +class JWTRoutingOverride(LiteLLMBaseModel): """ Override default auth routing for JWT-shaped bearer tokens. @@ -5187,9 +5188,7 @@ class JWTRoutingOverride(BaseModel): aud: str | list[str] | None = None path: Literal["oauth2"] = "oauth2" - model_config = { - "extra": "forbid", - } + model_config = ConfigDict(extra="forbid") class UnregisteredJWTClientBehavior(str, enum.Enum): @@ -5211,7 +5210,7 @@ class UnregisteredJWTClientBehavior(str, enum.Enum): AUTO_REGISTER = "auto_register" -class JWTIssuerConfig(BaseModel): +class JWTIssuerConfig(LiteLLMBaseModel): """ Issuer-bound JWT validation configuration. @@ -5268,9 +5267,7 @@ class JWTIssuerConfig(BaseModel): description="Issuer-specific policy when the virtual key claim has no mapping. Falls back to the global policy.", ) - model_config = { - "extra": "forbid", - } + model_config = ConfigDict(extra="forbid") @model_validator(mode="after") def validate_audience_configured(self) -> "JWTIssuerConfig": @@ -5567,7 +5564,7 @@ class SpecialManagementEndpointEnums(enum.Enum): DEFAULT_ORGANIZATION = "default_organization" -class TransformRequestBody(BaseModel): +class TransformRequestBody(LiteLLMBaseModel): call_type: CallTypes request_body: dict diff --git a/litellm/proxy/a2a/endpoints.py b/litellm/proxy/a2a/endpoints.py index 57fc5f1dce2..56b512df934 100644 --- a/litellm/proxy/a2a/endpoints.py +++ b/litellm/proxy/a2a/endpoints.py @@ -13,7 +13,7 @@ from typing import Any, Final from fastapi import APIRouter, Depends, HTTPException from fastapi.responses import JSONResponse -from pydantic import BaseModel, Field +from pydantic import Field from litellm._logging import verbose_proxy_logger from litellm.proxy._types import LitellmUserRoles, UserAPIKeyAuth @@ -24,11 +24,12 @@ from litellm.proxy.a2a.discovery import ( fetch_well_known_card, ) from litellm.proxy.auth.user_api_key_auth import user_api_key_auth +from litellm.types.llms.base import LiteLLMBaseModel router: Final = APIRouter() -class DiscoverAgentRequest(BaseModel): +class DiscoverAgentRequest(LiteLLMBaseModel): url: str = Field( ..., description=( @@ -58,7 +59,7 @@ class DiscoverAgentRequest(BaseModel): ) -class DiscoverAgentResponse(BaseModel): +class DiscoverAgentResponse(LiteLLMBaseModel): url: str agent_card: dict[str, Any] diff --git a/litellm/proxy/agent_endpoints/agent_search.py b/litellm/proxy/agent_endpoints/agent_search.py index 65a89bb2c7a..1d1778a960b 100644 --- a/litellm/proxy/agent_endpoints/agent_search.py +++ b/litellm/proxy/agent_endpoints/agent_search.py @@ -6,7 +6,7 @@ from collections.abc import Sequence from dataclasses import dataclass from typing import TYPE_CHECKING, Final, TypeAlias -from pydantic import BaseModel, ConfigDict, ValidationError +from pydantic import ConfigDict, ValidationError from litellm.proxy.common_utils.semantic_text_index import ( Embedder, @@ -15,6 +15,7 @@ from litellm.proxy.common_utils.semantic_text_index import ( router_embedder, ) from litellm.types.agents import AgentResponse +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: from litellm.proxy._types import UserAPIKeyAuth @@ -48,7 +49,7 @@ class AgentSearchEmbeddingFailed: AgentSearchOutcome: TypeAlias = AgentSearchHits | AgentSearchNotConfigured | AgentSearchEmbeddingFailed -class _SearchableSkill(BaseModel): +class _SearchableSkill(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") name: str = "" @@ -56,14 +57,14 @@ class _SearchableSkill(BaseModel): tags: tuple[str, ...] = () -class _SearchableCard(BaseModel): +class _SearchableCard(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") description: str = "" skills: tuple[_SearchableSkill, ...] = () -class AgentSearchResult(BaseModel): +class AgentSearchResult(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) agent_id: str diff --git a/litellm/proxy/analytics_endpoints/cache_activity.py b/litellm/proxy/analytics_endpoints/cache_activity.py index 5de3b610782..c860f3c8a88 100644 --- a/litellm/proxy/analytics_endpoints/cache_activity.py +++ b/litellm/proxy/analytics_endpoints/cache_activity.py @@ -4,9 +4,10 @@ from collections.abc import Sequence from datetime import datetime from typing import Final, Protocol -from pydantic import BaseModel, TypeAdapter +from pydantic import TypeAdapter from litellm.proxy._types import LiteLLMRoutes +from litellm.types.llms.base import LiteLLMBaseModel UNKNOWN_CALL_TYPE: Final = "Unknown" INFO_ROUTES_JSON: Final = json.dumps(LiteLLMRoutes.info_routes.value) @@ -25,7 +26,7 @@ class _SupportsRawQueryDb(Protocol): def db(self) -> _SupportsQueryRaw: ... -class CacheActivityGroup(BaseModel): +class CacheActivityGroup(LiteLLMBaseModel): call_type: str api_requests: int cache_hits: int @@ -34,7 +35,7 @@ class CacheActivityGroup(BaseModel): generated_completion_tokens: int -class CacheActivityTotals(BaseModel): +class CacheActivityTotals(LiteLLMBaseModel): api_requests: int cache_hits: int failed_requests: int @@ -42,19 +43,19 @@ class CacheActivityTotals(BaseModel): cache_hit_ratio: float -class CacheActivityFilterOptions(BaseModel): +class CacheActivityFilterOptions(LiteLLMBaseModel): key_aliases: list[str] models: list[str] -class CacheActivityErrorBucket(BaseModel): +class CacheActivityErrorBucket(LiteLLMBaseModel): call_type: str error_code: str error_class: str count: int -class CacheActivityResponse(BaseModel): +class CacheActivityResponse(LiteLLMBaseModel): groups: list[CacheActivityGroup] totals: CacheActivityTotals filter_options: CacheActivityFilterOptions @@ -131,11 +132,11 @@ MODEL_OPTIONS_SQL: Final = """ """ -class _KeyAliasRow(BaseModel): +class _KeyAliasRow(LiteLLMBaseModel): key_alias: str -class _ModelRow(BaseModel): +class _ModelRow(LiteLLMBaseModel): model: str diff --git a/litellm/proxy/anthropic_endpoints/gateway_endpoints.py b/litellm/proxy/anthropic_endpoints/gateway_endpoints.py index e84bb73b05b..48acfa67a28 100644 --- a/litellm/proxy/anthropic_endpoints/gateway_endpoints.py +++ b/litellm/proxy/anthropic_endpoints/gateway_endpoints.py @@ -24,7 +24,7 @@ from typing import Final from fastapi import APIRouter, Depends, Request, Response from fastapi.responses import JSONResponse -from pydantic import BaseModel, Field, TypeAdapter, ValidationError +from pydantic import Field, TypeAdapter, ValidationError from litellm._internal_context import with_service_target from litellm._logging import verbose_proxy_logger @@ -40,6 +40,7 @@ from litellm.proxy.auth.user_api_key_auth import user_api_key_auth from litellm.proxy.common_utils.http_parsing_utils import _safe_set_request_parsed_body from litellm.proxy.management_endpoints.sso_helper_utils import CLI_SSO_SESSIONS_TARGET from litellm.proxy.management_endpoints.ui_sso import CliSsoTeamDetail +from litellm.types.llms.base import LiteLLMBaseModel GATEWAY_PREFIX: Final = "/claude_code_gateway" _DEVICE_CODE_GRANT: Final = "urn:ietf:params:oauth:grant-type:device_code" @@ -52,7 +53,7 @@ _NO_SETTINGS: Final = MappingProxyType({}) _POST_ONLY: Final = ["POST"] -class _GatewaySessionData(BaseModel): +class _GatewaySessionData(LiteLLMBaseModel): user_id: str user_role: LitellmUserRoles models: list[str] = Field(default_factory=list) @@ -67,19 +68,19 @@ class _GatewayLogin: team: CliSsoTeamDetail -class _OAuthErrorBody(BaseModel): +class _OAuthErrorBody(LiteLLMBaseModel): error: str error_description: str | None = None -class _AuthorizationServerMetadata(BaseModel): +class _AuthorizationServerMetadata(LiteLLMBaseModel): issuer: str device_authorization_endpoint: str token_endpoint: str grant_types_supported: tuple[str, ...] -class _DeviceAuthorizationBody(BaseModel): +class _DeviceAuthorizationBody(LiteLLMBaseModel): device_code: str user_code: str verification_uri: str @@ -88,13 +89,13 @@ class _DeviceAuthorizationBody(BaseModel): interval: int -class _AccessTokenBody(BaseModel): +class _AccessTokenBody(LiteLLMBaseModel): access_token: str expires_in: int token_type: str = "Bearer" -class _ManagedSettingsBody(BaseModel): +class _ManagedSettingsBody(LiteLLMBaseModel): uuid: str checksum: str settings: dict[str, object] diff --git a/litellm/proxy/auth/fallback_budget.py b/litellm/proxy/auth/fallback_budget.py index e356f8acc7d..9029f9d6996 100644 --- a/litellm/proxy/auth/fallback_budget.py +++ b/litellm/proxy/auth/fallback_budget.py @@ -35,7 +35,7 @@ from collections.abc import Callable, Mapping from dataclasses import dataclass from typing import Final -from pydantic import BaseModel, ValidationError +from pydantic import ValidationError from litellm._logging import verbose_proxy_logger from litellm.proxy._types import UserAPIKeyAuth @@ -43,13 +43,14 @@ from litellm.proxy.auth.auth_checks import ( _is_model_cost_zero, # pyright: ignore[reportPrivateUsage] # the zero-cost predicate the auth-time budget checks use; no public equivalent ) from litellm.router import Router +from litellm.types.llms.base import LiteLLMBaseModel -class _RequestMetadata(BaseModel): +class _RequestMetadata(LiteLLMBaseModel): user_api_key_auth: UserAPIKeyAuth | None = None -class _FallbackBudgetSettings(BaseModel): +class _FallbackBudgetSettings(LiteLLMBaseModel): enforce_fallback_budget: bool = True diff --git a/litellm/proxy/auth/fallback_model_access.py b/litellm/proxy/auth/fallback_model_access.py index c601a5e415e..53807f076ea 100644 --- a/litellm/proxy/auth/fallback_model_access.py +++ b/litellm/proxy/auth/fallback_model_access.py @@ -12,19 +12,20 @@ from collections.abc import Callable, Mapping from dataclasses import dataclass from typing import Final -from pydantic import BaseModel, ValidationError +from pydantic import ValidationError from litellm._logging import verbose_proxy_logger from litellm.proxy._types import ProxyException, UserAPIKeyAuth from litellm.proxy.auth.auth_checks import can_key_call_resolved_model from litellm.router import Router +from litellm.types.llms.base import LiteLLMBaseModel -class _RequestMetadata(BaseModel): +class _RequestMetadata(LiteLLMBaseModel): user_api_key_auth: UserAPIKeyAuth | None = None -class _FallbackAccessSettings(BaseModel): +class _FallbackAccessSettings(LiteLLMBaseModel): enforce_fallback_model_access: bool = False diff --git a/litellm/proxy/auth/network.py b/litellm/proxy/auth/network.py index 4e8ab7512a7..230dde072ca 100644 --- a/litellm/proxy/auth/network.py +++ b/litellm/proxy/auth/network.py @@ -5,20 +5,21 @@ from collections.abc import Sequence from typing import Any, Final from fastapi import Request -from pydantic import BaseModel, Field +from pydantic import Field from litellm._logging import verbose_proxy_logger +from litellm.types.llms.base import LiteLLMBaseModel TrustedProxyNetwork = ipaddress.IPv4Network | ipaddress.IPv6Network -class NetworkContext(BaseModel): +class NetworkContext(LiteLLMBaseModel): client_ip: str | None = None host: str | None = None via_trusted_proxy: bool = False -class TrustedProxyConfig(BaseModel): +class TrustedProxyConfig(LiteLLMBaseModel): use_forwarded_for: bool = False trusted_proxy_cidrs: Sequence[str] = Field(default_factory=tuple) diff --git a/litellm/proxy/auth/resolvers/grants.py b/litellm/proxy/auth/resolvers/grants.py index cbfe21924ec..c66761a8459 100644 --- a/litellm/proxy/auth/resolvers/grants.py +++ b/litellm/proxy/auth/resolvers/grants.py @@ -14,7 +14,7 @@ from types import MappingProxyType from typing import TYPE_CHECKING, Final, NoReturn, Protocol, TypeAlias from fastapi import HTTPException, status -from pydantic import BaseModel, ValidationError +from pydantic import ValidationError from pydantic.main import IncEx from typing_extensions import assert_never @@ -32,6 +32,7 @@ from litellm.proxy.auth.auth_checks import ( get_team_object, get_user_object, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.auth.auth_checks import UserNotFoundError if TYPE_CHECKING: @@ -133,7 +134,7 @@ GrantOutcome: TypeAlias = ResolvedGrants | GrantDenial | LookupDegraded _MODELS_COLUMN: Final[Mapping[str, IncEx | bool]] = MappingProxyType({"models": True}) -class _UserModelColumn(BaseModel): +class _UserModelColumn(LiteLLMBaseModel): """``LiteLLM_UserTable.models`` is a bare ``list``; re-read it with the shape a token's ``models`` takes.""" models: tuple[str, ...] = () diff --git a/litellm/proxy/auth/resolvers/models.py b/litellm/proxy/auth/resolvers/models.py index 97e66b8fe67..6119bbee6d6 100644 --- a/litellm/proxy/auth/resolvers/models.py +++ b/litellm/proxy/auth/resolvers/models.py @@ -2,12 +2,13 @@ from __future__ import annotations from enum import Enum -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.auth.auth_method import AuthMethod from litellm.proxy.auth.network import NetworkContext from litellm.proxy.auth.roles import Role, TeamRole +from litellm.types.llms.base import LiteLLMBaseModel class PrincipalType(str, Enum): @@ -15,7 +16,7 @@ class PrincipalType(str, Enum): SERVICE_ACCOUNT = "service_account" -class UserIdentity(BaseModel): +class UserIdentity(LiteLLMBaseModel): id: str external_id: str | None = None user_name: str | None = None @@ -23,32 +24,32 @@ class UserIdentity(BaseModel): display_name: str | None = None -class OrganizationIdentity(BaseModel): +class OrganizationIdentity(LiteLLMBaseModel): id: str name: str | None = None -class TeamIdentity(BaseModel): +class TeamIdentity(LiteLLMBaseModel): id: str name: str | None = None role: TeamRole = TeamRole.MEMBER -class ProjectIdentity(BaseModel): +class ProjectIdentity(LiteLLMBaseModel): id: str name: str | None = None -class EndUserIdentity(BaseModel): +class EndUserIdentity(LiteLLMBaseModel): id: str -class CredentialRef(BaseModel): +class CredentialRef(LiteLLMBaseModel): key_id: str | None = None token_id: str | None = None -class Principal(BaseModel): +class Principal(LiteLLMBaseModel): """Normalized caller identity, resolved once per request at the auth seam. Frozen and constructed fresh per request, never cached or shared. The identity diff --git a/litellm/proxy/auth/team_grants.py b/litellm/proxy/auth/team_grants.py index 2029ee342ae..450a3ce456e 100644 --- a/litellm/proxy/auth/team_grants.py +++ b/litellm/proxy/auth/team_grants.py @@ -10,7 +10,7 @@ from collections.abc import Mapping, Sequence from types import MappingProxyType from typing import Annotated, Final -from pydantic import BaseModel, BeforeValidator, ConfigDict, TypeAdapter, ValidationError +from pydantic import BeforeValidator, ConfigDict, TypeAdapter, ValidationError from pydantic.main import IncEx from typing_extensions import ReadOnly, TypedDict @@ -20,6 +20,7 @@ from litellm.proxy._types import ( LiteLLM_TeamTable, Member, ) +from litellm.types.llms.base import LiteLLMBaseModel _MODEL_ALIASES_ADAPTER: Final = TypeAdapter(dict[str, str]) _JSON_COLUMNS: Final[Mapping[str, IncEx | bool]] = MappingProxyType( @@ -37,13 +38,13 @@ def _decode_model_aliases(value: object) -> object: return None -class TeamModelAliasTable(BaseModel): +class TeamModelAliasTable(LiteLLMBaseModel): model_config = ConfigDict(protected_namespaces=()) model_aliases: Annotated[Mapping[str, str] | None, BeforeValidator(_decode_model_aliases)] = None -class _TeamJsonColumns(BaseModel): +class _TeamJsonColumns(LiteLLMBaseModel): """The two loosely typed columns on ``LiteLLM_TeamTable``, re-read with the shape the badge needs.""" metadata: Mapping[str, object] | None = None diff --git a/litellm/proxy/batches_endpoints/litellm_executed_batches.py b/litellm/proxy/batches_endpoints/litellm_executed_batches.py index 7de170880ca..984aed71b1c 100644 --- a/litellm/proxy/batches_endpoints/litellm_executed_batches.py +++ b/litellm/proxy/batches_endpoints/litellm_executed_batches.py @@ -32,6 +32,7 @@ from litellm.proxy.openai_files_endpoints.common_utils import LITELLM_EXECUTED_B from litellm.proxy.openai_files_endpoints.storage_backend_service import StorageBackendFileService from litellm.proxy.utils import PrismaClient, ProxyLogging from litellm.repositories.managed_batch_repository import ManagedBatchRepository +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import LiteLLMBatchCreateRequest, OpenAIFileObject, OpenAIFilesPurpose from litellm.types.utils import LITELLM_EXECUTED_BATCH_PROVIDERS, ExtractedFileData, LiteLLMBatch, LlmProviders @@ -103,7 +104,7 @@ class _ResultLine(TypedDict): error: ReadOnly[_LineError | None] -class BatchInputLine(BaseModel): +class BatchInputLine(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True) custom_id: str diff --git a/litellm/proxy/client/cli/commands/agents.py b/litellm/proxy/client/cli/commands/agents.py index 28f74c7465e..579d020f936 100644 --- a/litellm/proxy/client/cli/commands/agents.py +++ b/litellm/proxy/client/cli/commands/agents.py @@ -13,7 +13,7 @@ from typing import Final, TypeAlias import click import requests -from pydantic import BaseModel, TypeAdapter, ValidationError +from pydantic import TypeAdapter, ValidationError from litellm.proxy.common_utils.codex_model_catalog import ( CODEX_BASE_INSTRUCTIONS_PATH, @@ -22,6 +22,7 @@ from litellm.proxy.common_utils.codex_model_catalog import ( CodexStockModel, codex_models_response_json, ) +from litellm.types.llms.base import LiteLLMBaseModel from .auth import CliContextObj, context_secret_vault, get_stored_api_key, login from .claude_settings import ClaudeSettingsError, install_statusline_script @@ -261,7 +262,7 @@ def agent_launch_args(command: str, base_url: str) -> list[str]: return builder(base_url) if builder else [] -class ListedModel(BaseModel): +class ListedModel(LiteLLMBaseModel): """The fields of a /v1/models entry that an OpenCode or Codex model entry is built from.""" id: str @@ -270,7 +271,7 @@ class ListedModel(BaseModel): max_output_tokens: int | None = None -class _ModelListing(BaseModel): +class _ModelListing(LiteLLMBaseModel): data: tuple[ListedModel, ...] @@ -318,29 +319,29 @@ def _fetch_model_listing( return listing.data -class _OpenCodeLimit(BaseModel): +class _OpenCodeLimit(LiteLLMBaseModel): context: int output: int -class _OpenCodeModel(BaseModel): +class _OpenCodeModel(LiteLLMBaseModel): name: str limit: _OpenCodeLimit | None = None -class _OpenCodeProviderOptions(BaseModel): +class _OpenCodeProviderOptions(LiteLLMBaseModel): baseURL: str apiKey: str -class _OpenCodeProvider(BaseModel): +class _OpenCodeProvider(LiteLLMBaseModel): npm: str name: str options: _OpenCodeProviderOptions models: Mapping[str, _OpenCodeModel] -class _OpenCodeConfig(BaseModel): +class _OpenCodeConfig(LiteLLMBaseModel): provider: Mapping[str, _OpenCodeProvider] diff --git a/litellm/proxy/client/cli/commands/autoroute/config.py b/litellm/proxy/client/cli/commands/autoroute/config.py index f8738af221e..28a57f71d08 100644 --- a/litellm/proxy/client/cli/commands/autoroute/config.py +++ b/litellm/proxy/client/cli/commands/autoroute/config.py @@ -1,7 +1,9 @@ from collections.abc import Mapping from typing import Final, Literal -from pydantic import BaseModel, ConfigDict, Field, JsonValue, TypeAdapter +from pydantic import ConfigDict, Field, JsonValue, TypeAdapter + +from litellm.types.llms.base import LiteLLMBaseModel TIER_NAMES: Final[tuple[str, ...]] = ("SIMPLE", "MEDIUM", "COMPLEX", "REASONING") AUTOROUTER_MODEL_NAME: Final = "autorouter" @@ -11,14 +13,14 @@ class ConfigGenerationError(Exception): """Raised when an AutorouteConfig references a model the discovery step didn't find.""" -class DiscoveredModel(BaseModel): +class DiscoveredModel(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) name: str mode: str = "chat" -class _RawModelListing(BaseModel): +class _RawModelListing(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") id: str @@ -45,12 +47,12 @@ def embedding_models(models: tuple[DiscoveredModel, ...]) -> tuple[DiscoveredMod return tuple(m for m in models if m.mode == "embedding") -class HeuristicClassifier(BaseModel): +class HeuristicClassifier(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) kind: Literal["heuristic"] = "heuristic" -class LLMClassifier(BaseModel): +class LLMClassifier(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) kind: Literal["llm"] = "llm" model: str @@ -60,12 +62,12 @@ class LLMClassifier(BaseModel): ClassifierChoice = HeuristicClassifier | LLMClassifier -class NoSemanticMatching(BaseModel): +class NoSemanticMatching(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) kind: Literal["none"] = "none" -class KeywordTierRule(BaseModel): +class KeywordTierRule(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) keywords: tuple[str, ...] tier: str @@ -81,7 +83,7 @@ DEFAULT_KEYWORD_TIER_RULES: Final[tuple[KeywordTierRule, ...]] = ( ) -class SemanticMatching(BaseModel): +class SemanticMatching(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) kind: Literal["semantic"] = "semantic" embedding_model: str @@ -92,7 +94,7 @@ class SemanticMatching(BaseModel): SemanticMatchingChoice = NoSemanticMatching | SemanticMatching -class AutorouteConfig(BaseModel): +class AutorouteConfig(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) base_url: str diff --git a/litellm/proxy/client/cli/commands/claude_settings.py b/litellm/proxy/client/cli/commands/claude_settings.py index 0c8b2ef9dcf..cdceb91712b 100644 --- a/litellm/proxy/client/cli/commands/claude_settings.py +++ b/litellm/proxy/client/cli/commands/claude_settings.py @@ -25,7 +25,7 @@ from typing import Final, TypeAlias import click from filelock import FileLock from packaging.version import InvalidVersion, Version -from pydantic import BaseModel, ConfigDict, JsonValue, TypeAdapter, ValidationError +from pydantic import ConfigDict, JsonValue, TypeAdapter, ValidationError from litellm._version import version as litellm_version from litellm.litellm_core_utils.private_json import ( @@ -35,6 +35,7 @@ from litellm.litellm_core_utils.private_json import ( stage_private_json, write_private_bytes, ) +from litellm.types.llms.base import LiteLLMBaseModel from . import statusline_script from .cmd_quoting import quote_for_cmd @@ -159,7 +160,7 @@ class StartOn: ModelChoice: TypeAlias = KeepModel | UnpinModel | StartOn -class OwnedValue(BaseModel): +class OwnedValue(LiteLLMBaseModel): """What one key held at a moment in time; `present=False` is an absent key, not a null one.""" model_config = ConfigDict(frozen=True) @@ -168,7 +169,7 @@ class OwnedValue(BaseModel): value: JsonValue = None -class ConfigureReceipt(BaseModel): +class ConfigureReceipt(LiteLLMBaseModel): """What `lite configure claude` found and what it owns, keyed by dotted path (`env.X` or a top-level key). Ownership moves only by a write: `written` fingerprints the keys some configure changed, at the diff --git a/litellm/proxy/client/cli/commands/codex_settings.py b/litellm/proxy/client/cli/commands/codex_settings.py index 5b01c31683a..ca133d3f1e5 100644 --- a/litellm/proxy/client/cli/commands/codex_settings.py +++ b/litellm/proxy/client/cli/commands/codex_settings.py @@ -10,7 +10,7 @@ from types import MappingProxyType from typing import Final, Literal, TypeAlias import tomlkit -from pydantic import BaseModel, ConfigDict, ValidationError +from pydantic import ConfigDict, ValidationError from tomlkit.container import OutOfOrderTableProxy from tomlkit.exceptions import TOMLKitError from tomlkit.items import InlineTable, Table @@ -23,6 +23,7 @@ from litellm.litellm_core_utils.private_json import ( stage_private_bytes, stage_private_json, ) +from litellm.types.llms.base import LiteLLMBaseModel from .agents import CODEX_PROXY_PROVIDER, codex_proxy_provider @@ -37,7 +38,7 @@ class CodexSettingsError(Exception): pass -class _Receipt(BaseModel): +class _Receipt(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="forbid") version: Literal[1] = 1 diff --git a/litellm/proxy/client/cli/commands/configure.py b/litellm/proxy/client/cli/commands/configure.py index ea24a644084..45c79ccf014 100644 --- a/litellm/proxy/client/cli/commands/configure.py +++ b/litellm/proxy/client/cli/commands/configure.py @@ -6,7 +6,8 @@ from typing import Final import click from InquirerPy import inquirer -from pydantic import BaseModel + +from litellm.types.llms.base import LiteLLMBaseModel from .auth import CliContextObj from .claude_settings import ( @@ -38,7 +39,7 @@ from .configure_setup import ( ) -class _ConnectionOptions(BaseModel): +class _ConnectionOptions(LiteLLMBaseModel): api_key: str | None = None gateway_url: str | None = None @@ -253,7 +254,7 @@ def unconfigure_group(ctx: click.Context, forget: bool) -> None: _disconnect(target, forget) -class _UnconfigureOptions(BaseModel): +class _UnconfigureOptions(LiteLLMBaseModel): forget: bool = False diff --git a/litellm/proxy/client/cli/commands/configure_profiles.py b/litellm/proxy/client/cli/commands/configure_profiles.py index 8d84dfc2146..3ae651ff6db 100644 --- a/litellm/proxy/client/cli/commands/configure_profiles.py +++ b/litellm/proxy/client/cli/commands/configure_profiles.py @@ -9,7 +9,7 @@ from typing import Final, Literal, TypeAlias import click from filelock import FileLock, Timeout -from pydantic import BaseModel, ConfigDict, Field, ValidationError, field_validator +from pydantic import ConfigDict, Field, ValidationError, field_validator from litellm.litellm_core_utils.private_json import ( commit_staged_json, @@ -17,6 +17,7 @@ from litellm.litellm_core_utils.private_json import ( ensure_private_dir, stage_private_json, ) +from litellm.types.llms.base import LiteLLMBaseModel from .agents import codex_config_path from .claude_settings import claude_settings_path, configure_state_path @@ -27,7 +28,7 @@ Target: TypeAlias = Literal["claude", "codex"] TARGETS: Final[tuple[Target, ...]] = ("claude", "codex") -class SavedSetup(BaseModel): +class SavedSetup(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="forbid", strict=True) version: Literal[1] = 1 diff --git a/litellm/proxy/client/cli/commands/configure_setup.py b/litellm/proxy/client/cli/commands/configure_setup.py index b988b7e95d2..7a262650cc2 100644 --- a/litellm/proxy/client/cli/commands/configure_setup.py +++ b/litellm/proxy/client/cli/commands/configure_setup.py @@ -12,13 +12,14 @@ import click import requests from InquirerPy import inquirer from InquirerPy.base.control import Choice -from pydantic import BaseModel, TypeAdapter, ValidationError +from pydantic import TypeAdapter, ValidationError from litellm.proxy.common_utils.model_listing_utils import ( CLAUDE_CODE_CLIENT, CLAUDE_CODE_PICKER_PATTERN, GATEWAY_CLIENT_HEADER, ) +from litellm.types.llms.base import LiteLLMBaseModel from .agents import codex_config_path from .claude_settings import ( @@ -68,7 +69,7 @@ _TARGET_SELECTION: Final = TypeAdapter(tuple[Target, ...]) _MODEL_SELECTION: Final = TypeAdapter(str) -class ConnectionSettings(BaseModel): +class ConnectionSettings(LiteLLMBaseModel): base_url: str base_url_explicit: bool = False api_key: str | None = None diff --git a/litellm/proxy/client/cli/commands/debug.py b/litellm/proxy/client/cli/commands/debug.py index 2aca60ca810..3db3662b021 100644 --- a/litellm/proxy/client/cli/commands/debug.py +++ b/litellm/proxy/client/cli/commands/debug.py @@ -18,7 +18,9 @@ from typing import Final import click import requests -from pydantic import BaseModel, ConfigDict, Field, JsonValue, TypeAdapter, ValidationError, field_validator +from pydantic import ConfigDict, Field, JsonValue, TypeAdapter, ValidationError, field_validator + +from litellm.types.llms.base import LiteLLMBaseModel from ...http_client import HTTPClient from ._cli_context import cli_context_values @@ -44,7 +46,7 @@ class DebugFailure: message: str -class ErrorInformation(BaseModel): +class ErrorInformation(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") error_code: str | None = None @@ -53,14 +55,14 @@ class ErrorInformation(BaseModel): llm_provider: str | None = None -class SpendLogMetadata(BaseModel): +class SpendLogMetadata(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") status: str | None = None error_information: ErrorInformation | None = None -class SpendLogRow(BaseModel): +class SpendLogRow(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore", populate_by_name=True) request_id: str @@ -96,7 +98,7 @@ class SpendLogRow(BaseModel): return self.metadata.error_information -class SessionLogsPage(BaseModel): +class SessionLogsPage(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") data: tuple[SpendLogRow, ...] @@ -104,7 +106,7 @@ class SessionLogsPage(BaseModel): total_pages: int -class RequestResponsePayload(BaseModel): +class RequestResponsePayload(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") proxy_server_request: JsonValue = None diff --git a/litellm/proxy/client/cli/commands/pi.py b/litellm/proxy/client/cli/commands/pi.py index 5966a11485d..22c9755ab8e 100644 --- a/litellm/proxy/client/cli/commands/pi.py +++ b/litellm/proxy/client/cli/commands/pi.py @@ -16,9 +16,11 @@ from types import MappingProxyType from typing import Annotated, Final import requests -from pydantic import BaseModel, ConfigDict, JsonValue, TypeAdapter, ValidationError, model_validator +from pydantic import ConfigDict, JsonValue, TypeAdapter, ValidationError, model_validator from pydantic.types import StringConstraints +from litellm.types.llms.base import LiteLLMBaseModel + PI_CONFIG_DIR_ENV: Final = "PI_CODING_AGENT_DIR" PI_PROVIDER_NAME: Final = "litellm" LITELLM_PROXY_API_KEY_ENV: Final = "LITELLM_PROXY_API_KEY" @@ -55,14 +57,14 @@ class ModelLimits: _NonEmptyString = Annotated[str, StringConstraints(min_length=1)] -class ListedModel(BaseModel): +class ListedModel(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) id: _NonEmptyString source_model: _NonEmptyString | None = None -class _ModelList(BaseModel): +class _ModelList(LiteLLMBaseModel): data: tuple[ListedModel, ...] @model_validator(mode="after") @@ -73,13 +75,13 @@ class _ModelList(BaseModel): return self -class _ModelGroup(BaseModel): +class _ModelGroup(LiteLLMBaseModel): model_group: str max_input_tokens: float | None = None max_output_tokens: float | None = None -class _ModelGroupList(BaseModel): +class _ModelGroupList(LiteLLMBaseModel): data: tuple[_ModelGroup, ...] diff --git a/litellm/proxy/client/cli/commands/pkce_login.py b/litellm/proxy/client/cli/commands/pkce_login.py index 93f5cfea21b..7cf846bdf9a 100644 --- a/litellm/proxy/client/cli/commands/pkce_login.py +++ b/litellm/proxy/client/cli/commands/pkce_login.py @@ -20,10 +20,11 @@ from typing import TYPE_CHECKING, Final, Literal, Protocol from urllib.parse import parse_qs, urlencode, urlparse import requests -from pydantic import BaseModel, ConfigDict, Field, TypeAdapter, ValidationError +from pydantic import ConfigDict, Field, TypeAdapter, ValidationError from typing_extensions import ReadOnly, TypedDict from litellm.litellm_core_utils.cli_token_utils import CLI_TOKEN_FRESHNESS_BUFFER_SECONDS +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: from .auth import CliTokenData @@ -35,7 +36,7 @@ _HTTP_TIMEOUT_SECONDS: Final = 15 _CLIENT_NAME: Final = "litellm-cli" -class CliAuthContract(BaseModel): +class CliAuthContract(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) contract_version: Literal[1] @@ -48,13 +49,13 @@ class CliAuthContract(BaseModel): code_challenge_methods_supported: tuple[str, ...] -class _RegisteredClient(BaseModel): +class _RegisteredClient(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) client_id: str = Field(min_length=1) -class _TokenResponse(BaseModel): +class _TokenResponse(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) access_token: str = Field(min_length=1) diff --git a/litellm/proxy/common_utils/cache_aware_routing.py b/litellm/proxy/common_utils/cache_aware_routing.py index 436482a3421..d0685218c87 100644 --- a/litellm/proxy/common_utils/cache_aware_routing.py +++ b/litellm/proxy/common_utils/cache_aware_routing.py @@ -8,7 +8,7 @@ from itertools import chain from types import MappingProxyType from typing import TYPE_CHECKING, Final -from pydantic import BaseModel, ConfigDict, JsonValue, TypeAdapter, ValidationError +from pydantic import ConfigDict, JsonValue, TypeAdapter, ValidationError from litellm._logging import verbose_router_logger from litellm.caching.dual_cache import DualCache @@ -17,6 +17,7 @@ from litellm.llms.anthropic.cache_aware_routing import AnthropicCacheRouting, To from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.auth.auth_checks import can_key_call_resolved_model from litellm.router_strategy.complexity_router.config import ComplexityRouterConfig +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.router import Deployment, PreRoutingHookResponse from litellm.types.utils import StandardLoggingRoutingDecision @@ -45,14 +46,14 @@ _CLASSIFIED_CAUSES: Final = frozenset( ) -class _ProxyRequest(BaseModel): +class _ProxyRequest(LiteLLMBaseModel): model_config = ConfigDict(strict=True) url: str body: Mapping[str, JsonValue] headers: Mapping[str, str] -class _CallerSettings(BaseModel): +class _CallerSettings(LiteLLMBaseModel): config: Mapping[str, object] | None = None diff --git a/litellm/proxy/common_utils/codex_model_catalog.py b/litellm/proxy/common_utils/codex_model_catalog.py index 177ce6ae9c5..115b31930dc 100644 --- a/litellm/proxy/common_utils/codex_model_catalog.py +++ b/litellm/proxy/common_utils/codex_model_catalog.py @@ -26,9 +26,10 @@ from pathlib import Path from types import MappingProxyType, NoneType from typing import TYPE_CHECKING, Annotated, Final, Literal -from pydantic import BaseModel, ConfigDict, StringConstraints, TypeAdapter, ValidationError +from pydantic import ConfigDict, StringConstraints, TypeAdapter, ValidationError from litellm._logging import verbose_proxy_logger +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: from litellm.router import Router @@ -44,7 +45,7 @@ _BODY_PREFIX: Final = '{"models":[' _BODY_SUFFIX: Final = "]}" -class CodexServiceTier(BaseModel): +class CodexServiceTier(LiteLLMBaseModel): """A `ModelServiceTier` as Codex reads it: the slash command is `name` lowercased, and toggling it sends `id` as the request's `service_tier`.""" @@ -55,7 +56,7 @@ class CodexServiceTier(BaseModel): description: str -class _ConfiguredTier(BaseModel): +class _ConfiguredTier(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="forbid") id: _TierId @@ -66,12 +67,12 @@ class _ConfiguredTier(BaseModel): _CONFIGURED_TIERS: Final = TypeAdapter(tuple[_TierId | _ConfiguredTier, ...]) -class CodexTruncationPolicy(BaseModel): +class CodexTruncationPolicy(LiteLLMBaseModel): mode: Literal["bytes"] = "bytes" limit: int = 10_000 -class CodexFallbackModel(BaseModel): +class CodexFallbackModel(LiteLLMBaseModel): """One `ModelInfo` entry of a Codex model catalog for a model Codex does not know. Every field that some Codex release since `model_catalog_json` appeared @@ -103,13 +104,13 @@ class CodexFallbackModel(BaseModel): base_instructions: str -class CodexStockUpgrade(BaseModel): +class CodexStockUpgrade(LiteLLMBaseModel): model_config = ConfigDict(extra="allow") model: str -class CodexStockModel(BaseModel): +class CodexStockModel(LiteLLMBaseModel): """One `ModelInfo` entry as Codex ships it or prints it from `codex debug models`. Only the fields the listing rewrites are named; everything else that release @@ -129,7 +130,7 @@ class CodexStockModel(BaseModel): default_service_tier: str | None = None -class CodexStockCatalog(BaseModel): +class CodexStockCatalog(LiteLLMBaseModel): models: tuple[CodexStockModel, ...] diff --git a/litellm/proxy/common_utils/periodic_reload_schedule.py b/litellm/proxy/common_utils/periodic_reload_schedule.py index c3228ee8ac0..4bead482905 100644 --- a/litellm/proxy/common_utils/periodic_reload_schedule.py +++ b/litellm/proxy/common_utils/periodic_reload_schedule.py @@ -25,12 +25,13 @@ from typing import ( cast, # noqa: TID251 # prisma table access is untyped (PrismaWrapper.__getattr__) ) -from pydantic import BaseModel, ConfigDict, ValidationError +from pydantic import ConfigDict, ValidationError from litellm._logging import verbose_proxy_logger from litellm.litellm_core_utils.safe_json_dumps import safe_dumps from litellm.proxy.utils import PrismaClient, evict_config_param from litellm.repositories.config_repository import ConfigRepository +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: from prisma.models import LiteLLM_Config @@ -80,7 +81,7 @@ class ReloadScheduleStatus(TypedDict): next_run: str | None -class _IntervalConfig(BaseModel): +class _IntervalConfig(LiteLLMBaseModel): model_config = ConfigDict(strict=True) interval_hours: int | None = None diff --git a/litellm/proxy/common_utils/responses_stream_errors.py b/litellm/proxy/common_utils/responses_stream_errors.py index 25b83a5ba34..723cd88aad0 100644 --- a/litellm/proxy/common_utils/responses_stream_errors.py +++ b/litellm/proxy/common_utils/responses_stream_errors.py @@ -9,10 +9,11 @@ from pydantic import BaseModel, ConfigDict, field_validator from litellm._logging import redact_internal_details_from_client_message from litellm._uuid import uuid from litellm.exceptions import MidStreamFallbackError +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import ResponseFailedEvent, ResponsesAPIResponse, ResponsesAPIStreamEvents -class _ResponseIdentity(BaseModel): +class _ResponseIdentity(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, from_attributes=True) id: str | None = None @@ -20,7 +21,7 @@ class _ResponseIdentity(BaseModel): created_at: int | None = None -class _StreamEvent(BaseModel): +class _StreamEvent(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, from_attributes=True) type: str | None = None @@ -28,7 +29,7 @@ class _StreamEvent(BaseModel): response: _ResponseIdentity | None = None -class _FailureDetails(BaseModel): +class _FailureDetails(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, from_attributes=True) message: str | None = None diff --git a/litellm/proxy/common_utils/semantic_text_index.py b/litellm/proxy/common_utils/semantic_text_index.py index 030958706cf..7450ef2b509 100644 --- a/litellm/proxy/common_utils/semantic_text_index.py +++ b/litellm/proxy/common_utils/semantic_text_index.py @@ -11,9 +11,10 @@ from typing import TYPE_CHECKING, Final, Protocol, TypeAlias from fastapi import HTTPException from openai import OpenAIError -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict from litellm.exceptions import BudgetExceededError +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: from litellm.proxy._types import UserAPIKeyAuth @@ -35,19 +36,19 @@ class EmbeddingFailed: reason: str -class _EmbeddingItem(BaseModel): +class _EmbeddingItem(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") embedding: tuple[float, ...] -class _EmbeddingData(BaseModel): +class _EmbeddingData(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") data: tuple[_EmbeddingItem, ...] -class _EmbeddingRequest(BaseModel): +class _EmbeddingRequest(LiteLLMBaseModel): """The /embeddings-shaped request as the pre-call hooks (rate limits, budgets, guardrails) hand it back.""" model_config = ConfigDict(frozen=True, extra="ignore") diff --git a/litellm/proxy/common_utils/swagger_utils.py b/litellm/proxy/common_utils/swagger_utils.py index 83480bf161d..c2a53a37212 100644 --- a/litellm/proxy/common_utils/swagger_utils.py +++ b/litellm/proxy/common_utils/swagger_utils.py @@ -1,12 +1,13 @@ import inspect from typing import Any, Final -from pydantic import BaseModel, Field +from pydantic import Field from litellm.exceptions import LITELLM_EXCEPTION_TYPES +from litellm.types.llms.base import LiteLLMBaseModel -class ErrorResponse(BaseModel): +class ErrorResponse(LiteLLMBaseModel): detail: dict[str, Any] = Field( ..., example={ diff --git a/litellm/proxy/common_utils/timezone_utils.py b/litellm/proxy/common_utils/timezone_utils.py index 99e89210e43..f7907675fb0 100644 --- a/litellm/proxy/common_utils/timezone_utils.py +++ b/litellm/proxy/common_utils/timezone_utils.py @@ -1,12 +1,13 @@ from datetime import datetime, time, timezone -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict import litellm from litellm.litellm_core_utils.duration_parser import get_next_standardized_reset_time +from litellm.types.llms.base import LiteLLMBaseModel -class BudgetResetSettings(BaseModel): +class BudgetResetSettings(LiteLLMBaseModel): """Immutable, validated settings that govern when budgets reset. Parsed once from `litellm_settings` and injected into consumers (the reset diff --git a/litellm/proxy/db/baseline_accounting.py b/litellm/proxy/db/baseline_accounting.py index 625f5d03125..b21b7c8a2b9 100644 --- a/litellm/proxy/db/baseline_accounting.py +++ b/litellm/proxy/db/baseline_accounting.py @@ -35,19 +35,20 @@ from litellm.proxy.spend_tracking.baseline_accounting import ( advance_baseline_history, ) from litellm.proxy.spend_tracking.savings import BaselineCosts, BaselineCostSnapshot, price_baseline_comparison +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: from litellm.proxy.utils import PrismaClient -class DailyBaselineTarget(BaseModel): +class DailyBaselineTarget(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True, strict=True) entity: DailySpendEntity entity_id: str | None -class DailyBaselineAttribution(BaseModel): +class DailyBaselineAttribution(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True, strict=True) date: str @@ -77,7 +78,7 @@ class DailyBaselineAttribution(BaseModel): ) -class BaselineAccountingRecord(BaseModel): +class BaselineAccountingRecord(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True, strict=True) scope: str = Field(pattern=r"^autorouter-baseline:v3:[a-f0-9]{64}$") @@ -110,7 +111,7 @@ class BaselineAccountingRecord(BaseModel): return self -class BaselinePublication(BaseModel): +class BaselinePublication(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True, strict=True) version: Literal[3] = 3 @@ -154,7 +155,7 @@ def baseline_publication( ) -class _Comparison(BaseModel): +class _Comparison(LiteLLMBaseModel): revision: int published_revision: int initial_equivalent: bool @@ -162,14 +163,14 @@ class _Comparison(BaseModel): history: str | None -class _StoredRecord(BaseModel): +class _StoredRecord(LiteLLMBaseModel): data: str publication: str | None conflicted: bool started_at: float -class _Change(BaseModel): +class _Change(LiteLLMBaseModel): request_id: str publication: BaselinePublication api_key: str @@ -618,7 +619,7 @@ class BaselineAccountingStore: return "unavailable" -class _Scope(BaseModel): +class _Scope(LiteLLMBaseModel): scope: str diff --git a/litellm/proxy/db/db_transaction_queue/spend_log_cleanup.py b/litellm/proxy/db/db_transaction_queue/spend_log_cleanup.py index 4ff6d926a99..82ac7828c39 100644 --- a/litellm/proxy/db/db_transaction_queue/spend_log_cleanup.py +++ b/litellm/proxy/db/db_transaction_queue/spend_log_cleanup.py @@ -5,7 +5,7 @@ from dataclasses import dataclass from datetime import datetime, timedelta, timezone from typing import Final, Literal, TypeAlias -from pydantic import BaseModel, TypeAdapter +from pydantic import TypeAdapter from litellm._logging import verbose_proxy_logger from litellm.caching import RedisCache @@ -30,6 +30,7 @@ from litellm.proxy.db.db_transaction_queue.spend_logs_partition_manager import ( SpendLogsPartitionManager, ) from litellm.proxy.utils import PrismaClient +from litellm.types.llms.base import LiteLLMBaseModel StopReason: TypeAlias = Literal["exhausted", "budget_exhausted", "batch_cap_reached", "aborted"] @@ -76,7 +77,7 @@ def _record_run_batch(rows_deleted: int) -> None: progress.record_batch(rows_deleted) -class _RemainingRow(BaseModel): +class _RemainingRow(LiteLLMBaseModel): """One row of the capped outstanding-rows probe, validated out of prisma's untyped result.""" remaining: int diff --git a/litellm/proxy/db/health_check_latest.py b/litellm/proxy/db/health_check_latest.py index a825a23841e..9deb7de4ca5 100644 --- a/litellm/proxy/db/health_check_latest.py +++ b/litellm/proxy/db/health_check_latest.py @@ -14,10 +14,11 @@ from collections.abc import Sequence from datetime import datetime, timezone from typing import TYPE_CHECKING, Final -from pydantic import BaseModel, ConfigDict, JsonValue, TypeAdapter, field_validator +from pydantic import ConfigDict, JsonValue, TypeAdapter, field_validator from litellm._logging import verbose_proxy_logger from litellm.proxy.db.db_span import db_span +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: from litellm.proxy.utils import PrismaClient @@ -44,7 +45,7 @@ ORDER BY "model_id" ASC, "model_name" ASC, "checked_at" DESC """ -class LatestHealthCheckRow(BaseModel): +class LatestHealthCheckRow(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, protected_namespaces=()) health_check_id: str diff --git a/litellm/proxy/db/token_auth.py b/litellm/proxy/db/token_auth.py index 32c83c4f404..1875158f2b1 100644 --- a/litellm/proxy/db/token_auth.py +++ b/litellm/proxy/db/token_auth.py @@ -17,10 +17,10 @@ from dataclasses import dataclass from datetime import datetime, timedelta, timezone from typing import Final, TypeAlias -from pydantic import BaseModel from typing_extensions import assert_never from litellm._logging import verbose_proxy_logger +from litellm.types.llms.base import LiteLLMBaseModel IAM_TOKEN_DB_AUTH_ENV_VAR: Final = "IAM_TOKEN_DB_AUTH" AZURE_POSTGRESQL_AUTH_ENV_VAR: Final = "AZURE_POSTGRESQL_AUTH" @@ -217,7 +217,7 @@ def _parse_rds_token_expiration(token: str) -> datetime | None: return None -class _EntraAccessTokenClaims(BaseModel): +class _EntraAccessTokenClaims(LiteLLMBaseModel): exp: int diff --git a/litellm/proxy/guardrails/guardrail_endpoints.py b/litellm/proxy/guardrails/guardrail_endpoints.py index 4195f319f16..c43c59f11b8 100644 --- a/litellm/proxy/guardrails/guardrail_endpoints.py +++ b/litellm/proxy/guardrails/guardrail_endpoints.py @@ -65,6 +65,7 @@ from litellm.types.guardrails import ( SupportedGuardrailIntegrations, ToolPermissionGuardrailConfigModel, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.guardrails.guardrail_hooks.hide_secrets import ( HideSecretsGuardrailConfigModel, ) @@ -342,7 +343,7 @@ async def list_guardrails_v2( raise HTTPException(status_code=500, detail=str(e)) -class CreateGuardrailRequest(BaseModel): +class CreateGuardrailRequest(LiteLLMBaseModel): guardrail: Guardrail @@ -453,7 +454,7 @@ async def create_guardrail( raise HTTPException(status_code=500, detail=str(e)) -class UpdateGuardrailRequest(BaseModel): +class UpdateGuardrailRequest(LiteLLMBaseModel): guardrail: Guardrail @@ -662,7 +663,7 @@ async def delete_guardrail( GENERIC_GUARDRAIL_API: Final = "generic_guardrail_api" -class RegisterGuardrailRequest(BaseModel): +class RegisterGuardrailRequest(LiteLLMBaseModel): """Request body for POST /guardrails/register. Follows Generic Guardrail API config.""" guardrail_name: str @@ -674,21 +675,21 @@ class RegisterGuardrailRequest(BaseModel): return dict(self.litellm_params) -class RegisterGuardrailResponse(BaseModel): +class RegisterGuardrailResponse(LiteLLMBaseModel): guardrail_id: str guardrail_name: str status: str submitted_at: datetime | None = None -class GuardrailSubmissionSummary(BaseModel): +class GuardrailSubmissionSummary(LiteLLMBaseModel): total: int pending_review: int active: int rejected: int -class GuardrailSubmissionItem(BaseModel): +class GuardrailSubmissionItem(LiteLLMBaseModel): guardrail_id: str guardrail_name: str status: str # pending_review | active | rejected @@ -706,7 +707,7 @@ class GuardrailSubmissionItem(BaseModel): updated_at: datetime | None = None -class ListGuardrailSubmissionsResponse(BaseModel): +class ListGuardrailSubmissionsResponse(LiteLLMBaseModel): submissions: list[GuardrailSubmissionItem] summary: GuardrailSubmissionSummary @@ -2028,7 +2029,7 @@ async def get_provider_specific_params(): return provider_params -class TestCustomCodeGuardrailRequest(BaseModel): +class TestCustomCodeGuardrailRequest(LiteLLMBaseModel): """Request model for testing custom code guardrails.""" custom_code: str @@ -2044,7 +2045,7 @@ class TestCustomCodeGuardrailRequest(BaseModel): """Optional mock request_data (model, user_id, team_id, metadata, etc.).""" -class TestCustomCodeGuardrailResponse(BaseModel): +class TestCustomCodeGuardrailResponse(LiteLLMBaseModel): """Response model for testing custom code guardrails.""" success: bool diff --git a/litellm/proxy/guardrails/guardrail_hooks/agent_365/agent_365.py b/litellm/proxy/guardrails/guardrail_hooks/agent_365/agent_365.py index c683e1f2c5d..ac0a6911184 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/agent_365/agent_365.py +++ b/litellm/proxy/guardrails/guardrail_hooks/agent_365/agent_365.py @@ -19,7 +19,7 @@ from typing import TYPE_CHECKING, ClassVar, Final, Literal, NoReturn import httpx from fastapi import HTTPException -from pydantic import BaseModel, ConfigDict, Field, TypeAdapter, ValidationError +from pydantic import ConfigDict, Field, TypeAdapter, ValidationError from typing_extensions import ReadOnly, TypedDict from litellm._logging import verbose_proxy_logger @@ -35,6 +35,7 @@ from litellm.llms.custom_httpx.http_handler import ( httpxSpecialProvider, ) from litellm.types.guardrails import GuardrailEventHooks +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.guardrails.guardrail_hooks.agent_365 import ( AGENT_365_PROD_API_BASE, AGENT_365_PROD_RESOURCE_APP_ID, @@ -108,7 +109,7 @@ class _EvaluateResponse(TypedDict, total=False): correlationId: ReadOnly[str] -class _ToolReference(BaseModel): +class _ToolReference(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) name: str diff --git a/litellm/proxy/guardrails/guardrail_hooks/conduct/conduct.py b/litellm/proxy/guardrails/guardrail_hooks/conduct/conduct.py index c87f8c016b1..077255017f4 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/conduct/conduct.py +++ b/litellm/proxy/guardrails/guardrail_hooks/conduct/conduct.py @@ -12,9 +12,10 @@ from functools import partial from types import MappingProxyType from typing import TYPE_CHECKING, Final, Literal, Protocol -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict from litellm.integrations.custom_guardrail import CustomGuardrail, log_guardrail_information +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import ChatCompletionUserMessage from litellm.types.proxy.guardrails.guardrail_hooks.conduct import ConductGuardrailConfigModel @@ -60,7 +61,7 @@ def decision_status(decision: ConductDecision) -> GuardrailStatus: return "guardrail_flagged" if decision.verdict in FLAGGED_VERDICTS else "success" -class ConductVerdict(BaseModel): +class ConductVerdict(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) verdict: str diff --git a/litellm/proxy/guardrails/guardrail_hooks/crowdstrike_aidr/crowdstrike_aidr.py b/litellm/proxy/guardrails/guardrail_hooks/crowdstrike_aidr/crowdstrike_aidr.py index 578825d971e..15803c9a0cf 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/crowdstrike_aidr/crowdstrike_aidr.py +++ b/litellm/proxy/guardrails/guardrail_hooks/crowdstrike_aidr/crowdstrike_aidr.py @@ -5,7 +5,7 @@ from collections.abc import Mapping, Sequence from typing import TYPE_CHECKING, Annotated, Final, Literal, NamedTuple, Optional, cast from fastapi import HTTPException -from pydantic import BaseModel, ConfigDict, Field, ValidationError +from pydantic import ConfigDict, Field, ValidationError from typing_extensions import override from litellm._logging import verbose_proxy_logger @@ -26,6 +26,7 @@ from litellm.proxy.common_utils.callback_utils import ( add_guardrail_to_applied_guardrails_header, ) from litellm.types.guardrails import GuardrailEventHooks, LitellmParams +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import AllMessageValues, OpenAIChatCompletionToolParam from litellm.types.proxy.guardrails.guardrail_hooks.crowdstrike_aidr import ( CrowdStrikeAIDRGuardrailConfigModelOptionalParams, @@ -41,18 +42,18 @@ class CrowdStrikeAIDRGuardrailMissingSecrets(Exception): """Custom exception for missing CrowdStrike AIDR secrets.""" -class _TextContentPart(BaseModel): +class _TextContentPart(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid") type: Literal["text"] = "text" text: str -class _ImageUrl(BaseModel): +class _ImageUrl(LiteLLMBaseModel): url: str -class _ImageUrlContentPart(BaseModel): +class _ImageUrlContentPart(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid") type: Literal["image_url"] = "image_url" @@ -62,17 +63,17 @@ class _ImageUrlContentPart(BaseModel): _ContentPart = Annotated[_TextContentPart | _ImageUrlContentPart, Field(discriminator="type")] -class _Message(BaseModel): +class _Message(LiteLLMBaseModel): role: str content: str | list[_ContentPart] | None = None -class _GuardInput(BaseModel): +class _GuardInput(LiteLLMBaseModel): messages: list[_Message] tools: Sequence[OpenAIChatCompletionToolParam] | None = None -class _GuardChatCompletionsResult(BaseModel): +class _GuardChatCompletionsResult(LiteLLMBaseModel): guard_output: _GuardInput | None = None """Updated structured prompt.""" blocked: bool | None = None @@ -83,7 +84,7 @@ class _GuardChatCompletionsResult(BaseModel): """Result of the policy analyzing and input prompt.""" -class _GuardChatCompletionsResponse(BaseModel): +class _GuardChatCompletionsResponse(LiteLLMBaseModel): result: _GuardChatCompletionsResult | None = None diff --git a/litellm/proxy/guardrails/guardrail_hooks/llm_as_a_judge/__init__.py b/litellm/proxy/guardrails/guardrail_hooks/llm_as_a_judge/__init__.py index efec15144b8..5085181639f 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/llm_as_a_judge/__init__.py +++ b/litellm/proxy/guardrails/guardrail_hooks/llm_as_a_judge/__init__.py @@ -6,7 +6,7 @@ from types import MappingProxyType from typing import TYPE_CHECKING, Final, Generic, Literal, Optional, TypeVar from fastapi import HTTPException -from pydantic import BaseModel, ConfigDict, ValidationError +from pydantic import ConfigDict, ValidationError from typing_extensions import NotRequired, ReadOnly, TypedDict, Unpack import litellm @@ -21,6 +21,7 @@ from litellm.litellm_core_utils.llm_judge import ( ) from litellm.litellm_core_utils.prompt_templates.common_utils import get_last_user_message from litellm.types.guardrails import GuardrailEventHooks, Mode, SupportedGuardrailIntegrations +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import LLM_AS_A_JUDGE_GUARDRAIL_CALL_ORIGIN, GenericGuardrailAPIInputs, GuardrailStatus if TYPE_CHECKING: @@ -72,7 +73,7 @@ _JUDGE_CALL_METADATA: Final = MappingProxyType( ) -class _LoggedCallParams(BaseModel): +class _LoggedCallParams(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) metadata: Mapping[str, object] | None = None diff --git a/litellm/proxy/guardrails/guardrail_hooks/model_armor/file_scanning.py b/litellm/proxy/guardrails/guardrail_hooks/model_armor/file_scanning.py index 2938f5a6ed8..366ea7326ae 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/model_armor/file_scanning.py +++ b/litellm/proxy/guardrails/guardrail_hooks/model_armor/file_scanning.py @@ -19,9 +19,10 @@ from collections.abc import Sequence from dataclasses import dataclass from typing import Annotated, Final, Literal -from pydantic import BaseModel, ConfigDict, Field, TypeAdapter, ValidationError +from pydantic import ConfigDict, Field, TypeAdapter, ValidationError from litellm._logging import verbose_proxy_logger +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import AllMessageValues MODEL_ARMOR_MAX_FILE_SIZE_BYTES: Final = 4 * 1024 * 1024 @@ -72,26 +73,26 @@ class FileScanPlan: unscannable_count: int -class _FileData(BaseModel): +class _FileData(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") file_data: str | None = None format: str | None = None filename: str | None = None -class _FileBlock(BaseModel): +class _FileBlock(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") type: Literal["file"] file: _FileData -class _DocumentSource(BaseModel): +class _DocumentSource(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") data: str | None = None media_type: str | None = None -class _DocumentBlock(BaseModel): +class _DocumentBlock(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") type: Literal["document"] source: _DocumentSource diff --git a/litellm/proxy/guardrails/guardrail_hooks/panw_prisma_airs/panw_prisma_airs.py b/litellm/proxy/guardrails/guardrail_hooks/panw_prisma_airs/panw_prisma_airs.py index d51e7c8b8fb..0607996d13d 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/panw_prisma_airs/panw_prisma_airs.py +++ b/litellm/proxy/guardrails/guardrail_hooks/panw_prisma_airs/panw_prisma_airs.py @@ -17,7 +17,7 @@ from urllib.parse import urlparse import httpx from fastapi import HTTPException -from pydantic import BaseModel, ConfigDict, TypeAdapter, ValidationError, field_validator +from pydantic import ConfigDict, TypeAdapter, ValidationError, field_validator from litellm._logging import verbose_proxy_logger from litellm._uuid import uuid @@ -43,6 +43,7 @@ from litellm.proxy.common_utils.callback_utils import ( add_guardrail_to_applied_guardrails_header, ) from litellm.types.guardrails import GuardrailEventHooks +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import AllMessageValues from litellm.types.utils import ( CallTypes, @@ -67,7 +68,7 @@ ToolCallLike: TypeAlias = ( ) -class _ToolCallFunctionSlice(BaseModel): +class _ToolCallFunctionSlice(LiteLLMBaseModel): model_config = ConfigDict(from_attributes=True, extra="ignore") name: str | None = None @@ -90,19 +91,19 @@ class _ToolCallFunctionSlice(BaseModel): return json.dumps(value) if isinstance(value, (dict, list)) else str(value) -class _ToolCallSlice(BaseModel): +class _ToolCallSlice(LiteLLMBaseModel): model_config = ConfigDict(from_attributes=True, extra="ignore") function: _ToolCallFunctionSlice | None = None -class _ResponsesContentPart(BaseModel): +class _ResponsesContentPart(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") text: str | None = None -class _ResponsesInputItem(BaseModel): +class _ResponsesInputItem(LiteLLMBaseModel): """The slice of a raw Responses ``input`` item that decides which ``texts`` it flattens to.""" model_config = ConfigDict(extra="ignore") diff --git a/litellm/proxy/guardrails/guardrail_hooks/straiker/__init__.py b/litellm/proxy/guardrails/guardrail_hooks/straiker/__init__.py index cb037fb7513..13f8212e8d0 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/straiker/__init__.py +++ b/litellm/proxy/guardrails/guardrail_hooks/straiker/__init__.py @@ -1,10 +1,11 @@ from typing import TYPE_CHECKING, Final, Literal -from pydantic import BaseModel, field_validator +from pydantic import field_validator import litellm from litellm._logging import verbose_proxy_logger from litellm.types.guardrails import SupportedGuardrailIntegrations +from litellm.types.llms.base import LiteLLMBaseModel from .straiker import StraikerGuardrail @@ -12,7 +13,7 @@ if TYPE_CHECKING: from litellm.types.guardrails import Guardrail, LitellmParams -class _V3Routing(BaseModel): +class _V3Routing(LiteLLMBaseModel): api_version: Literal["v1", "v3"] | None = None agent_ref: str | None = None client: str | None = None diff --git a/litellm/proxy/guardrails/guardrail_hooks/typesafe/typesafe.py b/litellm/proxy/guardrails/guardrail_hooks/typesafe/typesafe.py index 96971f0b570..e62f4b70cb8 100644 --- a/litellm/proxy/guardrails/guardrail_hooks/typesafe/typesafe.py +++ b/litellm/proxy/guardrails/guardrail_hooks/typesafe/typesafe.py @@ -16,7 +16,7 @@ from typing import TYPE_CHECKING, Annotated, Final, Literal import httpx from fastapi import HTTPException from httpx import Response as HttpxResponse -from pydantic import BaseModel, ConfigDict, Field, TypeAdapter, ValidationError +from pydantic import ConfigDict, Field, TypeAdapter, ValidationError from litellm._logging import verbose_proxy_logger from litellm.compression.compress import get_protected_indices @@ -33,6 +33,7 @@ from litellm.llms.custom_httpx.http_handler import ( from litellm.proxy.guardrails.guardrail_hooks.content_text import content_to_text from litellm.secret_managers.main import get_secret_str from litellm.types.guardrails import GuardrailEventHooks, Mode +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import GenericGuardrailAPIInputs if TYPE_CHECKING: @@ -84,14 +85,14 @@ def _safe_response_text(response: HttpxResponse | None, limit: int = 500) -> str return (text or "")[:limit] -class _JevNoulAnswer(BaseModel): +class _JevNoulAnswer(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, allow_inf_nan=False) type: Literal["noul"] noul: Annotated[float, Field(ge=0.0, le=1.0)] -class _JevSystemOneResponse(BaseModel): +class _JevSystemOneResponse(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) answers: Mapping[str, _JevNoulAnswer] diff --git a/litellm/proxy/guardrails/usage_endpoints.py b/litellm/proxy/guardrails/usage_endpoints.py index fc237bd55c4..2f466f22ef8 100644 --- a/litellm/proxy/guardrails/usage_endpoints.py +++ b/litellm/proxy/guardrails/usage_endpoints.py @@ -28,6 +28,7 @@ from litellm.repositories.table_repositories import ( SpendLogGuardrailIndexRepository, SpendLogsRepository, ) +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: from prisma import models as prisma_models @@ -248,7 +249,7 @@ class _DailyPassBlocked(TypedDict): blocked: int -class UsageOverviewRow(BaseModel): +class UsageOverviewRow(LiteLLMBaseModel): id: str name: str type: str @@ -268,7 +269,7 @@ class UsageOverviewRow(BaseModel): ) -class UsageOverviewResponse(BaseModel): +class UsageOverviewResponse(LiteLLMBaseModel): rows: list[UsageOverviewRow] chart: list[UsageChartPoint] # [{ date, passed, blocked }] totalRequests: int @@ -291,13 +292,13 @@ _EMPTY_OVERVIEW: Final = UsageOverviewResponse( ) -class UsageUnitsDailyPoint(BaseModel): +class UsageUnitsDailyPoint(LiteLLMBaseModel): date: str units: Mapping[str, int] cost: float | None -class UsageDetailResponse(BaseModel): +class UsageDetailResponse(LiteLLMBaseModel): guardrail_id: str guardrail_name: str type: str @@ -323,7 +324,7 @@ class UsageDetailResponse(BaseModel): untracked_usage_units_by_key: Mapping[str, Mapping[str, int]] -class UsageLogEntry(BaseModel): +class UsageLogEntry(LiteLLMBaseModel): id: str timestamp: str action: str # blocked | passed | flagged | not_run @@ -335,7 +336,7 @@ class UsageLogEntry(BaseModel): reason: str | None -class UsageLogsResponse(BaseModel): +class UsageLogsResponse(LiteLLMBaseModel): logs: list[UsageLogEntry] total: int page: int diff --git a/litellm/proxy/hooks/autorouter_baseline_cache.py b/litellm/proxy/hooks/autorouter_baseline_cache.py index 3d577fa60c3..e3cd6c67aa0 100644 --- a/litellm/proxy/hooks/autorouter_baseline_cache.py +++ b/litellm/proxy/hooks/autorouter_baseline_cache.py @@ -11,7 +11,7 @@ from types import MappingProxyType from typing import TYPE_CHECKING, Final import httpx -from pydantic import BaseModel, ConfigDict, Field, JsonValue, TypeAdapter +from pydantic import ConfigDict, Field, JsonValue, TypeAdapter from litellm._logging import verbose_proxy_logger from litellm.constants import INTERNAL_CALL_ORIGIN_METADATA_KEY @@ -37,6 +37,7 @@ from litellm.proxy.spend_tracking.savings import ( _effective_model_info, # pyright: ignore[reportPrivateUsage] # existing deployment-price owner _proxy_llm_router, # pyright: ignore[reportPrivateUsage] # existing optional proxy-router owner ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.router import BaselineRouteStamp from litellm.types.utils import CallTypes, ModelInfo, Usage from litellm.utils import get_prompt_cache_min_tokens @@ -53,7 +54,7 @@ _COUNT_TIMEOUT: Final = 3.0 _MAX_COUNTS: Final = 4096 -class CapturedBaselineObservation(BaseModel): +class CapturedBaselineObservation(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True, strict=True) scope: str @@ -75,14 +76,14 @@ class BaselineCacheContext: invalidated: str | None = None -class _Metadata(BaseModel): +class _Metadata(LiteLLMBaseModel): model_config = ConfigDict(strict=True, arbitrary_types_allowed=True) route: BaselineRouteStamp = Field(alias="_autorouter_baseline_route") user_api_key_hash: str = Field(min_length=1) session_id: str | None = None -class _WireEvent(BaseModel): +class _WireEvent(LiteLLMBaseModel): model_config = ConfigDict(strict=True, arbitrary_types_allowed=True) httpx_response: httpx.Response api_call_start_time: datetime @@ -92,7 +93,7 @@ class _WireEvent(BaseModel): prompt_cache_response_complete: bool = False -class _ResponseUsage(BaseModel): +class _ResponseUsage(LiteLLMBaseModel): model_config = ConfigDict(strict=True, from_attributes=True) usage: Usage | None = None diff --git a/litellm/proxy/hooks/batch_enqueued_tokens.py b/litellm/proxy/hooks/batch_enqueued_tokens.py index 7b4fa6fe625..c4591eb17fe 100644 --- a/litellm/proxy/hooks/batch_enqueued_tokens.py +++ b/litellm/proxy/hooks/batch_enqueued_tokens.py @@ -17,13 +17,14 @@ from collections.abc import Awaitable, Callable, Mapping, Sequence from dataclasses import dataclass, field from typing import TYPE_CHECKING, Annotated, Final, Literal, Protocol, TypeAlias -from pydantic import BaseModel, ConfigDict, Field, TypeAdapter, ValidationError +from pydantic import ConfigDict, Field, TypeAdapter, ValidationError from litellm._internal_context import with_service_target from litellm._logging import verbose_proxy_logger from litellm.caching.redis_cache import log_redis_failure from litellm.constants import BATCH_ENQUEUED_TOKEN_LIMIT_METADATA_KEY, BATCH_ENQUEUED_TOKEN_TTL_SECONDS from litellm.proxy._types import UserAPIKeyAuth +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: from opentelemetry.trace import Span as _Span @@ -160,7 +161,7 @@ def canonical_provider_batch_id(batch_id: str) -> str: return get_original_file_id(batch_id) -class _BatchResponseView(BaseModel): +class _BatchResponseView(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") id: str diff --git a/litellm/proxy/hooks/batch_rate_limiter.py b/litellm/proxy/hooks/batch_rate_limiter.py index 894123b256a..b707e72792c 100644 --- a/litellm/proxy/hooks/batch_rate_limiter.py +++ b/litellm/proxy/hooks/batch_rate_limiter.py @@ -24,7 +24,7 @@ from types import MappingProxyType from typing import TYPE_CHECKING, Any, Final, Literal, NoReturn, TypeAlias from fastapi import HTTPException -from pydantic import BaseModel, Field, TypeAdapter, ValidationError +from pydantic import Field, TypeAdapter, ValidationError import litellm from litellm._internal_context import with_service_target @@ -62,6 +62,7 @@ from litellm.proxy.hooks.parallel_request_limiter_v3 import ( get_or_create_request_stash, ) from litellm.proxy.hooks.rate_limiter_utils import resolve_llm_provider_for_rate_limit +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: from opentelemetry.trace import Span as _Span @@ -101,7 +102,7 @@ _WINDOW_START_ADAPTER: Final[TypeAdapter[int | float | str | None]] = TypeAdapte IncrementAmounts: TypeAlias = dict[Literal["requests", "tokens"], int] -class BatchFileUsage(BaseModel): +class BatchFileUsage(LiteLLMBaseModel): """ Internal model for batch file usage tracking, used for batch rate limiting """ diff --git a/litellm/proxy/hooks/prompt_cache_prediction.py b/litellm/proxy/hooks/prompt_cache_prediction.py index e724d973d95..b4f7322b58b 100644 --- a/litellm/proxy/hooks/prompt_cache_prediction.py +++ b/litellm/proxy/hooks/prompt_cache_prediction.py @@ -7,12 +7,13 @@ from datetime import datetime from typing import TYPE_CHECKING, Final, Literal import httpx -from pydantic import BaseModel, ConfigDict, Field, TypeAdapter, ValidationError +from pydantic import ConfigDict, Field, TypeAdapter, ValidationError from litellm._internal_context import with_service_target from litellm.caching.dual_cache import DualCache from litellm.integrations.custom_logger import CustomLogger from litellm.llms.anthropic.prompt_cache_prediction import PromptPrefix, parse_observed_cache +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import ModelResponse if TYPE_CHECKING: @@ -21,7 +22,7 @@ if TYPE_CHECKING: _RETENTION_SECONDS: Final = 86_400 -class CacheObservation(BaseModel): +class CacheObservation(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True, strict=True) fingerprint: str = Field(pattern=r"^[0-9a-f]{64}$") @@ -65,19 +66,19 @@ async def _read_exact(cache: DualCache, scope: str, fingerprint: str) -> CacheOb return observation if observation.fingerprint == fingerprint else None -class _Metadata(BaseModel): +class _Metadata(LiteLLMBaseModel): model_config = ConfigDict(strict=True) user_api_key_hash: str = Field(min_length=1) -class _Logged(BaseModel): +class _Logged(LiteLLMBaseModel): model_config = ConfigDict(strict=True) status: Literal["success"] model_id: str = Field(min_length=1) metadata: _Metadata -class _Event(BaseModel): +class _Event(LiteLLMBaseModel): model_config = ConfigDict(strict=True, arbitrary_types_allowed=True) call_type: Literal["anthropic_messages"] custom_llm_provider: Literal["anthropic"] diff --git a/litellm/proxy/lens/endpoints.py b/litellm/proxy/lens/endpoints.py index 1ac4d96b712..e0b887b3d91 100644 --- a/litellm/proxy/lens/endpoints.py +++ b/litellm/proxy/lens/endpoints.py @@ -9,7 +9,7 @@ from uuid import uuid4 from fastapi import APIRouter, Depends, HTTPException, Query, Request, Response from fastapi.security import HTTPAuthorizationCredentials, HTTPBearer -from pydantic import AwareDatetime, BaseModel, Field +from pydantic import AwareDatetime, Field from litellm.litellm_core_utils.secret_redaction import redact_internal_details from litellm.proxy._types import LitellmUserRoles, ModelAccessDeniedProxyException, ProxyException, UserAPIKeyAuth @@ -68,6 +68,7 @@ from litellm.proxy.lens.state import ( summarized, ) from litellm.proxy.tracing_runtime import provide_storage +from litellm.types.llms.base import LiteLLMBaseModel router: Final = APIRouter(prefix="/lens", tags=["Lens"]) _bearer: Final = HTTPBearer() @@ -397,7 +398,7 @@ async def update_finding(lens_id: str, finding_id: str, body: FindingUpdate, aut ) -class Preview(BaseModel): +class Preview(LiteLLMBaseModel): as_of: AwareDatetime | None = None offset: int = Field(default=0, ge=0) selection: ActivitySelection @@ -423,7 +424,7 @@ async def preview_sample(body: Preview, auth: Auth, storage: StorageDep) -> Samp ) -class WorkerBilling(BaseModel): +class WorkerBilling(LiteLLMBaseModel): analysis_key_id: str = Field(pattern=r"^[a-f0-9]{64}$") diff --git a/litellm/proxy/lens/inference.py b/litellm/proxy/lens/inference.py index 491ed9c472f..576e311baf8 100644 --- a/litellm/proxy/lens/inference.py +++ b/litellm/proxy/lens/inference.py @@ -5,7 +5,7 @@ from types import MappingProxyType from typing import Final from fastapi import HTTPException, Request -from pydantic import BaseModel, ConfigDict, Field, field_validator +from pydantic import ConfigDict, Field, field_validator import litellm from litellm.exceptions import ContextWindowExceededError, ModelNotMappedError @@ -18,11 +18,12 @@ from litellm.proxy.lens.models import Job, Lens, ModelRequest, ModelResult, Step from litellm.proxy.lens.repository import LensRepository from litellm.proxy.lens.state import add_step, current_job, renew_budget, replace_job from litellm.types.integrations.anthropic_cache_control_hook import CacheControlMessageInjectionPoint +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import AllMessageValues from litellm.types.utils import CostPerToken, ModelResponse -class DeploymentParams(BaseModel): +class DeploymentParams(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") model: str input_cost_per_token: float | None = None @@ -31,30 +32,30 @@ class DeploymentParams(BaseModel): max_completion_tokens: int | None = Field(default=None, gt=0) -class ModelCapacity(BaseModel): +class ModelCapacity(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") max_input_tokens: int | None = Field(default=None, gt=0) max_output_tokens: int | None = Field(default=None, gt=0) -class Deployment(BaseModel): +class Deployment(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") litellm_params: DeploymentParams model_info: ModelCapacity = ModelCapacity() -class Message(BaseModel): +class Message(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") content: str | None = None -class Choice(BaseModel): +class Choice(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") message: Message finish_reason: str | None = None -class Completion(BaseModel): +class Completion(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") choices: tuple[Choice, ...] = Field(min_length=1) @@ -67,7 +68,7 @@ _SYSTEM: Final = ( ) -class Prices(BaseModel): +class Prices(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") input_cost_per_token: float = Field(ge=0) output_cost_per_token: float = Field(ge=0) @@ -331,13 +332,13 @@ async def analyze( ) -class Usage(BaseModel): +class Usage(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") prompt_tokens: int | None = None completion_tokens: int | None = None -class UsageEnvelope(BaseModel): +class UsageEnvelope(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") model: str | None = None usage: Usage | None = None diff --git a/litellm/proxy/lens/repository.py b/litellm/proxy/lens/repository.py index ba626ea8dc3..d50299dded6 100644 --- a/litellm/proxy/lens/repository.py +++ b/litellm/proxy/lens/repository.py @@ -5,10 +5,11 @@ from collections.abc import AsyncIterator, Awaitable, Callable from types import MappingProxyType from typing import Final, Protocol -from pydantic import BaseModel, JsonValue, TypeAdapter +from pydantic import JsonValue, TypeAdapter from litellm.proxy.db.prisma_client import PrismaWrapper from litellm.proxy.lens.models import Job, Lens, Scope, TraceFindingCount, TraceIdentity, Worker +from litellm.types.llms.base import LiteLLMBaseModel class Database(Protocol): @@ -16,7 +17,7 @@ class Database(Protocol): def execute_raw(self, query: str, *args: object) -> Awaitable[int]: ... -class Row(BaseModel): +class Row(LiteLLMBaseModel): data: JsonValue diff --git a/litellm/proxy/management_endpoints/auto_router_endpoints.py b/litellm/proxy/management_endpoints/auto_router_endpoints.py index e372ccedd80..617a76aaa04 100644 --- a/litellm/proxy/management_endpoints/auto_router_endpoints.py +++ b/litellm/proxy/management_endpoints/auto_router_endpoints.py @@ -14,7 +14,7 @@ from types import MappingProxyType from typing import TYPE_CHECKING, Annotated, Final, Protocol from uuid import uuid4 -from pydantic import BaseModel, ConfigDict, TypeAdapter, field_validator +from pydantic import ConfigDict, TypeAdapter, field_validator import litellm from litellm._logging import verbose_proxy_logger @@ -62,6 +62,7 @@ from litellm.router_utils.auto_router_model_naming import ( classify_strategy_router_model, strategy_router_dependencies, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.management_endpoints.auto_router_endpoints import ( SHADOW_EVAL_TURN_VALVE, AutoRouterAvailabilityRequest, @@ -627,7 +628,7 @@ async def preview_auto_router_routing( ) -class _SessionAggRow(BaseModel): +class _SessionAggRow(LiteLLMBaseModel): """One router's window: session shape from overlapping sessions, money from the selected days.""" router_name: str @@ -1249,7 +1250,7 @@ def _is_unique_violation(error: Exception) -> bool: return isinstance(error, UniqueViolationError) -class _AttemptAggRow(BaseModel): +class _AttemptAggRow(LiteLLMBaseModel): grp: str turn_count: int real_wins: int @@ -1361,7 +1362,7 @@ WHERE group_id = $1 AND stopped_by IS NULL """ -class _FunnelTotalsRow(BaseModel): +class _FunnelTotalsRow(LiteLLMBaseModel): legs_with_rows: int not_sampled: int unjudgeable: int @@ -1369,7 +1370,7 @@ class _FunnelTotalsRow(BaseModel): withheld: int -class _AttemptCountRow(BaseModel): +class _AttemptCountRow(LiteLLMBaseModel): job_id: str attempt_count: int spend: float @@ -1395,7 +1396,7 @@ WHERE group_id IN ( """ -class _AttemptTotalsRow(BaseModel): +class _AttemptTotalsRow(LiteLLMBaseModel): judged_count: int error_count: int judge_spend: float @@ -1429,7 +1430,7 @@ def _leg_group_id(leg: "_LegRow") -> str: return leg.group_id -class _LegRow(BaseModel): +class _LegRow(LiteLLMBaseModel): """One LiteLLM_ShadowEvalJob row, validated off the untyped prisma record. A row is one target's leg of a job; the legs of a job share group_id and identical config, written together by one create_many. The API's job id is the group id, so leg ids diff --git a/litellm/proxy/management_endpoints/cache_settings_endpoints.py b/litellm/proxy/management_endpoints/cache_settings_endpoints.py index 40124bd19a4..2bd4b6b47f9 100644 --- a/litellm/proxy/management_endpoints/cache_settings_endpoints.py +++ b/litellm/proxy/management_endpoints/cache_settings_endpoints.py @@ -15,7 +15,7 @@ from datetime import datetime, timezone from typing import TYPE_CHECKING, Any, Final, Protocol from fastapi import APIRouter, Depends, Header, HTTPException -from pydantic import BaseModel, Field, TypeAdapter +from pydantic import Field, TypeAdapter from litellm._logging import verbose_proxy_logger from litellm._redis import _redis_kwargs_from_environment @@ -30,6 +30,7 @@ from litellm.proxy._types import ( from litellm.proxy.auth.user_api_key_auth import user_api_key_auth from litellm.proxy.db.exception_handler import call_with_db_reconnect_retry from litellm.repositories.table_repositories import CacheConfigRepository +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.management_endpoints import ( CACHE_SETTINGS_FIELDS, REDIS_TYPE_DESCRIPTIONS, @@ -419,23 +420,23 @@ class CacheSettingsManager: CacheSettingsManager._last_cache_params = cache_params.copy() -class CacheSettingsResponse(BaseModel): +class CacheSettingsResponse(LiteLLMBaseModel): fields: list[CacheSettingsField] = Field(description="List of all configurable cache settings with metadata") current_values: dict[str, object] = Field(description="Current values of cache settings") redis_type_descriptions: dict[str, str] = Field(description="Descriptions for each Redis type option") -class CacheTestRequest(BaseModel): +class CacheTestRequest(LiteLLMBaseModel): cache_settings: dict[str, object] = Field(description="Cache settings to test connection with") -class CacheTestResponse(BaseModel): +class CacheTestResponse(LiteLLMBaseModel): status: str = Field(description="Connection status: 'success' or 'failed'") message: str = Field(description="Connection result message") error: str | None = Field(default=None, description="Error message if connection failed") -class CacheSettingsUpdateRequest(BaseModel): +class CacheSettingsUpdateRequest(LiteLLMBaseModel): cache_settings: dict[str, object] = Field(description="Cache settings to save") diff --git a/litellm/proxy/management_endpoints/coordination_redis_endpoints.py b/litellm/proxy/management_endpoints/coordination_redis_endpoints.py index c59ee92f073..fb8b2544d7d 100644 --- a/litellm/proxy/management_endpoints/coordination_redis_endpoints.py +++ b/litellm/proxy/management_endpoints/coordination_redis_endpoints.py @@ -19,7 +19,7 @@ from datetime import datetime, timezone from typing import Final from fastapi import APIRouter, Depends, Header, HTTPException -from pydantic import BaseModel, Field, TypeAdapter, ValidationError +from pydantic import Field, TypeAdapter, ValidationError import litellm from litellm._logging import verbose_proxy_logger @@ -39,6 +39,7 @@ from litellm.proxy.auth.user_api_key_auth import user_api_key_auth from litellm.proxy.utils import invalidate_config_param from litellm.repositories.config_repository import ConfigRepository from litellm.secret_managers.main import get_secret_str +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.management_endpoints import ( COORDINATION_REDIS_SETTINGS_FIELDS, CoordinationRedisSettingsField, @@ -270,7 +271,7 @@ async def _emit_coordination_redis_audit_log( task.add_done_callback(_log_audit_task_exception) -class CoordinationRedisSettingsResponse(BaseModel): +class CoordinationRedisSettingsResponse(LiteLLMBaseModel): values: dict[str, object] = Field(description="Current coordination Redis settings, with credentials redacted") fields: list[CoordinationRedisSettingsField] = Field( description="List of all configurable coordination Redis settings with metadata" @@ -280,11 +281,11 @@ class CoordinationRedisSettingsResponse(BaseModel): ) -class CoordinationRedisSettingsRequest(BaseModel): +class CoordinationRedisSettingsRequest(LiteLLMBaseModel): settings: dict[str, object] = Field(description="Coordination Redis connection params") -class CoordinationRedisTestResponse(BaseModel): +class CoordinationRedisTestResponse(LiteLLMBaseModel): status: str = Field(description="Connection status: 'healthy' or 'unhealthy'") error: str | None = Field(default=None, description="Error message if the connection failed") diff --git a/litellm/proxy/management_endpoints/cost_tracking_settings.py b/litellm/proxy/management_endpoints/cost_tracking_settings.py index f6c767cfbb6..469d112675e 100644 --- a/litellm/proxy/management_endpoints/cost_tracking_settings.py +++ b/litellm/proxy/management_endpoints/cost_tracking_settings.py @@ -15,7 +15,6 @@ from dataclasses import dataclass from typing import Final from fastapi import APIRouter, Depends, HTTPException -from pydantic import BaseModel import litellm from litellm._internal_context import current_billing_time, pinned_billing_time @@ -29,6 +28,7 @@ from litellm.proxy._types import ( ) from litellm.proxy.auth.user_api_key_auth import user_api_key_auth from litellm.proxy.management_endpoints.prompt_cache_prediction import router as prompt_cache_prediction_router +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import ( CostBreakdown, CostPerToken, @@ -496,11 +496,11 @@ async def update_cost_margin_config( ) -class BlockUnpricedModelsRequest(BaseModel): +class BlockUnpricedModelsRequest(LiteLLMBaseModel): enabled: bool -class BlockUnpricedModelsResponse(BaseModel): +class BlockUnpricedModelsResponse(LiteLLMBaseModel): enabled: bool diff --git a/litellm/proxy/management_endpoints/gateway_request_endpoints.py b/litellm/proxy/management_endpoints/gateway_request_endpoints.py index 898c801d347..c7ae50df91c 100644 --- a/litellm/proxy/management_endpoints/gateway_request_endpoints.py +++ b/litellm/proxy/management_endpoints/gateway_request_endpoints.py @@ -16,11 +16,12 @@ from datetime import datetime, timedelta, timezone from typing import Annotated, Final from fastapi import APIRouter, Depends, HTTPException, Query -from pydantic import BaseModel, TypeAdapter +from pydantic import TypeAdapter from litellm._logging import verbose_proxy_logger from litellm.proxy._types import CommonProxyErrors, LitellmUserRoles, UserAPIKeyAuth from litellm.proxy.auth.user_api_key_auth import user_api_key_auth +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.gateway_requests import ( GatewayRequestActivityResponse, GatewayRequestBreakdownEntry, @@ -44,7 +45,7 @@ _AGGREGATE_SQL: Final = """ """ -class _AggregateRow(BaseModel): +class _AggregateRow(LiteLLMBaseModel): """Validates one query_raw row so the handler works with typed values, not Any.""" date: str diff --git a/litellm/proxy/management_endpoints/key_management_endpoints.py b/litellm/proxy/management_endpoints/key_management_endpoints.py index 2ee29f894b5..6dd9888d925 100644 --- a/litellm/proxy/management_endpoints/key_management_endpoints.py +++ b/litellm/proxy/management_endpoints/key_management_endpoints.py @@ -154,6 +154,7 @@ from litellm.repositories.verification_token_repository import ( from litellm.router import Router from litellm.secret_managers.base_secret_manager import raise_if_unsafe_secret_name from litellm.secret_managers.main import get_secret +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.management_endpoints.key_management_endpoints import ( BulkUpdateKeyRequest, BulkUpdateKeyResponse, @@ -212,7 +213,7 @@ class _KeyUpdateResult(TypedDict): data: ReadOnly[Mapping[str, object]] -class _StoredKeyRouterSettings(BaseModel): +class _StoredKeyRouterSettings(LiteLLMBaseModel): router_settings: Mapping[str, object] | None = None @@ -6491,7 +6492,7 @@ KeyStatus = Literal["active", "expired", "revoked", "deleted"] VALID_STATUS_FILTER_VALUES: Final[frozenset[KeyStatus]] = frozenset({"active", "expired", "revoked", "deleted"}) -class _KeyStatusSource(BaseModel): +class _KeyStatusSource(LiteLLMBaseModel): blocked: bool | None = None expires: datetime | None = None diff --git a/litellm/proxy/management_endpoints/management_v1/budgets.py b/litellm/proxy/management_endpoints/management_v1/budgets.py index f1760b857c5..1fe9c94ac5f 100644 --- a/litellm/proxy/management_endpoints/management_v1/budgets.py +++ b/litellm/proxy/management_endpoints/management_v1/budgets.py @@ -7,7 +7,7 @@ from types import MappingProxyType from typing import Annotated, Final from fastapi import APIRouter, Depends, Request -from pydantic import BaseModel, TypeAdapter +from pydantic import TypeAdapter from litellm._logging import verbose_proxy_logger from litellm.proxy._types import ( @@ -35,6 +35,7 @@ from litellm.proxy.list_api.list_framework import ( ) from litellm.proxy.management_endpoints.management_v1.common import MANAGEMENT_V1_PREFIX from litellm.proxy.utils import PrismaClient +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.management_endpoints.management_v1 import ( ListResponse, ProblemDetail, @@ -45,7 +46,7 @@ router: Final = APIRouter(prefix=MANAGEMENT_V1_PREFIX) BUDGET_TABLE: Final = '"LiteLLM_BudgetTable"' -class BudgetListItem(BaseModel): +class BudgetListItem(LiteLLMBaseModel): """One budget as the Budgets page reads it, and as it comes back off the table. Validating the raw row through here is what makes `tpm_limit` / `rpm_limit` @@ -65,7 +66,7 @@ class BudgetListItem(BaseModel): updated_at: datetime -class _RowCount(BaseModel): +class _RowCount(LiteLLMBaseModel): count: int diff --git a/litellm/proxy/management_endpoints/mcp_connector_import.py b/litellm/proxy/management_endpoints/mcp_connector_import.py index 8120452393c..e3e04eebca0 100644 --- a/litellm/proxy/management_endpoints/mcp_connector_import.py +++ b/litellm/proxy/management_endpoints/mcp_connector_import.py @@ -11,13 +11,14 @@ from collections.abc import Mapping from dataclasses import dataclass from typing import Final -from pydantic import AliasChoices, BaseModel, ConfigDict, Field, ValidationError +from pydantic import AliasChoices, ConfigDict, Field, ValidationError from litellm.proxy._types import MCPApprovalStatus, NewMCPServerRequest +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.mcp import MCPAuth, MCPAuthType, MCPCredentials, MCPTransport -class MCPConnectorEntry(BaseModel): +class MCPConnectorEntry(LiteLLMBaseModel): model_config = ConfigDict(populate_by_name=True) name: str | None = None @@ -33,7 +34,7 @@ class MCPConnectorEntry(BaseModel): description: str | None = None -class MCPConnectorImportRequest(BaseModel): +class MCPConnectorImportRequest(LiteLLMBaseModel): model_config = ConfigDict(populate_by_name=True) mcp_servers: Mapping[str, MCPConnectorEntry] | tuple[MCPConnectorEntry, ...] = Field( @@ -53,23 +54,23 @@ class ConnectorConversionError: error: str -class MCPConnectorImportResult(BaseModel): +class MCPConnectorImportResult(LiteLLMBaseModel): name: str server_id: str alias: str -class MCPConnectorImportSkipped(BaseModel): +class MCPConnectorImportSkipped(LiteLLMBaseModel): name: str reason: str -class MCPConnectorImportFailure(BaseModel): +class MCPConnectorImportFailure(LiteLLMBaseModel): name: str error: str -class MCPConnectorImportResponse(BaseModel): +class MCPConnectorImportResponse(LiteLLMBaseModel): imported: tuple[MCPConnectorImportResult, ...] skipped: tuple[MCPConnectorImportSkipped, ...] errors: tuple[MCPConnectorImportFailure, ...] diff --git a/litellm/proxy/management_endpoints/mcp_management_endpoints.py b/litellm/proxy/management_endpoints/mcp_management_endpoints.py index e5bea71ac7c..e481f331e66 100644 --- a/litellm/proxy/management_endpoints/mcp_management_endpoints.py +++ b/litellm/proxy/management_endpoints/mcp_management_endpoints.py @@ -131,11 +131,13 @@ if MCP_AVAILABLE: validate_tool_name, # pyright: ignore[reportAssignmentType] ) except ImportError: - from pydantic import BaseModel + from pydantic import Field - class _ToolNameValidationResult(BaseModel): + from litellm.types.llms.base import LiteLLMBaseModel + + class _ToolNameValidationResult(LiteLLMBaseModel): is_valid: bool = True - warnings: list[str] = [] + warnings: list[str] = Field(default=[]) def validate_tool_name(name: str) -> _ToolNameValidationResult: return _ToolNameValidationResult() diff --git a/litellm/proxy/management_endpoints/model_insights_endpoints.py b/litellm/proxy/management_endpoints/model_insights_endpoints.py index 53e8dfcc71e..c0e7aaa3f7d 100644 --- a/litellm/proxy/management_endpoints/model_insights_endpoints.py +++ b/litellm/proxy/management_endpoints/model_insights_endpoints.py @@ -5,13 +5,14 @@ from datetime import date, datetime, timedelta, timezone from typing import Annotated, Final from fastapi import APIRouter, Depends, HTTPException, Query -from pydantic import BaseModel, Field, TypeAdapter +from pydantic import Field, TypeAdapter from litellm.constants import MODEL_INSIGHTS_DEFAULT_TASK, MODEL_INSIGHTS_MAX_RANGE_DAYS, MODEL_INSIGHTS_TOP_MODELS from litellm.proxy._types import CommonProxyErrors, LitellmUserRoles, UserAPIKeyAuth from litellm.proxy.auth.user_api_key_auth import user_api_key_auth from litellm.proxy.db.model_insights_tasks import load_model_insight_tasks from litellm.repositories.table_repositories import DailyModelUsageRepository +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.model_insights import ( ModelInsightDailyMetric, ModelInsightDailyTotal, @@ -26,7 +27,7 @@ from litellm.types.model_insights import ( router: Final = APIRouter() -class _Sums(BaseModel): +class _Sums(LiteLLMBaseModel): spend: float = 0.0 prompt_tokens: int = 0 completion_tokens: int = 0 @@ -35,7 +36,7 @@ class _Sums(BaseModel): failed_requests: int = 0 -class _GroupedModel(BaseModel): +class _GroupedModel(LiteLLMBaseModel): model_group: str model: str custom_llm_provider: str @@ -46,7 +47,7 @@ class _GroupedDaily(_GroupedModel): date: str -class _GroupedDate(BaseModel): +class _GroupedDate(LiteLLMBaseModel): date: str sums: _Sums = Field(alias="_sum") diff --git a/litellm/proxy/management_endpoints/model_management_endpoints.py b/litellm/proxy/management_endpoints/model_management_endpoints.py index b0653d83f15..42c4a15a4ef 100644 --- a/litellm/proxy/management_endpoints/model_management_endpoints.py +++ b/litellm/proxy/management_endpoints/model_management_endpoints.py @@ -136,6 +136,7 @@ from litellm.router_utils.auto_router_model_naming import ( validate_strategy_router_model_write, ) from litellm.router_utils.auto_router_tuning_baseline import is_mutable_tuned_candidate, tuning_quota_violation +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.bedrock import AwsSessionTag from litellm.types.proxy.management_endpoints.model_management_endpoints import ( AutoRouterClassifierDefaultPromptResponse, @@ -174,7 +175,7 @@ async def update_team(*args, **kwargs): return await _legacy_update_team(*args, **kwargs) -class UpdatePublicModelGroupsRequest(BaseModel): +class UpdatePublicModelGroupsRequest(LiteLLMBaseModel): """Request model for updating public model groups""" model_groups: list[str] = Field(description="List of model group names to make public") @@ -241,7 +242,7 @@ class _TransactionFactory(Protocol): def __call__(self, *, timeout: datetime.timedelta = ...) -> AbstractAsyncContextManager[_TxModelTables]: ... -class _ModelTransactionClient(BaseModel): +class _ModelTransactionClient(LiteLLMBaseModel): model_config = ConfigDict(arbitrary_types_allowed=True, from_attributes=True) tx: _TransactionFactory @@ -3088,7 +3089,7 @@ def _labeled_tiers_from_query(tier_labels: str | None) -> tuple[tuple[Complexity return _validated_labeled_tiers(parsed) -class AutoRouterClassifierPromptPreviewRequest(BaseModel): +class AutoRouterClassifierPromptPreviewRequest(LiteLLMBaseModel): """A POST rather than query params: the classification sections are the operator's own text, which must not reach access logs through a URL.""" diff --git a/litellm/proxy/management_endpoints/policy_endpoints/endpoints.py b/litellm/proxy/management_endpoints/policy_endpoints/endpoints.py index c3c499eeec1..c3d1020f089 100644 --- a/litellm/proxy/management_endpoints/policy_endpoints/endpoints.py +++ b/litellm/proxy/management_endpoints/policy_endpoints/endpoints.py @@ -45,6 +45,7 @@ from litellm.proxy.guardrails.guardrail_registry import GuardrailRegistry from litellm.proxy.management_helpers.utils import management_endpoint_wrapper from litellm.proxy.policy_engine.policy_registry import get_policy_registry from litellm.proxy.policy_engine.policy_resolver import PolicyResolver +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.policy_engine import ( PolicyGuardrailsResponse, PolicyInfoResponse, @@ -258,7 +259,7 @@ def _request_with_json_body(body: dict) -> Request: return Request(scope, receive=receive) -class TestPoliciesAndGuardrailsRequest(BaseModel): +class TestPoliciesAndGuardrailsRequest(LiteLLMBaseModel): """Request body for POST /utils/test_policies_and_guardrails.""" policy_names: list[str] | None = Field(default=None, description="Policy names to resolve guardrails from") @@ -449,7 +450,7 @@ async def validate_policy( return result -class _LoadedPolicy(BaseModel): +class _LoadedPolicy(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", frozen=True, hide_input_in_errors=True) inherit: str | None = None @@ -459,7 +460,7 @@ class _LoadedPolicy(BaseModel): inheritance_chain: tuple[str, ...] = () -class _LoadedPolicies(BaseModel): +class _LoadedPolicies(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", frozen=True, hide_input_in_errors=True) policies: Mapping[str, _LoadedPolicy] = Field(default_factory=dict) @@ -681,7 +682,7 @@ async def get_policy_templates( return _load_policy_templates_from_local_backup() -class EnrichTemplateRequest(BaseModel): +class EnrichTemplateRequest(LiteLLMBaseModel): template_id: str parameters: dict model: str | None = None @@ -1101,7 +1102,7 @@ def _build_comparison_blocked_words( return result -class SuggestTemplatesRequest(BaseModel): +class SuggestTemplatesRequest(LiteLLMBaseModel): attack_examples: list[str] = Field(default_factory=list) description: str = Field(default="") model: str | None = None @@ -1144,7 +1145,7 @@ class GuardrailTestResultEntry(TypedDict): details: str -class TestPolicyTemplateRequest(BaseModel): +class TestPolicyTemplateRequest(LiteLLMBaseModel): guardrail_definitions: list[dict] = Field(description="All guardrailDefinitions from the policy template") text: str = Field(description="Test input text to run guardrails against") diff --git a/litellm/proxy/management_endpoints/prompt_cache_prediction.py b/litellm/proxy/management_endpoints/prompt_cache_prediction.py index 441b05e3773..9103fa09893 100644 --- a/litellm/proxy/management_endpoints/prompt_cache_prediction.py +++ b/litellm/proxy/management_endpoints/prompt_cache_prediction.py @@ -3,7 +3,7 @@ from types import MappingProxyType from typing import Annotated, Final from fastapi import APIRouter, Depends, HTTPException, Request -from pydantic import BaseModel, JsonValue, TypeAdapter +from pydantic import JsonValue, TypeAdapter from litellm.llms.anthropic.prompt_cache_prediction import ( TokenCounter, @@ -23,6 +23,7 @@ from litellm.proxy.hooks.parallel_request_limiter_v3 import ( _PROXY_MaxParallelRequestsHandler_v3, # pyright: ignore[reportPrivateUsage] # use the configured proxy limiter's shared capacity owner ) from litellm.proxy.litellm_pre_call_utils import LiteLLMProxyRequestSetup +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.management_endpoints.prompt_cache_prediction import ( CachePredictionArm, CachePredictionRequest, @@ -33,7 +34,7 @@ router: Final = APIRouter() _REQUEST_DATA: Final = TypeAdapter(Mapping[str, object]) -class _CallerSettings(BaseModel): +class _CallerSettings(LiteLLMBaseModel): config: Mapping[str, object] | None = None diff --git a/litellm/proxy/management_endpoints/prompt_caching_requests.py b/litellm/proxy/management_endpoints/prompt_caching_requests.py index ff99a78e407..2f00d263d84 100644 --- a/litellm/proxy/management_endpoints/prompt_caching_requests.py +++ b/litellm/proxy/management_endpoints/prompt_caching_requests.py @@ -4,7 +4,7 @@ from types import MappingProxyType from typing import TYPE_CHECKING, Annotated, Final from fastapi import APIRouter, Depends, HTTPException, Query -from pydantic import BaseModel, Json, TypeAdapter +from pydantic import Json, TypeAdapter from litellm.proxy._types import CommonProxyErrors, UserAPIKeyAuth, user_api_key_has_admin_view from litellm.proxy.auth.user_api_key_auth import user_api_key_auth @@ -18,6 +18,7 @@ from litellm.proxy.spend_tracking.spend_tracking_utils import ( _query_raw_rows, # pyright: ignore[reportPrivateUsage] # existing typed spend-query adapter; rows validated below ) from litellm.types.integrations.anthropic_cache_control_hook import GATEWAY_INJECTED_CACHE_METADATA_KEY +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.management_endpoints.prompt_caching_requests import ( PromptCachingRequest, PromptCachingRequestCursor, @@ -86,7 +87,7 @@ def prompt_caching_requests_sql(filter: PromptCachingRequestFilter) -> str: """ -class _PromptCachingRow(BaseModel): +class _PromptCachingRow(LiteLLMBaseModel): request_id: str start_time: datetime end_time: datetime diff --git a/litellm/proxy/management_endpoints/roi_calculator_endpoints.py b/litellm/proxy/management_endpoints/roi_calculator_endpoints.py index 4d2f53f2227..2c074dafbe6 100644 --- a/litellm/proxy/management_endpoints/roi_calculator_endpoints.py +++ b/litellm/proxy/management_endpoints/roi_calculator_endpoints.py @@ -15,7 +15,7 @@ from apscheduler.schedulers.asyncio import ( # pyright: ignore[reportMissingTyp AsyncIOScheduler, ) from fastapi import APIRouter, Depends, FastAPI, HTTPException, Query -from pydantic import BaseModel, ConfigDict, SecretStr, TypeAdapter, ValidationError +from pydantic import ConfigDict, SecretStr, TypeAdapter, ValidationError from starlette.types import Receive, Scope, Send from litellm.llms.custom_httpx.http_handler import ( @@ -50,6 +50,7 @@ from litellm.proxy.roi_calculator.sync import ( ) from litellm.proxy.roi_calculator.sync_store import SyncStore from litellm.repositories.config_repository import ConfigRepository +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.roi_calculator import ( DEFAULT_PROMPT, ROIBranchSpend, @@ -78,7 +79,7 @@ _SYNC_MANAGER: Final = SyncManager() _ROI_TAGS: Final[list[str | Enum]] = ["roi calculator"] # mutable-ok: FastAPI requires list-valued route tags -class _RouterEstimatorParams(BaseModel): +class _RouterEstimatorParams(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", from_attributes=True) model: str | None = None @@ -86,14 +87,14 @@ class _RouterEstimatorParams(BaseModel): custom_llm_provider: str | None = None -class _RouterEstimatorModelInfo(BaseModel): +class _RouterEstimatorModelInfo(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", from_attributes=True) base_model: str | None = None mode: str | None = None -class _RouterEstimatorDeployment(BaseModel): +class _RouterEstimatorDeployment(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", from_attributes=True) model_name: str = "" @@ -270,11 +271,11 @@ def _completion_caller(settings: ROISettings) -> CompletionCaller: return complete -class _GatewayModel(BaseModel): +class _GatewayModel(LiteLLMBaseModel): id: str -class _GatewayModels(BaseModel): +class _GatewayModels(LiteLLMBaseModel): data: tuple[_GatewayModel, ...] diff --git a/litellm/proxy/management_endpoints/router_settings_endpoints.py b/litellm/proxy/management_endpoints/router_settings_endpoints.py index d8ea96e6a46..3f927906ed8 100644 --- a/litellm/proxy/management_endpoints/router_settings_endpoints.py +++ b/litellm/proxy/management_endpoints/router_settings_endpoints.py @@ -13,13 +13,14 @@ from types import MappingProxyType from typing import Any, Final, get_args from fastapi import APIRouter, Depends -from pydantic import BaseModel, Field +from pydantic import Field from litellm._logging import verbose_proxy_logger from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.auth.user_api_key_auth import user_api_key_auth from litellm.proxy.config_resolvers import FieldSource, SettingsStore, source_for from litellm.router import Router +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.management_endpoints import ( ROUTER_SETTINGS_FIELDS, ROUTING_STRATEGY_DESCRIPTIONS, @@ -29,7 +30,7 @@ from litellm.types.management_endpoints import ( router: Final = APIRouter() -class RouterSettingsResponse(BaseModel): +class RouterSettingsResponse(LiteLLMBaseModel): 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") @@ -39,7 +40,7 @@ class RouterSettingsResponse(BaseModel): source: dict[str, FieldSource] = Field(description="Source of each current router setting") -class RouterFieldsResponse(BaseModel): +class RouterFieldsResponse(LiteLLMBaseModel): fields: list[RouterSettingsField] = Field( description="List of all configurable router settings with metadata (without field values)" ) diff --git a/litellm/proxy/management_endpoints/router_weights.py b/litellm/proxy/management_endpoints/router_weights.py index 99b368808c3..314f80ad37a 100644 --- a/litellm/proxy/management_endpoints/router_weights.py +++ b/litellm/proxy/management_endpoints/router_weights.py @@ -6,6 +6,7 @@ from fastapi import HTTPException from pydantic import BaseModel, BeforeValidator, ValidationError from litellm.repositories.prisma_protocols import TableActions +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.router_weights import RouterWeights @@ -36,11 +37,11 @@ class _Router(Protocol): pass -class _RouterWeightSettings(BaseModel): +class _RouterWeightSettings(LiteLLMBaseModel): weights: RouterWeights | None = None -class _RouterWeightModelInfo(BaseModel): +class _RouterWeightModelInfo(LiteLLMBaseModel): team_id: str | None = None db_model: bool | None = None team_public_model_name: str | None = None @@ -52,7 +53,7 @@ def _router_weight_model_info(value: object) -> _RouterWeightModelInfo: return _RouterWeightModelInfo.model_validate(value or {}, from_attributes=True) -class _RouterWeightDeployment(BaseModel): +class _RouterWeightDeployment(LiteLLMBaseModel): model_name: str model_info: Annotated[_RouterWeightModelInfo, BeforeValidator(_router_weight_model_info)] diff --git a/litellm/proxy/management_endpoints/scim/scim_v2.py b/litellm/proxy/management_endpoints/scim/scim_v2.py index a7ee0170325..12e1a0841f4 100644 --- a/litellm/proxy/management_endpoints/scim/scim_v2.py +++ b/litellm/proxy/management_endpoints/scim/scim_v2.py @@ -23,7 +23,7 @@ from fastapi import ( Request, Response, ) -from pydantic import BaseModel, TypeAdapter, ValidationError +from pydantic import TypeAdapter, ValidationError from typing_extensions import ReadOnly, TypedDict, assert_never import litellm @@ -73,6 +73,7 @@ from litellm.repositories.user_repository import UserRepository from litellm.repositories.verification_token_repository import ( VerificationTokenRepository, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.management_endpoints.scim_v2 import * if TYPE_CHECKING: @@ -248,7 +249,7 @@ class ScimUserData(TypedDict): roles: list[SCIMMultiValuedAttribute] | None -class GroupMemberExtractionResult(BaseModel): +class GroupMemberExtractionResult(LiteLLMBaseModel): """Result of extracting and processing group members. ``all_member_ids`` is deduped order-preserving; ``existing_member_ids`` is not, diff --git a/litellm/proxy/management_endpoints/team_endpoints.py b/litellm/proxy/management_endpoints/team_endpoints.py index 0266b452b61..20005862b1a 100644 --- a/litellm/proxy/management_endpoints/team_endpoints.py +++ b/litellm/proxy/management_endpoints/team_endpoints.py @@ -33,7 +33,7 @@ from typing import ( import fastapi from fastapi import APIRouter, Depends, Header, HTTPException, Request, status -from pydantic import BaseModel, JsonValue, TypeAdapter, ValidationError +from pydantic import BaseModel, Field, JsonValue, TypeAdapter, ValidationError from typing_extensions import ReadOnly, TypedDict, assert_never import litellm @@ -195,6 +195,7 @@ from litellm.repositories.verification_token_repository import ( VerificationTokenRepository, ) from litellm.router import Router +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.auth.auth_checks import UserNotFoundError from litellm.types.proxy.management_endpoints.common_daily_activity import ( SpendAnalyticsPaginatedResponse, @@ -4034,7 +4035,7 @@ async def reset_team_member_spend_fn( } -class _TeamMetadataView(BaseModel): +class _TeamMetadataView(LiteLLMBaseModel): metadata: Mapping[str, object] | None = None @@ -4793,11 +4794,11 @@ async def _hydrate_member_user_details( return tuple(hydrate(m) for m in members) -class _OrganizationModelsRow(BaseModel): - models: list[str] = [] # mutable-ok: pydantic field default +class _OrganizationModelsRow(LiteLLMBaseModel): + models: list[str] = Field(default=[]) # mutable-ok: pydantic field default -class _TeamRowWithOrganization(BaseModel): +class _TeamRowWithOrganization(LiteLLMBaseModel): litellm_organization_table: _OrganizationModelsRow | None = None diff --git a/litellm/proxy/management_endpoints/tool_management_endpoints.py b/litellm/proxy/management_endpoints/tool_management_endpoints.py index b480d46f185..003b1499582 100644 --- a/litellm/proxy/management_endpoints/tool_management_endpoints.py +++ b/litellm/proxy/management_endpoints/tool_management_endpoints.py @@ -15,7 +15,9 @@ from datetime import datetime, timedelta, timezone from typing import TYPE_CHECKING, Annotated, Final, Protocol, TypeAlias, TypeVar, overload from fastapi import APIRouter, Depends, HTTPException, Query -from pydantic import BaseModel, Field, TypeAdapter +from pydantic import Field, TypeAdapter + +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: from prisma.models import LiteLLM_DailyToolSpend as PrismaDailyToolSpendRow @@ -216,13 +218,13 @@ def _parse_day_start(value: str | None) -> datetime | None: ) -class _ToolSpendSums(BaseModel): +class _ToolSpendSums(LiteLLMBaseModel): spend: float = 0.0 total_tokens: int = 0 request_count: int = 0 -class _TopToolRow(BaseModel): +class _TopToolRow(LiteLLMBaseModel): tool_name: str sums: _ToolSpendSums = Field(alias="_sum") diff --git a/litellm/proxy/management_endpoints/ui_sso.py b/litellm/proxy/management_endpoints/ui_sso.py index 57f52ef4acf..605952b44f0 100644 --- a/litellm/proxy/management_endpoints/ui_sso.py +++ b/litellm/proxy/management_endpoints/ui_sso.py @@ -41,7 +41,7 @@ if TYPE_CHECKING: import jwt from fastapi import APIRouter, Depends, Header, HTTPException, Request, Response, status from fastapi.responses import RedirectResponse -from pydantic import BaseModel, TypeAdapter, ValidationError +from pydantic import TypeAdapter, ValidationError import litellm from litellm._internal_context import with_service_target @@ -139,6 +139,7 @@ from litellm.repositories.table_repositories import SSOConfigRepository from litellm.repositories.team_repository import TeamRepository from litellm.repositories.user_repository import UserRepository from litellm.secret_managers.main import get_secret_bool, get_secret_str +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.management_endpoints.ui_sso import * # noqa: F403 from litellm.types.proxy.management_endpoints.ui_sso import ( DefaultTeamSSOParams, @@ -218,14 +219,14 @@ def _team_detail_db(repo: TeamRepository) -> "TableActions[_TeamDetailRow]": _SSO_TOKEN_CLAIMS_ADAPTER: Final = TypeAdapter(Mapping[str, object]) -class _TeamRowGrants(BaseModel): +class _TeamRowGrants(LiteLLMBaseModel): team_id: str team_alias: str | None = None models: tuple[str, ...] = () litellm_model_table: TeamModelAliasTable | None = None -class CliSsoTeamDetail(BaseModel): +class CliSsoTeamDetail(LiteLLMBaseModel): """The per-team snapshot cached in the CLI SSO flow and echoed to the CLI on poll.""" team_id: str | None = None diff --git a/litellm/proxy/management_endpoints/usage_endpoints/endpoints.py b/litellm/proxy/management_endpoints/usage_endpoints/endpoints.py index d1e92d0c7e4..f03259cb4e9 100644 --- a/litellm/proxy/management_endpoints/usage_endpoints/endpoints.py +++ b/litellm/proxy/management_endpoints/usage_endpoints/endpoints.py @@ -8,7 +8,7 @@ from typing import Final, Literal from fastapi import APIRouter, Depends, Request from fastapi.responses import StreamingResponse -from pydantic import BaseModel, Field +from pydantic import Field import litellm from litellm.proxy._types import UserAPIKeyAuth @@ -17,16 +17,17 @@ from litellm.proxy.common_utils.sse_keepalive import ( SSE_COMMENT_PING, wrap_sse_stream_with_keepalive_pings, ) +from litellm.types.llms.base import LiteLLMBaseModel router: Final = APIRouter() -class ChatMessage(BaseModel): +class ChatMessage(LiteLLMBaseModel): role: Literal["user", "assistant"] content: str -class UsageAIChatRequest(BaseModel): +class UsageAIChatRequest(LiteLLMBaseModel): messages: list[ChatMessage] = Field(..., description="Chat messages (user/assistant history)") model: str | None = Field(default=None, description="Model to use for AI chat") diff --git a/litellm/proxy/management_endpoints/user_agent_analytics_endpoints.py b/litellm/proxy/management_endpoints/user_agent_analytics_endpoints.py index 0422c72cdb3..348f5815be6 100644 --- a/litellm/proxy/management_endpoints/user_agent_analytics_endpoints.py +++ b/litellm/proxy/management_endpoints/user_agent_analytics_endpoints.py @@ -16,7 +16,9 @@ from datetime import datetime, timedelta from typing import TYPE_CHECKING, Final, Protocol, TypeVar, overload from fastapi import APIRouter, Depends, HTTPException, Query -from pydantic import BaseModel, TypeAdapter +from pydantic import TypeAdapter + +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: from prisma.models import LiteLLM_DailyTagSpend as PrismaDailyTagSpendRow @@ -42,7 +44,7 @@ MAX_TAGS: Final = 250 # Maximum number of distinct tags to return router: Final = APIRouter() -class TagActiveUsersResponse(BaseModel): +class TagActiveUsersResponse(LiteLLMBaseModel): """Response for tag active users metrics""" tag: str @@ -52,13 +54,13 @@ class TagActiveUsersResponse(BaseModel): period_end: str | None = None # For WAU/MAU, this will be the end of the period -class ActiveUsersAnalyticsResponse(BaseModel): +class ActiveUsersAnalyticsResponse(LiteLLMBaseModel): """Response for active users analytics""" results: list[TagActiveUsersResponse] -class TagSummaryMetrics(BaseModel): +class TagSummaryMetrics(LiteLLMBaseModel): """Summary metrics for a tag""" tag: str @@ -70,25 +72,25 @@ class TagSummaryMetrics(BaseModel): total_spend: float -class TagSummaryResponse(BaseModel): +class TagSummaryResponse(LiteLLMBaseModel): """Response for tag summary analytics""" results: list[TagSummaryMetrics] -class DistinctTagResponse(BaseModel): +class DistinctTagResponse(LiteLLMBaseModel): """Response for distinct user agent tags""" tag: str -class DistinctTagsResponse(BaseModel): +class DistinctTagsResponse(LiteLLMBaseModel): """Response for all distinct user agent tags""" results: list[DistinctTagResponse] -class PerUserMetrics(BaseModel): +class PerUserMetrics(LiteLLMBaseModel): """Metrics for individual user""" user_id: str @@ -101,7 +103,7 @@ class PerUserMetrics(BaseModel): spend: float = 0.0 -class PerUserAnalyticsResponse(BaseModel): +class PerUserAnalyticsResponse(LiteLLMBaseModel): """Response for per-user analytics""" results: list[PerUserMetrics] @@ -111,11 +113,11 @@ class PerUserAnalyticsResponse(BaseModel): total_pages: int -class _DistinctTagRow(BaseModel): +class _DistinctTagRow(LiteLLMBaseModel): tag: str -class _ActiveUsersRow(BaseModel): +class _ActiveUsersRow(LiteLLMBaseModel): tag: str active_users: int date: str @@ -123,7 +125,7 @@ class _ActiveUsersRow(BaseModel): period_end: str | None = None -class _TagSummaryRow(BaseModel): +class _TagSummaryRow(LiteLLMBaseModel): tag: str unique_users: int | None = None total_requests: float | int | str | None = None diff --git a/litellm/proxy/management_endpoints/workflow_management_endpoints.py b/litellm/proxy/management_endpoints/workflow_management_endpoints.py index eeb64ab2773..890a344dfe0 100644 --- a/litellm/proxy/management_endpoints/workflow_management_endpoints.py +++ b/litellm/proxy/management_endpoints/workflow_management_endpoints.py @@ -23,8 +23,6 @@ try: from prisma.errors import UniqueViolationError except ImportError: UniqueViolationError = None -from pydantic import BaseModel - from litellm._logging import verbose_proxy_logger from litellm.proxy._types import ( CommonProxyErrors, @@ -38,6 +36,7 @@ from litellm.repositories.table_repositories import ( WorkflowMessageRepository, WorkflowRunRepository, ) +from litellm.types.llms.base import LiteLLMBaseModel router: Final = APIRouter() @@ -76,7 +75,7 @@ _EVENT_STATUS_MAP: Final[Mapping[str, str]] = { # --------------------------------------------------------------------------- -class WorkflowRunCreateRequest(BaseModel): +class WorkflowRunCreateRequest(LiteLLMBaseModel): workflow_type: str input: Mapping[str, object] | None = None metadata: Mapping[str, object] | None = None @@ -85,19 +84,19 @@ class WorkflowRunCreateRequest(BaseModel): WorkflowRunStatus = Literal["pending", "running", "paused", "completed", "failed"] -class WorkflowRunUpdateRequest(BaseModel): +class WorkflowRunUpdateRequest(LiteLLMBaseModel): status: WorkflowRunStatus | None = None output: Mapping[str, object] | None = None metadata: Mapping[str, object] | None = None -class WorkflowEventCreateRequest(BaseModel): +class WorkflowEventCreateRequest(LiteLLMBaseModel): event_type: str step_name: str data: Mapping[str, object] | None = None -class WorkflowMessageCreateRequest(BaseModel): +class WorkflowMessageCreateRequest(LiteLLMBaseModel): role: str content: str session_id: str | None = None diff --git a/litellm/proxy/management_helpers/access_group_key_sync.py b/litellm/proxy/management_helpers/access_group_key_sync.py index b9a28a2ebb3..a5289b89cec 100644 --- a/litellm/proxy/management_helpers/access_group_key_sync.py +++ b/litellm/proxy/management_helpers/access_group_key_sync.py @@ -28,8 +28,6 @@ schema. from collections.abc import Sequence from typing import Final, Protocol -from pydantic import BaseModel - from litellm.proxy._types import ( LiteLLM_VerificationToken, RegenerateKeyRequest, @@ -40,9 +38,10 @@ from litellm.proxy.auth.auth_checks import ( ) from litellm.proxy.db.routing_prisma_wrapper import writer_wrapper from litellm.repositories.table_repositories import AccessGroupRepository +from litellm.types.llms.base import LiteLLMBaseModel -class _MovedGroupRow(BaseModel): +class _MovedGroupRow(LiteLLMBaseModel): access_group_id: str diff --git a/litellm/proxy/management_helpers/access_group_model_sync.py b/litellm/proxy/management_helpers/access_group_model_sync.py index 683f2ea79b9..50813b4a2e6 100644 --- a/litellm/proxy/management_helpers/access_group_model_sync.py +++ b/litellm/proxy/management_helpers/access_group_model_sync.py @@ -8,19 +8,18 @@ the arrays alone strands every group on a name nothing serves any more. from collections.abc import Sequence from typing import Final, Protocol -from pydantic import BaseModel - from litellm.proxy.db.routing_prisma_wrapper import writer_wrapper from litellm.proxy.management_helpers.access_group_team_sync import invalidate_access_group_caches from litellm.repositories.table_repositories import AccessGroupRepository from litellm.router import Router +from litellm.types.llms.base import LiteLLMBaseModel -class _TouchedGroupRow(BaseModel): +class _TouchedGroupRow(LiteLLMBaseModel): access_group_id: str -class _DeploymentCountRow(BaseModel): +class _DeploymentCountRow(LiteLLMBaseModel): deployment_count: int diff --git a/litellm/proxy/management_helpers/access_group_team_sync.py b/litellm/proxy/management_helpers/access_group_team_sync.py index 555481d06a4..fbca95b9169 100644 --- a/litellm/proxy/management_helpers/access_group_team_sync.py +++ b/litellm/proxy/management_helpers/access_group_team_sync.py @@ -18,10 +18,11 @@ import asyncio from collections.abc import Mapping, Sequence from typing import Final, Protocol -from pydantic import BaseModel, TypeAdapter +from pydantic import TypeAdapter from litellm.proxy.auth.auth_checks import _delete_cache_access_object from litellm.proxy.db.db_span import db_span +from litellm.types.llms.base import LiteLLMBaseModel # hashtext collisions only cost two unrelated teams a little serialization, and the # lock is never taken by the access-group endpoints as a SELECT ... FOR UPDATE row lock, @@ -58,11 +59,11 @@ RETURNING access_group_id """ -class _AffectedGroup(BaseModel): +class _AffectedGroup(LiteLLMBaseModel): access_group_id: str -class _TeamGroups(BaseModel): +class _TeamGroups(LiteLLMBaseModel): access_group_ids: tuple[str, ...] | None = None diff --git a/litellm/proxy/management_helpers/auto_router_availability.py b/litellm/proxy/management_helpers/auto_router_availability.py index 52cd9f0499b..89baf738d75 100644 --- a/litellm/proxy/management_helpers/auto_router_availability.py +++ b/litellm/proxy/management_helpers/auto_router_availability.py @@ -4,7 +4,7 @@ from dataclasses import dataclass from types import MappingProxyType from typing import Final -from pydantic import BaseModel, Json, TypeAdapter, ValidationError +from pydantic import Json, TypeAdapter, ValidationError from litellm.proxy.common_utils.encrypt_decrypt_utils import decrypt_value_helper from litellm.router_utils.auto_router_model_naming import ( @@ -19,17 +19,18 @@ from litellm.router_utils.auto_router_tuning_baseline import ( mutable_tuned_identities, tuning_quota_violation, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.management_endpoints.auto_router_endpoints import ( AutoRouterAllowance, AutoRouterAvailabilityResponse, ) -class _CatalogModelInfo(BaseModel): +class _CatalogModelInfo(LiteLLMBaseModel): team_id: str | None = None -class _CatalogSource(BaseModel): +class _CatalogSource(LiteLLMBaseModel): model_id: str created_by: str | None = None litellm_params: Json[dict[str, object]] | dict[str, object] diff --git a/litellm/proxy/management_helpers/auto_router_permissions.py b/litellm/proxy/management_helpers/auto_router_permissions.py index 5845194fa9b..f2d0aaaec78 100644 --- a/litellm/proxy/management_helpers/auto_router_permissions.py +++ b/litellm/proxy/management_helpers/auto_router_permissions.py @@ -5,7 +5,7 @@ from types import MappingProxyType from typing import TYPE_CHECKING, Final, Literal from fastapi import HTTPException -from pydantic import BaseModel, ConfigDict, Field, ValidationError +from pydantic import ConfigDict, Field, ValidationError from typing_extensions import ReadOnly, TypedDict from litellm.models.organization import LiteLLM_OrganizationTable @@ -38,6 +38,7 @@ from litellm.router_strategy.complexity_router.config import ( resolve_complexity_router_config_write, ) from litellm.router_utils.auto_router_model_naming import classify_strategy_router_model, strategy_router_dependencies +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.management_endpoints.auto_router_endpoints import RequestComplexityRouterConfig from litellm.types.router import Deployment, updateDeployment @@ -45,14 +46,14 @@ if TYPE_CHECKING: from prisma import types as prisma_types -class _MemberRouterThinking(BaseModel): +class _MemberRouterThinking(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True) type: Literal["enabled", "disabled", "adaptive"] budget_tokens: int | None = Field(default=None, gt=0, le=1_000_000) -class _MemberRouterGenerationParams(BaseModel): +class _MemberRouterGenerationParams(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True) reasoning_effort: str | None = None @@ -69,7 +70,7 @@ class _MemberRouterGenerationParams(BaseModel): stop: str | tuple[str, ...] | None = None -class _MemberOpenSourceClassifierConfig(BaseModel): +class _MemberOpenSourceClassifierConfig(LiteLLMBaseModel): """Classifier settings a team member may set while the gateway owns the connection.""" model_config = ConfigDict(extra="forbid") @@ -88,7 +89,7 @@ class _MemberComplexityRouterConfig(RequestComplexityRouterConfig): model_config = ConfigDict(extra="forbid", arbitrary_types_allowed=True) -class _RouterConfigSource(BaseModel): +class _RouterConfigSource(LiteLLMBaseModel): model: str | None = None complexity_router_config: Mapping[str, object] | None = None @@ -270,7 +271,7 @@ async def _load_member_auto_router_dependency_objects( return MemberAutoRouterDependencyObjects(membership=membership, organization=organization, project=project) -class StoredAutoRouterIdentity(BaseModel): +class StoredAutoRouterIdentity(LiteLLMBaseModel): created_by: str | None = None updated_at: datetime | None = None diff --git a/litellm/proxy/management_helpers/bulk_team_member_budgets.py b/litellm/proxy/management_helpers/bulk_team_member_budgets.py index 6821e0ef413..292cb637687 100644 --- a/litellm/proxy/management_helpers/bulk_team_member_budgets.py +++ b/litellm/proxy/management_helpers/bulk_team_member_budgets.py @@ -11,7 +11,7 @@ from datetime import datetime, timedelta from types import MappingProxyType from typing import TYPE_CHECKING, Final -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict from litellm.litellm_core_utils.safe_json_dumps import safe_dumps from litellm.proxy._types import ( @@ -40,6 +40,7 @@ from litellm.proxy.management_helpers.bulk_user_deletion import ( ) from litellm.proxy.utils import PrismaClient from litellm.repositories.team_repository import TeamRepository +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.management_endpoints.team_endpoints import ( BulkTeamMemberBudgetUpdateRequest, TeamMemberBudgetPatch, @@ -86,7 +87,7 @@ async def _shared_budget_ids(tx: "Prisma", budget_ids: frozenset[str]) -> frozen return frozenset(budget_id for budget_id in budget_ids if sum(1 for row in rows if row.budget_id == budget_id) > 1) -class _AuditedMemberBudget(BaseModel): +class _AuditedMemberBudget(LiteLLMBaseModel): """One member's limits as the audit log's before/after values record them.""" model_config = ConfigDict(frozen=True) @@ -101,7 +102,7 @@ class _AuditedMemberBudget(BaseModel): allowed_models: tuple[str, ...] | None = None -class _AuditedMemberBudgets(BaseModel): +class _AuditedMemberBudgets(LiteLLMBaseModel): """The audit-log columns hold a JSON object, so the per-member list is nested under a key.""" model_config = ConfigDict(frozen=True) diff --git a/litellm/proxy/management_helpers/bulk_user_creation.py b/litellm/proxy/management_helpers/bulk_user_creation.py index af62ea62a1a..ecaec1b6260 100644 --- a/litellm/proxy/management_helpers/bulk_user_creation.py +++ b/litellm/proxy/management_helpers/bulk_user_creation.py @@ -13,7 +13,7 @@ from types import MappingProxyType from typing import TYPE_CHECKING, Final, Literal, TypeAlias, TypeVar from fastapi import HTTPException, Request -from pydantic import BaseModel, ConfigDict, TypeAdapter, ValidationError +from pydantic import ConfigDict, TypeAdapter, ValidationError from typing_extensions import ReadOnly, TypedDict from litellm._logging import verbose_proxy_logger @@ -59,6 +59,7 @@ from litellm.proxy.utils import PrismaClient from litellm.repositories.prisma_protocols import TableActions from litellm.repositories.team_repository import TeamRepository from litellm.repositories.user_repository import UserRepository +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.management_endpoints.internal_user_endpoints import ( BulkNewUserItem, BulkNewUserMeta, @@ -96,7 +97,7 @@ class _PendingUser: teams: tuple[NewUserRequestTeam, ...] -class _UserRow(BaseModel): +class _UserRow(LiteLLMBaseModel): """The `/user/new` body after defaults and object permission were applied.""" model_config = ConfigDict(extra="ignore") @@ -176,7 +177,7 @@ _ERROR_DETAIL: Final = TypeAdapter(Mapping[str, object]) _JSON_OBJECT: Final = TypeAdapter(dict[str, object]) -class _KeyResponse(BaseModel): +class _KeyResponse(LiteLLMBaseModel): token: str diff --git a/litellm/proxy/management_helpers/model_allowlist_rename_sync.py b/litellm/proxy/management_helpers/model_allowlist_rename_sync.py index f93312f7a37..f1a9faf6b2e 100644 --- a/litellm/proxy/management_helpers/model_allowlist_rename_sync.py +++ b/litellm/proxy/management_helpers/model_allowlist_rename_sync.py @@ -11,15 +11,14 @@ from dataclasses import dataclass from types import MappingProxyType from typing import Final -from pydantic import BaseModel - from litellm.proxy.common_utils.auth_cache_invalidation_pubsub import evict_and_broadcast from litellm.proxy.common_utils.user_api_key_cache import UserApiKeyCache from litellm.proxy.management_helpers.access_group_model_sync import raw_executor, still_backed from litellm.router import Router +from litellm.types.llms.base import LiteLLMBaseModel -class _TouchedRow(BaseModel): +class _TouchedRow(LiteLLMBaseModel): kind: str object_id: str team_alias: str | None = None diff --git a/litellm/proxy/management_helpers/team_metadata_validation.py b/litellm/proxy/management_helpers/team_metadata_validation.py index 8bb32696857..6171874f491 100644 --- a/litellm/proxy/management_helpers/team_metadata_validation.py +++ b/litellm/proxy/management_helpers/team_metadata_validation.py @@ -16,9 +16,10 @@ from types import MappingProxyType from typing import Final, Literal, Protocol from fastapi import HTTPException, status -from pydantic import BaseModel, JsonValue, TypeAdapter +from pydantic import JsonValue, TypeAdapter from litellm.proxy._types import CommonProxyErrors, UserAPIKeyAuth +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.management_endpoints.team_endpoints import ( TeamMetadataFieldSchema, ) @@ -30,13 +31,13 @@ DEFAULT_TEAM_METADATA_VALIDATION_UNAVAILABLE_MESSAGE: Final = ( DEFAULT_TEAM_METADATA_VALIDATION_REJECTED_MESSAGE: Final = "Team metadata failed validation." -class TeamMetadataRequester(BaseModel): +class TeamMetadataRequester(LiteLLMBaseModel): user_id: str | None = None user_email: str | None = None user_role: str | None = None -class TeamMetadataValidationPayload(BaseModel): +class TeamMetadataValidationPayload(LiteLLMBaseModel): operation: Literal["create", "update"] metadata: Mapping[str, JsonValue] existing_metadata: Mapping[str, JsonValue] | None = None @@ -45,7 +46,7 @@ class TeamMetadataValidationPayload(BaseModel): requester: TeamMetadataRequester -class TeamMetadataValidationResult(BaseModel): +class TeamMetadataValidationResult(LiteLLMBaseModel): valid: bool error_message: str | None = None diff --git a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/transcribe_passthrough_logging_handler.py b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/transcribe_passthrough_logging_handler.py index e08a600594e..a8dfb745290 100644 --- a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/transcribe_passthrough_logging_handler.py +++ b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/transcribe_passthrough_logging_handler.py @@ -14,7 +14,7 @@ from urllib.parse import quote import httpx import soundfile -from pydantic import BaseModel, ConfigDict, TypeAdapter, ValidationError +from pydantic import ConfigDict, TypeAdapter, ValidationError from typing_extensions import ReadOnly, TypedDict import litellm @@ -45,6 +45,7 @@ from litellm.proxy.common_utils.resource_ownership import ( is_proxy_admin, user_can_access_resource_owner, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.custom_http import httpxSpecialProvider from litellm.types.utils import StandardPassThroughResponseObject @@ -72,18 +73,18 @@ class GetTranscriptionJobRequest(TypedDict): TranscriptionJobName: ReadOnly[str] -class _MediaRef(BaseModel): +class _MediaRef(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) MediaFileUri: str | None = None -class _JobTag(BaseModel): +class _JobTag(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) Key: str | None = None Value: str | None = None -class TranscriptionJobRecord(BaseModel): +class TranscriptionJobRecord(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) TranscriptionJobStatus: str | None = None CreationTime: float | None = None @@ -91,7 +92,7 @@ class TranscriptionJobRecord(BaseModel): Tags: tuple[_JobTag, ...] = () -class _TranscriptionJobResponse(BaseModel): +class _TranscriptionJobResponse(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) TranscriptionJob: TranscriptionJobRecord | None = None @@ -105,7 +106,7 @@ StartedJob: TypeAlias = TranscriptionJobRecord | None JobPricer: TypeAlias = Callable[[str, str, float, StartedJob], Awaitable[float]] -class _PricedCostMapEntry(BaseModel): +class _PricedCostMapEntry(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, strict=True) input_cost_per_second: float diff --git a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/typesafe_passthrough_logging_handler.py b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/typesafe_passthrough_logging_handler.py index 0fa2bfff218..9f8318f9b74 100644 --- a/litellm/proxy/pass_through_endpoints/llm_provider_handlers/typesafe_passthrough_logging_handler.py +++ b/litellm/proxy/pass_through_endpoints/llm_provider_handlers/typesafe_passthrough_logging_handler.py @@ -3,7 +3,7 @@ from datetime import datetime from typing import TYPE_CHECKING, Final import httpx -from pydantic import BaseModel, TypeAdapter, ValidationError +from pydantic import TypeAdapter, ValidationError import litellm from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj @@ -11,23 +11,24 @@ from litellm.litellm_core_utils.litellm_logging import ( get_standard_logging_object_payload, # pyright: ignore[reportUnknownVariableType] # legacy helper has an untyped signature ) from litellm.llms.laya.common_utils import laya_response_model +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import ModelResponse, StandardPassThroughResponseObject, Usage if TYPE_CHECKING: from litellm.proxy._types import PassThroughEndpointLoggingTypedDict -class _TypeSafeUsage(BaseModel): +class _TypeSafeUsage(LiteLLMBaseModel): input_tokens: int = 0 output_tokens: int = 0 -class _TypeSafeResponse(BaseModel): +class _TypeSafeResponse(LiteLLMBaseModel): model: str | None = None usage: _TypeSafeUsage | None = None -class _RegistryPricing(BaseModel): +class _RegistryPricing(LiteLLMBaseModel): input_cost_per_token: float = 0.0 output_cost_per_token: float = 0.0 diff --git a/litellm/proxy/prometheus_metrics_server.py b/litellm/proxy/prometheus_metrics_server.py index 01479f9dd41..053accaf650 100644 --- a/litellm/proxy/prometheus_metrics_server.py +++ b/litellm/proxy/prometheus_metrics_server.py @@ -23,11 +23,12 @@ from typing import Final import httpx from fastapi import FastAPI from prometheus_client import CollectorRegistry, multiprocess -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict from starlette.types import ASGIApp, Message, Receive, Scope, Send from litellm.integrations.prometheus_metrics_endpoint import make_metrics_asgi_app from litellm.llms.custom_httpx.http_handler import HTTPHandler +from litellm.types.llms.base import LiteLLMBaseModel METRICS_PATH: Final = "/metrics" HEALTH_PATH: Final = "/health" @@ -39,7 +40,7 @@ _STARTUP_PROBE_TIMEOUT_SECONDS: Final = 1.0 _WILDCARD_TO_LOOPBACK: Final = MappingProxyType({"0.0.0.0": "127.0.0.1", "::": "::1"}) -class _CliArgs(BaseModel): +class _CliArgs(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) host: str diff --git a/litellm/proxy/prompts/prompt_endpoints.py b/litellm/proxy/prompts/prompt_endpoints.py index 06957fd1c0f..41c8a6a77b4 100644 --- a/litellm/proxy/prompts/prompt_endpoints.py +++ b/litellm/proxy/prompts/prompt_endpoints.py @@ -36,6 +36,7 @@ from litellm.proxy.prompts.prompt_registry import ( prompt_environment_or_default, ) from litellm.repositories.table_repositories import PromptRepository +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.prompts.init_prompts import ( ListPromptsResponse, PromptInfo, @@ -76,7 +77,7 @@ class _PromptRow(Protocol): def model_dump(self) -> Mapping[str, object]: ... -class _PromptRowData(BaseModel): +class _PromptRowData(LiteLLMBaseModel): prompt_id: str version: int = 1 environment: str = "development" @@ -190,7 +191,7 @@ def create_versioned_prompt_spec(db_prompt: _PromptRow) -> PromptSpec: ) -class Prompt(BaseModel): +class Prompt(LiteLLMBaseModel): prompt_id: str litellm_params: PromptLiteLLMParams prompt_info: PromptInfo | None = None @@ -211,7 +212,7 @@ def is_ambiguous_keyed_prompt_data(litellm_params: PromptLiteLLMParams) -> bool: return bool(prompt_data) and "content" not in prompt_data -class PatchPromptRequest(BaseModel): +class PatchPromptRequest(LiteLLMBaseModel): litellm_params: PromptLiteLLMParams | None = None prompt_info: PromptInfo | None = None @@ -1039,7 +1040,6 @@ async def test_prompt( }' ``` """ - from pydantic import BaseModel from litellm.integrations.dotprompt.dotprompt_manager import DotpromptManager from litellm.integrations.dotprompt.prompt_manager import ( diff --git a/litellm/proxy/proxy_cli.py b/litellm/proxy/proxy_cli.py index 08dfc79def7..1a741af6654 100644 --- a/litellm/proxy/proxy_cli.py +++ b/litellm/proxy/proxy_cli.py @@ -15,7 +15,7 @@ import click import httpx from click.core import ParameterSource from dotenv import load_dotenv -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict import litellm from litellm.constants import DEFAULT_NUM_WORKERS_LITELLM_PROXY @@ -26,6 +26,7 @@ from litellm.proxy.db.pgbouncer import ( start_in_container_pgbouncer, ) from litellm.proxy.db.query_engine_reaper import start_query_engine_reaper +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: from fastapi import FastAPI @@ -97,7 +98,7 @@ def _build_db_connection_url_params( return params -class DatabaseTimeoutSettings(BaseModel): +class DatabaseTimeoutSettings(LiteLLMBaseModel): """The `general_settings` keys that bound how long a statement may hold locks. Validated at the boundary so a mistyped value fails at startup with a clear diff --git a/litellm/proxy/response_api_endpoints/endpoints.py b/litellm/proxy/response_api_endpoints/endpoints.py index 882aa240fad..20461cc9a01 100644 --- a/litellm/proxy/response_api_endpoints/endpoints.py +++ b/litellm/proxy/response_api_endpoints/endpoints.py @@ -12,7 +12,7 @@ from fastapi import APIRouter, Depends, HTTPException, Request, Response from fastapi.responses import JSONResponse from openai.types.responses import ResponseItemList from openai.types.responses.response_create_params import ResponseInputParam -from pydantic import BaseModel, ConfigDict, ValidationError +from pydantic import ConfigDict, ValidationError from starlette.websockets import WebSocket, WebSocketDisconnect from typing_extensions import ReadOnly, TypedDict @@ -35,6 +35,7 @@ from litellm.proxy.common_utils.http_parsing_utils import ( _safe_set_request_parsed_body, ) from litellm.proxy.route_llm_request import raise_if_required_body_param_missing +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import ( REASONING_EFFORT, ResponsesAPIOptionalRequestParams, @@ -1396,7 +1397,7 @@ def _extract_model_from_first_ws_event(first_event: object) -> str | None: return (nested.get("model") if isinstance(nested, dict) else None) or first_event.get("model") -class _ResponseCreateRoutingHints(BaseModel): +class _ResponseCreateRoutingHints(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", frozen=True) input: str | Sequence[object] | None = None diff --git a/litellm/proxy/roi_calculator/github.py b/litellm/proxy/roi_calculator/github.py index 993b6b9c9fa..922faaed992 100644 --- a/litellm/proxy/roi_calculator/github.py +++ b/litellm/proxy/roi_calculator/github.py @@ -6,13 +6,14 @@ from typing import Final, TypeVar from urllib.parse import quote import httpx -from pydantic import BaseModel, ConfigDict, Field, TypeAdapter +from pydantic import ConfigDict, Field, TypeAdapter from typing_extensions import ReadOnly, TypedDict from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, # pyright: ignore[reportUnknownVariableType] # shared client factory has untyped params ) from litellm.proxy.roi_calculator.analytics import normalize_email +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.custom_http import httpxSpecialProvider from litellm.types.roi_calculator import ROIPullCommit, ROIPullEvidence, ROIPullFile, ROISettings from litellm.types.roi_observed import ObservedIssue @@ -24,7 +25,7 @@ class SourceError(Exception): pass -class _GitHubModel(BaseModel): +class _GitHubModel(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") @@ -333,7 +334,7 @@ class _Issue(_GitHubModel): pull_request: object | None = None -class GitHubIssueSettings(BaseModel): +class GitHubIssueSettings(LiteLLMBaseModel): has_issues: bool diff --git a/litellm/proxy/roi_calculator/github_observed.py b/litellm/proxy/roi_calculator/github_observed.py index a34d34823be..74d3557e203 100644 --- a/litellm/proxy/roi_calculator/github_observed.py +++ b/litellm/proxy/roi_calculator/github_observed.py @@ -2,38 +2,39 @@ from datetime import date, datetime, time, timedelta, timezone from typing import Final, Literal import httpx -from pydantic import BaseModel, Field +from pydantic import Field from litellm.proxy.roi_calculator.github import GitHubIssueSettings, GitHubPullListItem, SourceError, request_github +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.roi_calculator import ROISettings from litellm.types.roi_observed import ObservedIssue -class _PageInfo(BaseModel): +class _PageInfo(LiteLLMBaseModel): hasNextPage: bool = False endCursor: str | None = None -class _Author(BaseModel): +class _Author(LiteLLMBaseModel): login: str kind: str = Field(alias="__typename") email: str | None = None -class _Repository(BaseModel): +class _Repository(LiteLLMBaseModel): nameWithOwner: str -class _Label(BaseModel): +class _Label(LiteLLMBaseModel): name: str -class _Labels(BaseModel): +class _Labels(LiteLLMBaseModel): nodes: tuple[_Label, ...] = () pageInfo: _PageInfo = Field(default_factory=_PageInfo) -class _Node(BaseModel): +class _Node(LiteLLMBaseModel): number: int url: str title: str @@ -69,17 +70,17 @@ class _Node(BaseModel): ) -class _Search(BaseModel): +class _Search(LiteLLMBaseModel): issueCount: int pageInfo: _PageInfo nodes: tuple[_Node, ...] -class _Data(BaseModel): +class _Data(LiteLLMBaseModel): search: _Search -class _Response(BaseModel): +class _Response(LiteLLMBaseModel): data: _Data | None = None errors: tuple[object, ...] = () diff --git a/litellm/proxy/roi_calculator/gitlab.py b/litellm/proxy/roi_calculator/gitlab.py index 9fbf43d8890..ae53583ac5c 100644 --- a/litellm/proxy/roi_calculator/gitlab.py +++ b/litellm/proxy/roi_calculator/gitlab.py @@ -14,6 +14,7 @@ from litellm.llms.custom_httpx.http_handler import ( from litellm.proxy.roi_calculator.analytics import normalize_email from litellm.proxy.roi_calculator.github import GitHubPullListItem, SourceError from litellm.proxy.roi_calculator.source import repository_tag +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.custom_http import httpxSpecialProvider from litellm.types.roi_calculator import ROIPullCommit, ROIPullEvidence, ROIPullFile, ROISettings from litellm.types.roi_observed import ObservedIssue @@ -21,13 +22,13 @@ from litellm.types.roi_observed import ObservedIssue _T: Final = TypeVar("_T", bound=BaseModel) -class _User(BaseModel): +class _User(LiteLLMBaseModel): username: str public_email: str | None = None bot: bool = False -class _Project(BaseModel): +class _Project(LiteLLMBaseModel): id: int path_with_namespace: str visibility: str = "private" @@ -36,7 +37,7 @@ class _Project(BaseModel): issues_access_level: str = "enabled" -class _MergeRequest(BaseModel): +class _MergeRequest(LiteLLMBaseModel): iid: int title: str description: str | None = None @@ -70,7 +71,7 @@ class _MergeRequest(BaseModel): ) -class _Diff(BaseModel): +class _Diff(LiteLLMBaseModel): new_path: str old_path: str diff: str = "" @@ -95,12 +96,12 @@ class _Diff(BaseModel): ) -class _Commit(BaseModel): +class _Commit(LiteLLMBaseModel): id: str message: str -class _Issue(BaseModel): +class _Issue(LiteLLMBaseModel): iid: int created_at: datetime labels: tuple[str, ...] = () diff --git a/litellm/proxy/roi_calculator/oauth.py b/litellm/proxy/roi_calculator/oauth.py index 32d8cd3e1d0..68202ed5a8d 100644 --- a/litellm/proxy/roi_calculator/oauth.py +++ b/litellm/proxy/roi_calculator/oauth.py @@ -13,7 +13,7 @@ from urllib.parse import parse_qsl, urlencode, urlsplit import httpx from fastapi import HTTPException from oauthlib.oauth2 import WebApplicationClient -from pydantic import BaseModel, ConfigDict, Field, SecretStr, TypeAdapter +from pydantic import ConfigDict, Field, SecretStr, TypeAdapter from litellm.llms.custom_httpx.http_handler import ( get_async_httpx_client, # pyright: ignore[reportUnknownVariableType] # shared client factory has untyped params @@ -30,6 +30,7 @@ from litellm.proxy.roi_calculator.settings import ( ) from litellm.proxy.roi_calculator.sync_store import SyncStore from litellm.repositories.config_repository import ConfigRepository +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.custom_http import httpxSpecialProvider from litellm.types.roi_calculator import ROISettings, ROISyncStatus @@ -111,7 +112,7 @@ def oauth_config(provider: Provider) -> OAuthConfig | None: ) -class OAuthState(BaseModel): +class OAuthState(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) provider: Provider @@ -124,11 +125,11 @@ class OAuthState(BaseModel): flow: Literal["authorize", "install"] = "authorize" -class _Envelope(BaseModel): +class _Envelope(LiteLLMBaseModel): payload: str -class _StateRow(BaseModel): +class _StateRow(LiteLLMBaseModel): param_value: _Envelope @@ -218,7 +219,7 @@ async def consume_state( return value -class TokenGrant(BaseModel): +class TokenGrant(LiteLLMBaseModel): access_token: SecretStr token_type: str = "bearer" refresh_token: SecretStr = SecretStr("") diff --git a/litellm/proxy/roi_calculator/settings.py b/litellm/proxy/roi_calculator/settings.py index 89a691843f4..add8285b138 100644 --- a/litellm/proxy/roi_calculator/settings.py +++ b/litellm/proxy/roi_calculator/settings.py @@ -5,12 +5,13 @@ from types import MappingProxyType from typing import Annotated, Final, Literal from fastapi import Depends, HTTPException -from pydantic import BaseModel, ConfigDict, Field, SecretStr, TypeAdapter, ValidationError +from pydantic import ConfigDict, Field, SecretStr, TypeAdapter, ValidationError from litellm.proxy._types import CommonProxyErrors, LitellmUserRoles, UserAPIKeyAuth from litellm.proxy.auth.user_api_key_auth import user_api_key_auth from litellm.proxy.common_utils.encrypt_decrypt_utils import decrypt_value_helper, encrypt_value_helper from litellm.repositories.config_repository import ConfigRepository +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.roi_calculator import DEFAULT_PROMPT, ROISettings _SETTINGS_KEY: Final = "roi_calculator_settings" @@ -20,7 +21,7 @@ def connection_id(provider: str, api_url: str) -> str: return provider + "_" + sha256(api_url.strip().rstrip("/").encode()).hexdigest()[:16] -class StoredConnection(BaseModel): +class StoredConnection(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) source_provider: Literal["github", "gitlab"] @@ -38,7 +39,7 @@ class StoredConnection(BaseModel): return connection_id(self.source_provider, self.api_url) -class StoredROISettings(BaseModel): +class StoredROISettings(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") revision: int = 0 diff --git a/litellm/proxy/roi_calculator/sync.py b/litellm/proxy/roi_calculator/sync.py index de9a1a979f1..d134ec8bea0 100644 --- a/litellm/proxy/roi_calculator/sync.py +++ b/litellm/proxy/roi_calculator/sync.py @@ -8,7 +8,7 @@ from typing import Final, Literal, NamedTuple, Protocol, runtime_checkable from uuid import uuid4 import httpx -from pydantic import BaseModel, ConfigDict, Field, TypeAdapter +from pydantic import ConfigDict, Field, TypeAdapter from typing_extensions import ReadOnly, TypedDict, Unpack from litellm._logging import verbose_proxy_logger @@ -18,6 +18,7 @@ from litellm.proxy.roi_calculator.github import GitHubPullListItem, SourceError from litellm.proxy.roi_calculator.pull_cache import cache_key, settings_fingerprint from litellm.proxy.roi_calculator.source import RepositorySource, create_source, repository_tag from litellm.repositories.chunked_in import find_many_in +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.roi_calculator import ( ROIBranchSpend, ROIEstimate, @@ -99,12 +100,12 @@ def spend_prisma_client(prisma_client: object) -> _SpendPrismaClient: return prisma_client -class _DailySpendSums(BaseModel): +class _DailySpendSums(LiteLLMBaseModel): spend: float = 0.0 api_requests: int = 0 -class _DailySpendGroup(BaseModel): +class _DailySpendGroup(LiteLLMBaseModel): model_config = ConfigDict(from_attributes=True) user_id: str | None @@ -112,7 +113,7 @@ class _DailySpendGroup(BaseModel): sums: _DailySpendSums = Field(alias="_sum") -class _UserEmail(BaseModel): +class _UserEmail(LiteLLMBaseModel): model_config = ConfigDict(from_attributes=True) user_id: str diff --git a/litellm/proxy/roi_calculator/sync_store.py b/litellm/proxy/roi_calculator/sync_store.py index df126da6d70..c6263d48d43 100644 --- a/litellm/proxy/roi_calculator/sync_store.py +++ b/litellm/proxy/roi_calculator/sync_store.py @@ -2,9 +2,10 @@ from datetime import datetime, timezone from types import MappingProxyType from typing import Final, Literal, Protocol, cast # noqa: TID251 - PrismaWrapper dynamically delegates database methods -from pydantic import BaseModel, ConfigDict, TypeAdapter +from pydantic import ConfigDict, TypeAdapter from litellm.proxy.utils import PrismaClient +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.roi_calculator import ROIReport, ROISyncStatus from litellm.types.roi_observed import ObservedData @@ -12,13 +13,13 @@ _SYNC_KEY: Final = "roi_calculator_sync" _REPORT_KEY: Final = "roi_calculator_report" -class _SyncState(BaseModel): +class _SyncState(LiteLLMBaseModel): owner: str status: ROISyncStatus cancel: bool = False -class _StateRow(BaseModel): +class _StateRow(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") param_value: _SyncState expired: bool = False diff --git a/litellm/proxy/search_endpoints/search_tool_management.py b/litellm/proxy/search_endpoints/search_tool_management.py index 6c06836c190..9d4304e1d47 100644 --- a/litellm/proxy/search_endpoints/search_tool_management.py +++ b/litellm/proxy/search_endpoints/search_tool_management.py @@ -7,7 +7,6 @@ from datetime import datetime from typing import Any, Final, TypeAlias from fastapi import APIRouter, Depends, HTTPException -from pydantic import BaseModel from litellm._logging import verbose_proxy_logger from litellm.constants import UI_SESSION_TOKEN_TEAM_ID @@ -21,6 +20,7 @@ from litellm.proxy.search_endpoints.search_tool_registry import ( SearchToolRegistry, keep_loaded_search_tools_that_do_not_decrypt, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.search import ( ListSearchToolsResponse, SearchTool, @@ -277,7 +277,7 @@ async def list_search_tools( raise HTTPException(status_code=500, detail=str(e)) -class CreateSearchToolRequest(BaseModel): +class CreateSearchToolRequest(LiteLLMBaseModel): search_tool: SearchTool @@ -349,7 +349,7 @@ async def create_search_tool(request: CreateSearchToolRequest): raise HTTPException(status_code=500, detail=str(e)) -class UpdateSearchToolRequest(BaseModel): +class UpdateSearchToolRequest(LiteLLMBaseModel): search_tool: SearchTool @@ -566,7 +566,7 @@ async def get_search_tool_info(search_tool_id: str): raise HTTPException(status_code=500, detail=str(e)) -class TestSearchToolConnectionRequest(BaseModel): +class TestSearchToolConnectionRequest(LiteLLMBaseModel): litellm_params: dict[str, Any] diff --git a/litellm/proxy/spend_tracking/baseline_accounting.py b/litellm/proxy/spend_tracking/baseline_accounting.py index 263dc4de529..46a38f71260 100644 --- a/litellm/proxy/spend_tracking/baseline_accounting.py +++ b/litellm/proxy/spend_tracking/baseline_accounting.py @@ -13,16 +13,17 @@ from math import isfinite from types import MappingProxyType from typing import Final, Literal -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field from litellm.llms.anthropic.prompt_cache_prediction import CountedBreakpoint, CountedPromptCachePlan +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import CacheCreationTokenDetails, PromptTokensDetailsWrapper, Usage MAX_CACHE_TTL: Final = 3600 MAX_CACHE_ENTRIES: Final = 1024 -class BaselineObservation(BaseModel): +class BaselineObservation(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True, strict=True) version: Literal[3] = 3 diff --git a/litellm/proxy/spend_tracking/key_metadata_recovery.py b/litellm/proxy/spend_tracking/key_metadata_recovery.py index 900fea7e2cc..5442c0f3f81 100644 --- a/litellm/proxy/spend_tracking/key_metadata_recovery.py +++ b/litellm/proxy/spend_tracking/key_metadata_recovery.py @@ -6,7 +6,7 @@ from datetime import datetime, timedelta from types import MappingProxyType from typing import Final, Literal, TypeVar -from pydantic import BaseModel, TypeAdapter +from pydantic import TypeAdapter from typing_extensions import ReadOnly, TypedDict from litellm._logging import verbose_proxy_logger @@ -24,6 +24,7 @@ from litellm.proxy.db.db_span import db_span, db_spanned from litellm.proxy.utils import PrismaClient from litellm.repositories.chunked_in import find_many_in from litellm.repositories.user_repository import UserRepository +from litellm.types.llms.base import LiteLLMBaseModel _T = TypeVar("_T") @@ -118,7 +119,7 @@ class KeyMetadataDict(TypedDict, total=False): key_exists: ReadOnly[bool] -class _TokenDigestRow(BaseModel): +class _TokenDigestRow(LiteLLMBaseModel): digest: str key_alias: str | None = None team_id: str | None = None @@ -131,7 +132,7 @@ def _unanimous(first: str | None, last: str | None) -> str | None: return first if last is None or first == last else None -class _SpendLogDigestRow(BaseModel): +class _SpendLogDigestRow(LiteLLMBaseModel): digest: str first_alias: str | None = None last_alias: str | None = None @@ -148,7 +149,7 @@ class _SpendLogDigestRow(BaseModel): ) -class _DailyUserSpendOwnerRow(BaseModel): +class _DailyUserSpendOwnerRow(LiteLLMBaseModel): api_key: str first_owner: str | None = None last_owner: str | None = None diff --git a/litellm/proxy/spend_tracking/savings.py b/litellm/proxy/spend_tracking/savings.py index fbcf9c78d3e..aa0590ce934 100644 --- a/litellm/proxy/spend_tracking/savings.py +++ b/litellm/proxy/spend_tracking/savings.py @@ -14,7 +14,7 @@ from math import isclose, isfinite from types import MappingProxyType from typing import TYPE_CHECKING, Final, Literal, NamedTuple -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field import litellm from litellm._logging import verbose_proxy_logger @@ -28,6 +28,7 @@ from litellm.types.integrations.anthropic_cache_control_hook import ( GATEWAY_INJECTED_CACHE_METADATA_KEY, GATEWAY_INJECTED_FOR_EVERY_DEPLOYMENT, ) +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: from litellm.router import Router @@ -122,7 +123,7 @@ class PricingBasis(NamedTuple): _STANDARD_RATES: Final = PricingBasis() -class BaselineCostSnapshot(BaseModel): +class BaselineCostSnapshot(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True, strict=True) model: str diff --git a/litellm/proxy/spend_tracking/spend_capture_rate.py b/litellm/proxy/spend_tracking/spend_capture_rate.py index 664f100a7b2..443010b65da 100644 --- a/litellm/proxy/spend_tracking/spend_capture_rate.py +++ b/litellm/proxy/spend_tracking/spend_capture_rate.py @@ -11,7 +11,7 @@ from datetime import date, datetime, timedelta, timezone from types import MappingProxyType from typing import TYPE_CHECKING, Final, TypeAlias -from pydantic import BaseModel, ConfigDict, TypeAdapter +from pydantic import ConfigDict, TypeAdapter from typing_extensions import assert_never from litellm._internal_context import with_service_target @@ -30,6 +30,7 @@ from litellm.llms.openai.organization_costs import ( ) from litellm.proxy.db.db_transaction_queue.pod_lock_manager import POD_LOCK_TARGET from litellm.secret_managers.main import get_secret_str +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.spend_capture_rate import ( CaptureRateDay, CaptureRateReport, @@ -70,7 +71,7 @@ ProviderBillingFailure: TypeAlias = ProviderBillingCredentialMissing | ProviderB CheckResult: TypeAlias = CaptureRateReport | ProviderBillingFailure -class _CapturedSpendRow(BaseModel): +class _CapturedSpendRow(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") date: str diff --git a/litellm/proxy/spend_tracking/spend_event.py b/litellm/proxy/spend_tracking/spend_event.py index 53f26346f85..031e84896b2 100644 --- a/litellm/proxy/spend_tracking/spend_event.py +++ b/litellm/proxy/spend_tracking/spend_event.py @@ -26,6 +26,7 @@ import litellm from litellm.proxy._types import UserAPIKeyAuth from litellm.proxy.db.spend_log_tool_index import response_tool_call_names from litellm.types.interactions import InteractionsAPIResponse +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import LiteLLMBatch, Usage SPEND_EVENT_VERSION: Final = 1 @@ -159,7 +160,7 @@ _OBJECT_MAPPING: Final = TypeAdapter(ObjectMapping) _COMPACT_RESPONSE: Final = TypeAdapter(CompactResponse) -class SpendEvent(BaseModel): +class SpendEvent(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="forbid") version: Literal[1] diff --git a/litellm/proxy/tracing_endpoints.py b/litellm/proxy/tracing_endpoints.py index 019829c9366..f6ddc5ddebe 100644 --- a/litellm/proxy/tracing_endpoints.py +++ b/litellm/proxy/tracing_endpoints.py @@ -16,7 +16,7 @@ from types import MappingProxyType from typing import Annotated, Final, Literal from fastapi import APIRouter, Depends, HTTPException, Query, Request, Response -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict from typing_extensions import assert_never from litellm._logging import verbose_proxy_logger @@ -50,6 +50,7 @@ from litellm.rust_bridge.trace.generated.types import ( from litellm.rust_bridge.trace.storage import ClickHouseStorage, Tenant from litellm.tracing import TraceReceiver, TracingPayloadTooLargeError from litellm.tracing.otlp_http import InvalidOTLPPayloadError, encode_otlp_response +from litellm.types.llms.base import LiteLLMBaseModel router = APIRouter(tags=["agent tracing"]) @@ -150,7 +151,7 @@ async def ingest_otlp_traces( return Response(content=body, media_type=media_type) -class TraceReadFailure(BaseModel): +class TraceReadFailure(LiteLLMBaseModel): """The body of every failed trace read. Clients branch on `code`, never on `message`.""" model_config = ConfigDict(frozen=True) diff --git a/litellm/proxy/ui_crud_endpoints/latest_release_endpoints.py b/litellm/proxy/ui_crud_endpoints/latest_release_endpoints.py index 2e90d4c0d90..720b4dd8d32 100644 --- a/litellm/proxy/ui_crud_endpoints/latest_release_endpoints.py +++ b/litellm/proxy/ui_crud_endpoints/latest_release_endpoints.py @@ -8,11 +8,12 @@ from typing import Annotated, Final, Literal, Protocol, TypeAlias import httpx from fastapi import APIRouter, Depends -from pydantic import BaseModel, ValidationError +from pydantic import ValidationError from litellm._logging import verbose_proxy_logger from litellm.caching.in_memory_cache import InMemoryCache from litellm.proxy.auth.user_api_key_auth import user_api_key_auth +from litellm.types.llms.base import LiteLLMBaseModel router: Final = APIRouter() @@ -29,7 +30,7 @@ _Bucket: TypeAlias = Literal["new_features", "bug_fixes", "other_updates"] _PREFIX_BUCKETS: Final[Mapping[str, _Bucket]] = MappingProxyType({"feat": "new_features", "fix": "bug_fixes"}) -class LatestReleaseInfo(BaseModel): +class LatestReleaseInfo(LiteLLMBaseModel): version: str new_features: int bug_fixes: int @@ -42,7 +43,7 @@ class LatestReleaseUnavailable: reason: str -class _GitHubRelease(BaseModel): +class _GitHubRelease(LiteLLMBaseModel): tag_name: str html_url: str body: str diff --git a/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py b/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py index dc519bc4720..d307805427a 100644 --- a/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py +++ b/litellm/proxy/ui_crud_endpoints/proxy_setting_endpoints.py @@ -52,6 +52,7 @@ from litellm.repositories.table_repositories import ( ) from litellm.repositories.team_repository import TeamRepository from litellm.secret_managers.main import get_secret +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.mcp import MCPToolSearchSettings from litellm.types.proxy.management_endpoints.ui_sso import ( DefaultTeamSSOParams, @@ -168,11 +169,11 @@ def _resolve_ui_theme_field(stored_values: Mapping[str, object], field_name: str return env_value if _is_public_http_url(env_value) else None -class IPAddress(BaseModel): +class IPAddress(LiteLLMBaseModel): ip: str -class UIThemeConfig(BaseModel): +class UIThemeConfig(LiteLLMBaseModel): """Configuration for UI theme customization""" # Logo configuration @@ -196,7 +197,7 @@ class UIThemeConfig(BaseModel): ) -class SettingsResponse(BaseModel): +class SettingsResponse(LiteLLMBaseModel): """Base response model for settings with values and schema information""" values: dict[str, object] @@ -206,7 +207,7 @@ class SettingsResponse(BaseModel): """Schema information including descriptions and property types for UI display""" -class _SettingsWithSchema(BaseModel): +class _SettingsWithSchema(LiteLLMBaseModel): values: dict[str, object] field_schema: dict[str, object] @@ -233,7 +234,7 @@ class UIThemeSettingsResponse(SettingsResponse): _TEAM_ADMIN_FIELD_ENUM: Final = tuple(sorted(SUPPORTED_TEAM_ADMIN_PERMISSIONS)) -class UISettings(BaseModel): +class UISettings(LiteLLMBaseModel): """Configuration for UI-specific flags""" model_config = ConfigDict(extra="allow") @@ -476,7 +477,7 @@ def _get_effective_ui_settings_class() -> type[UISettings]: return _EFFECTIVE_UI_SETTINGS_CLASS -class MCPSemanticFilterSettings(BaseModel): +class MCPSemanticFilterSettings(LiteLLMBaseModel): """Configuration for MCP Semantic Tool Filter""" enabled: bool = Field( @@ -512,7 +513,7 @@ class MCPToolSearchSettingsResponse(SettingsResponse): """Response model for native MCP tool search settings""" -class WebSearchInterceptionSettings(BaseModel): +class WebSearchInterceptionSettings(LiteLLMBaseModel): """Configuration for server-side web search interception""" enabled: bool = Field( diff --git a/litellm/proxy/ui_crud_endpoints/user_banner_endpoints.py b/litellm/proxy/ui_crud_endpoints/user_banner_endpoints.py index 0ff61592d9f..56339202d46 100644 --- a/litellm/proxy/ui_crud_endpoints/user_banner_endpoints.py +++ b/litellm/proxy/ui_crud_endpoints/user_banner_endpoints.py @@ -3,12 +3,13 @@ import json from typing import Annotated, Final, Literal from fastapi import APIRouter, Depends, HTTPException -from pydantic import BaseModel, Field, ValidationError, model_validator +from pydantic import Field, ValidationError, model_validator from litellm._uuid import uuid4 from litellm.proxy._types import LitellmTableNames, LitellmUserRoles, UserAPIKeyAuth from litellm.proxy.auth.user_api_key_auth import user_api_key_auth from litellm.repositories.user_banner_repository import USER_BANNER_ROW_ID, UserBannerRepository +from litellm.types.llms.base import LiteLLMBaseModel router: Final = APIRouter() @@ -17,7 +18,7 @@ USER_BANNER_MAX_MESSAGE_LENGTH: Final = 4000 UserBannerSeverity = Literal["info", "warning", "error"] -class UserBannerUpdate(BaseModel): +class UserBannerUpdate(LiteLLMBaseModel): enabled: bool = Field( default=False, description="If true, the banner is shown to all authenticated dashboard users.", @@ -49,7 +50,7 @@ class UserBanner(UserBannerUpdate): ) -class UpdateUserBannerResponse(BaseModel): +class UpdateUserBannerResponse(LiteLLMBaseModel): message: str banner: UserBanner diff --git a/litellm/rag/ingestion/gemini_ingestion.py b/litellm/rag/ingestion/gemini_ingestion.py index a015f3cf614..4ee16685e03 100644 --- a/litellm/rag/ingestion/gemini_ingestion.py +++ b/litellm/rag/ingestion/gemini_ingestion.py @@ -9,7 +9,7 @@ from __future__ import annotations from typing import TYPE_CHECKING, Final, cast -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict from litellm._logging import verbose_logger from litellm.llms.custom_httpx.http_handler import ( @@ -19,13 +19,14 @@ from litellm.llms.custom_httpx.http_handler import ( ) from litellm.llms.gemini.common_utils import GeminiModelInfo from litellm.rag.ingestion.base_ingestion import BaseRAGIngestion +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: from litellm import Router from litellm.types.rag import RAGIngestOptions -class _WhiteSpaceConfig(BaseModel): +class _WhiteSpaceConfig(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore", frozen=True, hide_input_in_errors=True) max_tokens_per_chunk: object = 800 diff --git a/litellm/responses/additional_tools.py b/litellm/responses/additional_tools.py index 5239bd395cc..4b897ff58c0 100644 --- a/litellm/responses/additional_tools.py +++ b/litellm/responses/additional_tools.py @@ -2,19 +2,20 @@ from collections.abc import Sequence from dataclasses import dataclass from typing import Final, cast # noqa: TID251 # validating the openai tool union strips vendor keys from raw tools -from pydantic import BaseModel, ValidationError +from pydantic import ValidationError from litellm._logging import verbose_logger +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import ALL_RESPONSES_API_TOOL_PARAMS, ResponseInputParam ADDITIONAL_TOOLS_INPUT_ITEM_TYPE: Final = "additional_tools" -class _InputItemType(BaseModel): +class _InputItemType(LiteLLMBaseModel): type: str = "" -class _AdditionalToolsItem(BaseModel): +class _AdditionalToolsItem(LiteLLMBaseModel): tools: tuple[dict[str, object], ...] = () diff --git a/litellm/responses/litellm_completion_transformation/custom_tools.py b/litellm/responses/litellm_completion_transformation/custom_tools.py index 7888a07e248..1943dda09b3 100644 --- a/litellm/responses/litellm_completion_transformation/custom_tools.py +++ b/litellm/responses/litellm_completion_transformation/custom_tools.py @@ -20,8 +20,9 @@ from collections.abc import Mapping, Sequence from types import MappingProxyType from typing import Final -from pydantic import BaseModel, TypeAdapter, ValidationError +from pydantic import TypeAdapter, ValidationError +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import ( ChatCompletionToolParam, ChatCompletionToolParamFunctionChunk, @@ -39,7 +40,7 @@ def openai_shaped_tool_call_item_id(item_type: str, tool_id: str) -> str: return f"{prefix}_{tool_id}" -class _ToolNameFields(BaseModel): +class _ToolNameFields(LiteLLMBaseModel): type: str = "" name: str = "" tools: tuple[object, ...] = () @@ -151,7 +152,7 @@ def build_tool_call_item_kwargs( return kwargs -class _CustomToolFormat(BaseModel): +class _CustomToolFormat(LiteLLMBaseModel): syntax: str = "" definition: str = "" diff --git a/litellm/router_strategy/auto_router/auto_router.py b/litellm/router_strategy/auto_router/auto_router.py index 250201a46d1..6b97276a079 100644 --- a/litellm/router_strategy/auto_router/auto_router.py +++ b/litellm/router_strategy/auto_router/auto_router.py @@ -6,7 +6,7 @@ import asyncio from collections.abc import Mapping, Sequence from typing import TYPE_CHECKING, Any, Final, Optional -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict from litellm._logging import verbose_router_logger from litellm.constants import DEFAULT_AUTO_ROUTER_MAX_INPUT_CHARS @@ -16,6 +16,7 @@ from litellm.litellm_core_utils.internal_call_metadata import ( forwarded_internal_call_metadata, parent_session_kwargs, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import AUTOROUTER_CLASSIFIER_CALL_ORIGIN if TYPE_CHECKING: @@ -33,7 +34,7 @@ else: LiteLLMRouterEncoder = Any -class _CallerMetadata(BaseModel): +class _CallerMetadata(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="ignore") metadata: Mapping[str, object] | None = None diff --git a/litellm/router_strategy/complexity_router/capability_classifier.py b/litellm/router_strategy/complexity_router/capability_classifier.py index 93077af9e47..717e8d389a3 100644 --- a/litellm/router_strategy/complexity_router/capability_classifier.py +++ b/litellm/router_strategy/complexity_router/capability_classifier.py @@ -9,7 +9,9 @@ from sys import float_info from types import MappingProxyType from typing import Final, Literal, NamedTuple, TypeAlias -from pydantic import BaseModel, ConfigDict, Field, StrictFloat, TypeAdapter, model_validator +from pydantic import ConfigDict, Field, StrictFloat, TypeAdapter, model_validator + +from litellm.types.llms.base import LiteLLMBaseModel CapabilityBoundary: TypeAlias = Literal["supported", "uncertain", "unsupported", "unmatched"] CapabilityRule: TypeAlias = Literal[ @@ -111,7 +113,7 @@ _RULE_BOUNDARIES: Final = MappingProxyType( ) -class CapabilityClassifierVerdict(BaseModel): +class CapabilityClassifierVerdict(LiteLLMBaseModel): """Strict structured verdict returned by the capability forecaster.""" model_config = ConfigDict(extra="forbid", frozen=True) diff --git a/litellm/router_strategy/complexity_router/complexity_router.py b/litellm/router_strategy/complexity_router/complexity_router.py index 43200271f9f..5600f4c9354 100644 --- a/litellm/router_strategy/complexity_router/complexity_router.py +++ b/litellm/router_strategy/complexity_router/complexity_router.py @@ -65,6 +65,7 @@ from litellm.router_strategy.complexity_router.tier_predictor import ( ) from litellm.router_utils.pre_call_checks.deployment_affinity_check import DeploymentAffinityCheck from litellm.secret_managers.main import get_secret_str +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.custom_http import httpxSpecialProvider from litellm.types.llms.openai import ( AllMessageValues, @@ -136,13 +137,13 @@ else: SemanticRouter = Any -class TierClassification(BaseModel): +class TierClassification(LiteLLMBaseModel): """Structured response schema for the LLM-based complexity classifier.""" tier: Literal["SIMPLE", "MEDIUM", "COMPLEX", "REASONING"] -class _LabeledTierClassification(BaseModel): +class _LabeledTierClassification(LiteLLMBaseModel): """Parses the classifier's reply when the wire carries operator-chosen tier strings.""" tier: str diff --git a/litellm/router_strategy/complexity_router/config.py b/litellm/router_strategy/complexity_router/config.py index 8d00b45fed0..bd067892ddc 100644 --- a/litellm/router_strategy/complexity_router/config.py +++ b/litellm/router_strategy/complexity_router/config.py @@ -15,7 +15,6 @@ from types import MappingProxyType from typing import Annotated, Final, Literal, NamedTuple from pydantic import ( - BaseModel, ConfigDict, Field, SkipValidation, @@ -26,6 +25,8 @@ from pydantic import ( model_validator, ) +from litellm.types.llms.base import LiteLLMBaseModel + with warnings.catch_warnings(): warnings.simplefilter("ignore", DeprecationWarning) import sre_constants @@ -96,7 +97,7 @@ DEFAULT_CLASSIFIER_CONTEXT_WINDOW_SIZE: Final[int] = 3 DEFAULT_CLASSIFIER_CONTEXT_BUDGET_CHARS: Final[int] = 8000 -class KeywordTierRule(BaseModel): +class KeywordTierRule(LiteLLMBaseModel): """A deterministic override: if any keyword matches, route to this tier.""" keywords: list[str] = Field( @@ -173,7 +174,7 @@ def normalize_classification_examples(value: str | None) -> str | None: _BUILT_IN_TIER_NAMES: Final[str] = ", ".join(ComplexityTier.__members__) -class TierDefinition(BaseModel): +class TierDefinition(LiteLLMBaseModel): """An operator-defined tier: the name the LLM classifier must return and its rubric description.""" name: str = Field( @@ -217,7 +218,7 @@ class TierDefinition(BaseModel): return self -class ReminderMarkerPair(BaseModel): +class ReminderMarkerPair(LiteLLMBaseModel): """One open/close delimiter pair a harness wraps injected context in. Normalizing here rather than at the scan is what makes matching case-insensitive: markers reach @@ -241,7 +242,7 @@ class ReminderMarkerPair(BaseModel): return self -class ComplexityTierModel(BaseModel): +class ComplexityTierModel(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) model_name: str @@ -477,7 +478,7 @@ DEFAULT_TIER_MODELS: Final[dict[str, str]] = { } -class ClassifierVisionConfig(BaseModel): +class ClassifierVisionConfig(LiteLLMBaseModel): """Whether the LLM classifier sees the images on the request it is classifying. Off by default because images cost far more than the text ask they arrive with, and the @@ -508,7 +509,7 @@ class ClassifierVisionConfig(BaseModel): ) -class ClassifierLLMConfig(BaseModel): +class ClassifierLLMConfig(LiteLLMBaseModel): """Configuration for the LLM-based complexity classifier.""" model: str = Field( @@ -604,7 +605,7 @@ class ClassifierLLMConfig(BaseModel): return self -class CapabilityCalibrationConfig(BaseModel): +class CapabilityCalibrationConfig(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True) version: str = Field(min_length=1, max_length=128, pattern=r"^\S(?:.*\S)?$") @@ -617,7 +618,7 @@ class CapabilityCalibrationConfig(BaseModel): return 1.0 / (1.0 + math.exp(-log_odds)) -class CapabilityClassifierConfig(BaseModel): +class CapabilityClassifierConfig(LiteLLMBaseModel): """Switchyard-compatible probability threshold policy for two model tiers.""" model_config = ConfigDict(extra="forbid", frozen=True) @@ -695,7 +696,7 @@ def normalize_classifier_config_aliases(config: Mapping[str, object]) -> Mapping return normalized -class OpenSourceClassifierConfig(BaseModel): +class OpenSourceClassifierConfig(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True) provider: Literal["jev", "laya", "bespoke"] = "jev" @@ -904,7 +905,7 @@ def custom_pattern_work(pattern: str) -> int | str: return cost if isinstance(cost, str) else cost.steps -class CustomDimension(BaseModel): +class CustomDimension(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True) name: str = Field(min_length=1, max_length=64, pattern=r"^[A-Za-z][A-Za-z0-9_]*$") @@ -940,7 +941,7 @@ class CustomDimension(BaseModel): ) -class ContextCompactionConfig(BaseModel): +class ContextCompactionConfig(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="forbid") model: str | None = Field(default=None, min_length=1) @@ -949,7 +950,7 @@ class ContextCompactionConfig(BaseModel): timeout_seconds: float = Field(default=120, gt=0) -class ComplexityRouterConfig(BaseModel): +class ComplexityRouterConfig(LiteLLMBaseModel): """Configuration for the ComplexityRouter.""" @model_validator(mode="before") diff --git a/litellm/router_strategy/complexity_router/fuse_presets.py b/litellm/router_strategy/complexity_router/fuse_presets.py index 66a96ec5ad5..3bb0f2b41d8 100644 --- a/litellm/router_strategy/complexity_router/fuse_presets.py +++ b/litellm/router_strategy/complexity_router/fuse_presets.py @@ -2,12 +2,14 @@ from functools import lru_cache from importlib.resources import files from typing import Annotated, Final, Literal, TypeAlias -from pydantic import BaseModel, ConfigDict, Field, StringConstraints +from pydantic import ConfigDict, Field, StringConstraints + +from litellm.types.llms.base import LiteLLMBaseModel ProfileText: TypeAlias = Annotated[str, StringConstraints(strip_whitespace=True, min_length=1, max_length=4000)] -class FuseModelPreset(BaseModel): +class FuseModelPreset(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True) id: str @@ -17,7 +19,7 @@ class FuseModelPreset(BaseModel): model: str -class FuseHarnessPreset(BaseModel): +class FuseHarnessPreset(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True) id: str @@ -26,7 +28,7 @@ class FuseHarnessPreset(BaseModel): sources: tuple[str, ...] = Field(min_length=1) -class FusePresetCatalog(BaseModel): +class FusePresetCatalog(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True) version: str diff --git a/litellm/router_strategy/complexity_router/jev_classifier.py b/litellm/router_strategy/complexity_router/jev_classifier.py index 2b97ae824dd..93c8b0c1bd3 100644 --- a/litellm/router_strategy/complexity_router/jev_classifier.py +++ b/litellm/router_strategy/complexity_router/jev_classifier.py @@ -5,7 +5,7 @@ from typing import Annotated, Final, Literal, NamedTuple, Protocol, TypeAlias from uuid import uuid4 import httpx -from pydantic import BaseModel, ConfigDict, Field, TypeAdapter, ValidationError +from pydantic import ConfigDict, Field, TypeAdapter, ValidationError import litellm from litellm._logging import verbose_router_logger @@ -23,13 +23,14 @@ from litellm.proxy.pass_through_endpoints.llm_provider_handlers.typesafe_passthr TypeSafePassthroughLoggingHandler, ) from litellm.router_strategy.complexity_router.config import DEFAULT_JEV_INSTRUCTIONS as _DEFAULT_JEV_INSTRUCTIONS +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import AUTOROUTER_CLASSIFIER_CALL_ORIGIN JevProbability: TypeAlias = Annotated[float, Field(ge=0.0, le=1.0)] DEFAULT_JEV_INSTRUCTIONS: Final = _DEFAULT_JEV_INSTRUCTIONS -class JevChoiceQuestion(BaseModel): +class JevChoiceQuestion(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) type: Literal["choice"] = "choice" @@ -37,7 +38,7 @@ class JevChoiceQuestion(BaseModel): criteria: Mapping[str, str] -class JevSystemOneRequest(BaseModel): +class JevSystemOneRequest(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) state: str @@ -45,7 +46,7 @@ class JevSystemOneRequest(BaseModel): questions: Mapping[str, JevChoiceQuestion] -class JevChoiceAnswer(BaseModel): +class JevChoiceAnswer(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, allow_inf_nan=False) type: Literal["choice"] @@ -54,14 +55,14 @@ class JevChoiceAnswer(BaseModel): confidence: JevProbability -class JevUsage(BaseModel): +class JevUsage(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) input_tokens: int = Field(default=0, ge=0, strict=True) output_tokens: int = Field(default=0, ge=0, strict=True) -class JevSystemOneResponse(BaseModel): +class JevSystemOneResponse(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) model: str | None = None @@ -204,7 +205,7 @@ class JevVerdict(NamedTuple): provider: Literal["typesafe", "laya", "bespoke"] = "typesafe" -class _RegistryPricing(BaseModel): +class _RegistryPricing(LiteLLMBaseModel): input_cost_per_token: float = 0.0 output_cost_per_token: float = 0.0 diff --git a/litellm/router_strategy/complexity_router/llm_v2.py b/litellm/router_strategy/complexity_router/llm_v2.py index 8ef2f554ab2..c63d05de72b 100644 --- a/litellm/router_strategy/complexity_router/llm_v2.py +++ b/litellm/router_strategy/complexity_router/llm_v2.py @@ -7,13 +7,14 @@ from dataclasses import dataclass from sys import float_info from typing import Annotated, Final, Literal, TypeAlias -from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StringConstraints, TypeAdapter, model_validator +from pydantic import ConfigDict, Field, StrictFloat, StringConstraints, TypeAdapter, model_validator from typing_extensions import ReadOnly, TypedDict from litellm.llms.base_llm.base_utils import ( type_to_response_format_param, # pyright: ignore[reportUnknownVariableType] # legacy output validated below ) from litellm.router_strategy.complexity_router.fuse_presets import ProfileText, resolve_fuse_profile +from litellm.types.llms.base import LiteLLMBaseModel ShortText: TypeAlias = Annotated[str, StringConstraints(strip_whitespace=True, min_length=1, max_length=512)] VerdictText: TypeAlias = Annotated[str, StringConstraints(strip_whitespace=True, min_length=1)] @@ -80,7 +81,7 @@ these forecasts are calibrated. Do not optimize cost or output a selected model. Return only JSON matching the response schema. Keep text fields concise.""" -class LLMV2Demands(BaseModel): +class LLMV2Demands(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True) reasoning: Literal["routine", "multistep", "open_ended", "unknown"] @@ -88,21 +89,21 @@ class LLMV2Demands(BaseModel): specification: Literal["clear", "ambiguous", "unknown"] -class LLMV2SolverForecast(BaseModel): +class LLMV2SolverForecast(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True) likely_failure: VerdictText p_solve: StrictFloat = Field(ge=0.0, le=1.0) -class LLMV2SolverForecasts(BaseModel): +class LLMV2SolverForecasts(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True) efficient: LLMV2SolverForecast capable: LLMV2SolverForecast -class LLMV2Verdict(BaseModel): +class LLMV2Verdict(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True) crux: VerdictText @@ -111,7 +112,7 @@ class LLMV2Verdict(BaseModel): forecasts: LLMV2SolverForecasts -class LLMV2ProbabilityCalibration(BaseModel): +class LLMV2ProbabilityCalibration(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True) slope: float = Field(gt=0.0, allow_inf_nan=False) @@ -126,7 +127,7 @@ class LLMV2ProbabilityCalibration(BaseModel): return exponential / (1.0 + exponential) -class LLMV2Calibration(BaseModel): +class LLMV2Calibration(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True) version: ShortText @@ -135,7 +136,7 @@ class LLMV2Calibration(BaseModel): capable: LLMV2ProbabilityCalibration -class LLMV2Config(BaseModel): +class LLMV2Config(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid", frozen=True) efficient_tier: str = "SIMPLE" diff --git a/litellm/router_strategy/complexity_router/tier_predictor.py b/litellm/router_strategy/complexity_router/tier_predictor.py index 7775c36e795..246e58dbadf 100644 --- a/litellm/router_strategy/complexity_router/tier_predictor.py +++ b/litellm/router_strategy/complexity_router/tier_predictor.py @@ -7,12 +7,13 @@ from pathlib import Path from types import MappingProxyType from typing import Final, Literal -from pydantic import BaseModel, Field, model_validator +from pydantic import Field, model_validator +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.router import RequestType -class TierGlobalStatistic(BaseModel): +class TierGlobalStatistic(LiteLLMBaseModel): tier: int = Field(ge=1, le=4) successes: float = Field(ge=0.0) observations: float = Field(gt=0.0) @@ -32,7 +33,7 @@ class TierCohortStatistic(TierGlobalStatistic): cohort: str = Field(min_length=1) -class TierDataset(BaseModel): +class TierDataset(LiteLLMBaseModel): name: str = Field(min_length=1) url: str = Field(min_length=1) license: str = Field(min_length=1) @@ -40,7 +41,7 @@ class TierDataset(BaseModel): success_definition: str = Field(default="quality score meets the dataset success threshold", min_length=1) -class TrainedTierArtifact(BaseModel): +class TrainedTierArtifact(LiteLLMBaseModel): schema_version: Literal[1] = 1 global_statistics: tuple[TierGlobalStatistic, ...] domain_statistics: tuple[TierDomainStatistic, ...] = () diff --git a/litellm/router_strategy/quality_router/config.py b/litellm/router_strategy/quality_router/config.py index e07a6962d72..6e04a804c34 100644 --- a/litellm/router_strategy/quality_router/config.py +++ b/litellm/router_strategy/quality_router/config.py @@ -4,7 +4,9 @@ Configuration models for the QualityRouter. from typing import Final -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field + +from litellm.types.llms.base import LiteLLMBaseModel # Default mapping from ComplexityTier name (string) to quality tier (int). # Higher tier = higher capability requirement. @@ -16,7 +18,7 @@ DEFAULT_COMPLEXITY_TO_QUALITY: Final[dict[str, int]] = { } -class QualityRouterConfig(BaseModel): +class QualityRouterConfig(LiteLLMBaseModel): """Configuration for the QualityRouter.""" available_models: list[str] = Field( @@ -40,7 +42,7 @@ class QualityRouterConfig(BaseModel): model_config = ConfigDict(extra="allow") -class RoutingPreferences(BaseModel): +class RoutingPreferences(LiteLLMBaseModel): """Per-deployment routing preferences declared on model_info.""" quality_tier: int = Field( diff --git a/litellm/rust_bridge/trace/generated/models.py b/litellm/rust_bridge/trace/generated/models.py index db7b76eba96..ea2c8bda648 100644 --- a/litellm/rust_bridge/trace/generated/models.py +++ b/litellm/rust_bridge/trace/generated/models.py @@ -4,10 +4,12 @@ from __future__ import annotations from typing import Annotated, Literal, TypeAlias -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field + +from litellm.types.llms.base import LiteLLMBaseModel -class ActivityAvailability(BaseModel): +class ActivityAvailability(LiteLLMBaseModel): model_config = ConfigDict( frozen=True, ) @@ -16,7 +18,7 @@ class ActivityAvailability(BaseModel): requests: bool = False -class AgentRow(BaseModel): +class AgentRow(LiteLLMBaseModel): model_config = ConfigDict( frozen=True, ) @@ -57,7 +59,7 @@ Count1: TypeAlias = Annotated[ ] -class CountRow(BaseModel): +class CountRow(LiteLLMBaseModel): model_config = ConfigDict( frozen=True, ) @@ -170,7 +172,7 @@ Selected1: TypeAlias = Annotated[ ] -class ExecutionRow(BaseModel): +class ExecutionRow(LiteLLMBaseModel): model_config = ConfigDict( frozen=True, ) @@ -190,7 +192,7 @@ class ExecutionRow(BaseModel): selection_key: str = "" -class LensAccessParams(BaseModel): +class LensAccessParams(LiteLLMBaseModel): model_config = ConfigDict( extra="forbid", frozen=True, @@ -201,7 +203,7 @@ class LensAccessParams(BaseModel): key_hash: str -class LensContentParams(BaseModel): +class LensContentParams(LiteLLMBaseModel): model_config = ConfigDict( extra="forbid", frozen=True, @@ -218,7 +220,7 @@ class LensContentParams(BaseModel): offset: int = Field(..., ge=0, le=4294967295) -class LensEvidenceParams(BaseModel): +class LensEvidenceParams(LiteLLMBaseModel): model_config = ConfigDict( extra="forbid", frozen=True, @@ -238,7 +240,7 @@ class LensEvidenceParams(BaseModel): ExecutionSource: TypeAlias = Literal["traces", "requests", "both"] -class LensSampleParams(BaseModel): +class LensSampleParams(LiteLLMBaseModel): model_config = ConfigDict( extra="forbid", frozen=True, @@ -264,7 +266,7 @@ class LensSampleParams(BaseModel): offset: int = Field(..., ge=0, le=18446744073709551615) -class PartRow(BaseModel): +class PartRow(LiteLLMBaseModel): model_config = ConfigDict( frozen=True, ) @@ -282,7 +284,7 @@ class PartRow(BaseModel): TraceTableName: TypeAlias = Literal["otel_traces", "agent_traces_by_key", "spend_logs"] -class TraceQueryColumn(BaseModel): +class TraceQueryColumn(LiteLLMBaseModel): model_config = ConfigDict( extra="allow", frozen=True, @@ -292,7 +294,7 @@ class TraceQueryColumn(BaseModel): type: str -class TraceQueryNormalizedField(BaseModel): +class TraceQueryNormalizedField(LiteLLMBaseModel): model_config = ConfigDict( extra="forbid", frozen=True, @@ -317,7 +319,7 @@ MetadataValueType: TypeAlias = Literal["array", "boolean", "integer", "null", "n MapValueType: TypeAlias = Literal["String"] -class TraceQueryRelationship(BaseModel): +class TraceQueryRelationship(LiteLLMBaseModel): model_config = ConfigDict( extra="forbid", frozen=True, @@ -329,7 +331,7 @@ class TraceQueryRelationship(BaseModel): meaning: str -class TraceQueryExample(BaseModel): +class TraceQueryExample(LiteLLMBaseModel): model_config = ConfigDict( frozen=True, ) @@ -338,7 +340,7 @@ class TraceQueryExample(BaseModel): sql: str -class TraceQueryTable(BaseModel): +class TraceQueryTable(LiteLLMBaseModel): model_config = ConfigDict( extra="forbid", frozen=True, @@ -348,7 +350,7 @@ class TraceQueryTable(BaseModel): columns: tuple[TraceQueryColumn, ...] -class TraceQueryMetadataField(BaseModel): +class TraceQueryMetadataField(LiteLLMBaseModel): model_config = ConfigDict( extra="forbid", frozen=True, @@ -359,7 +361,7 @@ class TraceQueryMetadataField(BaseModel): expression: str -class TraceQueryAttributeField(BaseModel): +class TraceQueryAttributeField(LiteLLMBaseModel): model_config = ConfigDict( extra="forbid", frozen=True, @@ -370,7 +372,7 @@ class TraceQueryAttributeField(BaseModel): expression: str -class TraceQueryMetadata(BaseModel): +class TraceQueryMetadata(LiteLLMBaseModel): model_config = ConfigDict( extra="forbid", frozen=True, @@ -387,7 +389,7 @@ class TraceQueryMetadata(BaseModel): scope: str -class TraceQueryAttributes(BaseModel): +class TraceQueryAttributes(LiteLLMBaseModel): model_config = ConfigDict( extra="forbid", frozen=True, @@ -402,7 +404,7 @@ class TraceQueryAttributes(BaseModel): scope: str -class TraceQueryHelp(BaseModel): +class TraceQueryHelp(LiteLLMBaseModel): model_config = ConfigDict( extra="forbid", frozen=True, diff --git a/litellm/rust_bridge/trace/generated/requests.py b/litellm/rust_bridge/trace/generated/requests.py index dd5304ea09b..9c30049ce14 100644 --- a/litellm/rust_bridge/trace/generated/requests.py +++ b/litellm/rust_bridge/trace/generated/requests.py @@ -4,10 +4,12 @@ from __future__ import annotations from typing import Annotated, TypeAlias -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field + +from litellm.types.llms.base import LiteLLMBaseModel -class TraceDetailRequest(BaseModel): +class TraceDetailRequest(LiteLLMBaseModel): model_config = ConfigDict( frozen=True, ) @@ -17,7 +19,7 @@ class TraceDetailRequest(BaseModel): page_size: int | None = Field(None, ge=1, le=500) -class TraceErrorPageRequest(BaseModel): +class TraceErrorPageRequest(LiteLLMBaseModel): model_config = ConfigDict( frozen=True, ) @@ -26,7 +28,7 @@ class TraceErrorPageRequest(BaseModel): cursor: str | None = Field(None, max_length=512) -class TraceListRequest(BaseModel): +class TraceListRequest(LiteLLMBaseModel): model_config = ConfigDict( frozen=True, ) @@ -36,7 +38,7 @@ class TraceListRequest(BaseModel): cursor: str | None = Field(None, max_length=512) -class TraceQueryRequest(BaseModel): +class TraceQueryRequest(LiteLLMBaseModel): model_config = ConfigDict( extra="forbid", frozen=True, @@ -45,7 +47,7 @@ class TraceQueryRequest(BaseModel): sql: str -class TraceSpanRequest(BaseModel): +class TraceSpanRequest(LiteLLMBaseModel): model_config = ConfigDict( frozen=True, ) diff --git a/litellm/rust_bridge/trace/generated/responses.py b/litellm/rust_bridge/trace/generated/responses.py index b6de931c7ad..38dee46b305 100644 --- a/litellm/rust_bridge/trace/generated/responses.py +++ b/litellm/rust_bridge/trace/generated/responses.py @@ -5,10 +5,12 @@ from __future__ import annotations from collections.abc import Mapping from typing import Annotated, TypeAlias -from pydantic import BaseModel, ConfigDict, Field, JsonValue +from pydantic import ConfigDict, Field, JsonValue + +from litellm.types.llms.base import LiteLLMBaseModel -class TraceSQLResponse(BaseModel): +class TraceSQLResponse(LiteLLMBaseModel): model_config = ConfigDict( extra="forbid", frozen=True, diff --git a/litellm/rust_bridge/trace/queries.py b/litellm/rust_bridge/trace/queries.py index 681b6af9f7e..42d6430782f 100644 --- a/litellm/rust_bridge/trace/queries.py +++ b/litellm/rust_bridge/trace/queries.py @@ -4,6 +4,8 @@ from typing import Final, Generic, TypeVar from pydantic import BaseModel, ConfigDict, JsonValue, TypeAdapter +from litellm.types.llms.base import LiteLLMBaseModel + from .generated.models import ( ActivityAvailability, AgentRow, @@ -21,14 +23,14 @@ from .generated.types import ReadQueryName _RESPONSE_CONFIG: Final = ConfigDict(frozen=True, extra="allow") -class TraceQueryStatistics(BaseModel): +class TraceQueryStatistics(LiteLLMBaseModel): model_config = _RESPONSE_CONFIG elapsed: float rows_read: int | str bytes_read: int | str -class ClickHouseSQLEnvelope(BaseModel): +class ClickHouseSQLEnvelope(LiteLLMBaseModel): model_config = _RESPONSE_CONFIG meta: tuple[TraceQueryColumn, ...] data: tuple[Mapping[str, JsonValue], ...] @@ -40,7 +42,7 @@ ParamsT: Final = TypeVar("ParamsT", bound=BaseModel) RowT: Final = TypeVar("RowT") -class QueryResponse(BaseModel, Generic[RowT]): +class QueryResponse(LiteLLMBaseModel, Generic[RowT]): model_config = ConfigDict(frozen=True) data: tuple[RowT, ...] diff --git a/litellm/scheduler.py b/litellm/scheduler.py index e19e386f527..c88cc4ce0c0 100644 --- a/litellm/scheduler.py +++ b/litellm/scheduler.py @@ -2,12 +2,11 @@ import enum import heapq from typing import Final -from pydantic import BaseModel - from litellm import print_verbose from litellm._internal_context import with_service_target from litellm.caching.caching import DualCache, RedisCache from litellm.constants import DEFAULT_IN_MEMORY_TTL, DEFAULT_POLLING_INTERVAL +from litellm.types.llms.base import LiteLLMBaseModel SCHEDULER_QUEUE_TARGET: Final = "scheduler_queue" @@ -17,7 +16,7 @@ class SchedulerCacheKeys(enum.Enum): default_in_memory_ttl = DEFAULT_IN_MEMORY_TTL # cache queue in-memory for 5s when redis cache available -class FlowItem(BaseModel): +class FlowItem(LiteLLMBaseModel): priority: int # Priority between 0 and 255 request_id: str model_name: str diff --git a/litellm/secret_managers/main.py b/litellm/secret_managers/main.py index 275c029b0b7..a8420d3cbc6 100644 --- a/litellm/secret_managers/main.py +++ b/litellm/secret_managers/main.py @@ -6,7 +6,7 @@ import traceback from typing import Final import httpx -from pydantic import BaseModel, TypeAdapter, ValidationError +from pydantic import TypeAdapter, ValidationError import litellm from litellm._logging import verbose_logger @@ -16,6 +16,7 @@ from litellm.secret_managers.dispatch import get_secret_from_manager from litellm.secret_managers.get_azure_ad_token_provider import ( get_azure_ad_token_provider, ) +from litellm.types.llms.base import LiteLLMBaseModel oidc_cache: Final = DualCache() @@ -25,7 +26,7 @@ _PARSED_LITERAL: Final = TypeAdapter(object) _OIDC_TOKEN_EXPIRY_MARGIN_SECONDS: Final = 60 -class _OidcTokenClaims(BaseModel): +class _OidcTokenClaims(LiteLLMBaseModel): exp: float | None = None diff --git a/litellm/types/access_group.py b/litellm/types/access_group.py index 951e5a414b4..b4bf345ecbe 100644 --- a/litellm/types/access_group.py +++ b/litellm/types/access_group.py @@ -1,9 +1,9 @@ from datetime import datetime -from pydantic import BaseModel +from litellm.types.llms.base import LiteLLMBaseModel -class AccessGroupCreateRequest(BaseModel): +class AccessGroupCreateRequest(LiteLLMBaseModel): access_group_name: str description: str | None = None access_model_names: list[str] | None = None @@ -13,7 +13,7 @@ class AccessGroupCreateRequest(BaseModel): assigned_key_ids: list[str] | None = None -class AccessGroupUpdateRequest(BaseModel): +class AccessGroupUpdateRequest(LiteLLMBaseModel): access_group_name: str | None = None description: str | None = None access_model_names: list[str] | None = None @@ -23,14 +23,14 @@ class AccessGroupUpdateRequest(BaseModel): assigned_key_ids: list[str] | None = None -class AccessGroupResource(BaseModel): +class AccessGroupResource(LiteLLMBaseModel): """A resource referenced by an access group. `name` is null when the id no longer resolves or has no alias.""" id: str name: str | None -class AccessGroupResponse(BaseModel): +class AccessGroupResponse(LiteLLMBaseModel): access_group_id: str access_group_name: str description: str | None = None diff --git a/litellm/types/agents.py b/litellm/types/agents.py index 94adb9f7c4a..badaf20dba0 100644 --- a/litellm/types/agents.py +++ b/litellm/types/agents.py @@ -3,10 +3,10 @@ from datetime import datetime from typing import TYPE_CHECKING, Annotated, Any, Final, Literal, TypeAlias from urllib.parse import urlsplit -from pydantic import BaseModel, ConfigDict, Field, PrivateAttr, StrictInt, field_validator +from pydantic import ConfigDict, Field, PrivateAttr, StrictInt, field_validator from typing_extensions import ReadOnly, Required, TypedDict -from litellm.types.llms.base import LiteLLMPydanticObjectBase +from litellm.types.llms.base import LiteLLMBaseModel, LiteLLMPydanticObjectBase from litellm.types.proxy.agent_identity import ( AgentExecutionMode, AgentIdentityBinding, @@ -184,14 +184,14 @@ class AgentObjectPermission(TypedDict, total=False): agents: list[str] | None -class AgentKillSwitchBearerAuth(BaseModel): +class AgentKillSwitchBearerAuth(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="forbid") type: Literal["bearer"] token: str -class AgentKillSwitchApiKeyAuth(BaseModel): +class AgentKillSwitchApiKeyAuth(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="forbid") type: Literal["api_key"] @@ -199,7 +199,7 @@ class AgentKillSwitchApiKeyAuth(BaseModel): api_key: str -class AgentKillSwitchBasicAuth(BaseModel): +class AgentKillSwitchBasicAuth(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="forbid") type: Literal["basic"] @@ -215,7 +215,7 @@ AgentKillSwitchAuth: TypeAlias = Annotated[ AgentKillSwitchMethod: TypeAlias = Literal["POST", "PUT", "PATCH", "DELETE", "GET"] -class AgentKillSwitchConfig(BaseModel): +class AgentKillSwitchConfig(LiteLLMBaseModel): """Webhook an admin fires to shut an agent down out of band. LiteLLM only makes the call; whatever the endpoint does with it is the agent's business.""" @@ -237,7 +237,7 @@ class AgentKillSwitchConfig(BaseModel): return value -class AgentKillSwitchResult(BaseModel): +class AgentKillSwitchResult(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) agent_id: str @@ -292,7 +292,7 @@ AGENT_CALLER_USER_ID_HEADER: Final = "x-litellm-user-id" AGENT_CALLER_TEAM_ID_HEADER: Final = "x-litellm-team-id" -class AgentCaller(BaseModel): +class AgentCaller(LiteLLMBaseModel): """The user and team that invoked an agent, echoed back by the agent on its own proxy calls. Only ever narrows what the agent's key may do.""" @@ -305,13 +305,13 @@ class AgentCaller(BaseModel): # Request/Response models for CRUD endpoints -class AgentKeySummary(BaseModel): +class AgentKeySummary(LiteLLMBaseModel): token: str key_alias: str | None = None key_name: str | None = None -class AgentResponse(BaseModel): +class AgentResponse(LiteLLMBaseModel): identity: AgentIdentityBinding | None = None identity_managed: bool = False enabled: bool = True @@ -339,7 +339,7 @@ class AgentResponse(BaseModel): updated_by: str | None = None -class ListAgentsResponse(BaseModel): +class ListAgentsResponse(LiteLLMBaseModel): agents: list[AgentResponse] @@ -403,13 +403,13 @@ class AgentVersionsResponse(LiteLLMPydanticObjectBase): _hidden_params: dict[str, object] = PrivateAttr(default_factory=dict) -class AgentMakePublicResponse(BaseModel): +class AgentMakePublicResponse(LiteLLMBaseModel): message: str public_agent_groups: list[str] updated_by: str -class MakeAgentsPublicRequest(BaseModel): +class MakeAgentsPublicRequest(LiteLLMBaseModel): agent_ids: list[str] diff --git a/litellm/types/caching.py b/litellm/types/caching.py index 6d42556a9c4..036f7c452ea 100644 --- a/litellm/types/caching.py +++ b/litellm/types/caching.py @@ -2,9 +2,10 @@ from collections.abc import Sequence from enum import Enum from typing import Any, Final, Literal, Optional, Union -from pydantic import BaseModel from typing_extensions import ReadOnly, TypedDict +from litellm.types.llms.base import LiteLLMBaseModel + class LiteLLMCacheType(str, Enum): LOCAL = "local" @@ -114,7 +115,7 @@ DynamicCacheControl = TypedDict( ) -class CachePingResponse(BaseModel): +class CachePingResponse(LiteLLMBaseModel): status: str cache_type: str ping_response: bool | None = None @@ -125,7 +126,7 @@ class CachePingResponse(BaseModel): health_check_cache_params: dict | None = None -class HealthCheckCacheParams(BaseModel): +class HealthCheckCacheParams(LiteLLMBaseModel): """ Cache Params returned on /cache/ping call """ diff --git a/litellm/types/completion.py b/litellm/types/completion.py index 1e6cfc0ee33..156ae96410b 100644 --- a/litellm/types/completion.py +++ b/litellm/types/completion.py @@ -4,9 +4,11 @@ from collections.abc import Callable, Coroutine, Iterable, Mapping from dataclasses import dataclass from typing import TYPE_CHECKING, Any, Literal, Union -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict, Field from typing_extensions import Required, TypedDict +from litellm.types.llms.base import LiteLLMBaseModel + if TYPE_CHECKING: import httpx from aiohttp import ClientSession @@ -172,9 +174,9 @@ ChatCompletionMessageParam = ( ) -class CompletionRequest(BaseModel): +class CompletionRequest(LiteLLMBaseModel): model: str - messages: list[ChatCompletionMessageParam] = [] + messages: list[ChatCompletionMessageParam] = Field(default=[]) timeout: float | int | None = None temperature: float | None = None top_p: float | None = None diff --git a/litellm/types/containers/main.py b/litellm/types/containers/main.py index 62ef524a435..afa07462926 100644 --- a/litellm/types/containers/main.py +++ b/litellm/types/containers/main.py @@ -2,18 +2,20 @@ import builtins from collections.abc import Mapping from typing import Any, Literal -from pydantic import BaseModel +from pydantic import PrivateAttr from typing_extensions import ReadOnly, TypedDict +from litellm.types.llms.base import LiteLLMBaseModel -class ExpiresAfter(BaseModel): + +class ExpiresAfter(LiteLLMBaseModel): """Container expiration settings.""" anchor: Literal["last_active_at"] minutes: int -class ContainerObject(BaseModel): +class ContainerObject(LiteLLMBaseModel): """Represents a container object.""" id: str @@ -23,7 +25,7 @@ class ContainerObject(BaseModel): expires_after: ExpiresAfter | None = None last_active_at: int | None = None name: str | None = None - _hidden_params: dict[str, Any] = {} + _hidden_params: dict[str, Any] = PrivateAttr(default={}) def __contains__(self, key: str) -> bool: # Define custom behavior for the 'in' operator @@ -45,7 +47,7 @@ class ContainerObject(BaseModel): return self.dict() -class DeleteContainerResult(BaseModel): +class DeleteContainerResult(LiteLLMBaseModel): """Result of a delete container request.""" id: str @@ -68,7 +70,7 @@ class DeleteContainerResult(BaseModel): return self.dict() -class ContainerListResponse(BaseModel): +class ContainerListResponse(LiteLLMBaseModel): """Response object for list containers request.""" object: Literal["list"] @@ -130,7 +132,7 @@ class ContainerListOptionalRequestParams(TypedDict, total=False): extra_query: dict[str, str] | None -class ContainerFileObject(BaseModel): +class ContainerFileObject(LiteLLMBaseModel): """Represents a container file object.""" id: str @@ -140,7 +142,7 @@ class ContainerFileObject(BaseModel): created_at: int path: str source: str - _hidden_params: dict[str, builtins.object] = {} + _hidden_params: dict[str, builtins.object] = PrivateAttr(default={}) def __contains__(self, key: str) -> bool: return hasattr(self, key) @@ -158,7 +160,7 @@ class ContainerFileObject(BaseModel): return self.dict() -class ContainerFileListResponse(BaseModel): +class ContainerFileListResponse(LiteLLMBaseModel): """Response object for list container files request.""" object: Literal["list"] @@ -183,7 +185,7 @@ class ContainerFileListResponse(BaseModel): return self.dict() -class DeleteContainerFileResponse(BaseModel): +class DeleteContainerFileResponse(LiteLLMBaseModel): """Response object for delete container file request.""" id: str diff --git a/litellm/types/embedding.py b/litellm/types/embedding.py index cc1f518f20b..27a9903fe78 100644 --- a/litellm/types/embedding.py +++ b/litellm/types/embedding.py @@ -1,9 +1,11 @@ -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict, Field + +from litellm.types.llms.base import LiteLLMBaseModel -class EmbeddingRequest(BaseModel): +class EmbeddingRequest(LiteLLMBaseModel): model: str - input: list[str] = [] + input: list[str] = Field(default=[]) timeout: int = 600 api_base: str | None = None api_version: str | None = None diff --git a/litellm/types/guardrails.py b/litellm/types/guardrails.py index 8f1140cef62..0c7695d0852 100644 --- a/litellm/types/guardrails.py +++ b/litellm/types/guardrails.py @@ -4,10 +4,11 @@ from enum import Enum from types import MappingProxyType from typing import Final, Literal -from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator +from pydantic import ConfigDict, Field, field_validator, model_validator from typing_extensions import ReadOnly, Required, TypedDict from litellm.constants import BEDROCK_APPLY_GUARDRAIL_CHUNK_BUDGET_CHARS +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.guardrails.guardrail_hooks.agent_365 import ( Agent365GuardrailConfigModel, ) @@ -166,7 +167,7 @@ class GuardrailItemSpec(TypedDict, total=False): callback_args: dict[str, dict] -class GuardrailItem(BaseModel): +class GuardrailItem(LiteLLMBaseModel): callbacks: list[str] default_on: bool logging_only: bool | None @@ -436,7 +437,7 @@ class GuardrailParamUITypes(str, Enum): PERCENTAGE = "percentage" -class PresidioPresidioConfigModelUserInterface(BaseModel): +class PresidioPresidioConfigModelUserInterface(LiteLLMBaseModel): """Configuration parameters for the Presidio PII masking guardrail on LiteLLM UI""" presidio_analyzer_api_base: str | None = Field( @@ -545,31 +546,31 @@ BedrockChecksSensitiveInformationEntity = Literal[ ] -class BedrockChecksContentFilterCategoryItem(BaseModel): +class BedrockChecksContentFilterCategoryItem(LiteLLMBaseModel): category: BedrockChecksContentFilterCategory -class BedrockChecksContentFilterModel(BaseModel): +class BedrockChecksContentFilterModel(LiteLLMBaseModel): categories: list[BedrockChecksContentFilterCategoryItem] -class BedrockChecksPromptAttackCategoryItem(BaseModel): +class BedrockChecksPromptAttackCategoryItem(LiteLLMBaseModel): category: BedrockChecksPromptAttackCategory -class BedrockChecksPromptAttackModel(BaseModel): +class BedrockChecksPromptAttackModel(LiteLLMBaseModel): categories: list[BedrockChecksPromptAttackCategoryItem] -class BedrockChecksSensitiveInformationEntityItem(BaseModel): +class BedrockChecksSensitiveInformationEntityItem(LiteLLMBaseModel): type: BedrockChecksSensitiveInformationEntity -class BedrockChecksSensitiveInformationModel(BaseModel): +class BedrockChecksSensitiveInformationModel(LiteLLMBaseModel): entities: list[BedrockChecksSensitiveInformationEntityItem] -class BedrockChecksConfigModel(BaseModel): +class BedrockChecksConfigModel(LiteLLMBaseModel): """Inline `checks` config for the resource-less Bedrock InvokeGuardrailChecks API. Include only the checks you want to run; at least one must be set. @@ -588,7 +589,7 @@ class BedrockChecksConfigModel(BaseModel): return self -class BedrockGuardrailConfigModel(BaseModel): +class BedrockGuardrailConfigModel(LiteLLMBaseModel): """Configuration parameters for the AWS Bedrock guardrail""" guardrailIdentifier: str | None = Field(default=None, description="The ID of your guardrail on Bedrock") @@ -663,7 +664,7 @@ class BedrockGuardrailConfigModel(BaseModel): ) -class BedrockGuardrailStreamingParams(BaseModel): +class BedrockGuardrailStreamingParams(LiteLLMBaseModel): streaming_buffer_until_moderated: bool = Field( default=True, description="If True (default), withhold every streamed chunk until the end-of-stream " @@ -703,7 +704,7 @@ class BedrockGuardrailStreamingParams(BaseModel): ) -class LakeraV2GuardrailConfigModel(BaseModel): +class LakeraV2GuardrailConfigModel(LiteLLMBaseModel): """Configuration parameters for the Lakera AI v2 guardrail""" api_key: str | None = Field(default=None, description="API key for the Lakera AI service") @@ -728,7 +729,7 @@ class LakeraV2GuardrailConfigModel(BaseModel): ) -class LassoGuardrailConfigModel(BaseModel): +class LassoGuardrailConfigModel(LiteLLMBaseModel): """Configuration parameters for the Lasso guardrail""" lasso_user_id: str | None = Field(default=None, description="User ID for the Lasso guardrail") @@ -736,7 +737,7 @@ class LassoGuardrailConfigModel(BaseModel): mask: bool | None = Field(default=False, description="Enable content masking using Lasso classifix API") -class DeepKeepGuardrailConfigModel(BaseModel): +class DeepKeepGuardrailConfigModel(LiteLLMBaseModel): """Configuration parameters for the DeepKeep AI Firewall guardrail""" deepkeep_firewall_id: str | None = Field( @@ -748,7 +749,7 @@ class DeepKeepGuardrailConfigModel(BaseModel): ) -class PillarGuardrailConfigModel(BaseModel): +class PillarGuardrailConfigModel(LiteLLMBaseModel): """Configuration parameters for the Pillar Security guardrail""" on_flagged_action: str | None = Field( @@ -773,7 +774,7 @@ class PillarGuardrailConfigModel(BaseModel): ) -class NomaGuardrailConfigModel(BaseModel): +class NomaGuardrailConfigModel(LiteLLMBaseModel): """Configuration parameters for the Noma Security guardrail""" use_v2: bool | None = Field( @@ -802,7 +803,7 @@ class NomaGuardrailConfigModel(BaseModel): ) -class ZscalerAIGuardConfigModel(BaseModel): +class ZscalerAIGuardConfigModel(LiteLLMBaseModel): """Configuration parameters for the Zscaler AI Guard guardrail""" policy_id: int | None = Field( @@ -820,7 +821,7 @@ class ZscalerAIGuardConfigModel(BaseModel): ) -class JavelinGuardrailConfigModel(BaseModel): +class JavelinGuardrailConfigModel(LiteLLMBaseModel): """Configuration parameters for the Javelin guardrail""" guard_name: str | None = Field(default=None, description="Name of the Javelin guard to use") @@ -837,7 +838,7 @@ class ContentFilterAction(str, Enum): MASK = "MASK" -class BlockedWord(BaseModel): +class BlockedWord(LiteLLMBaseModel): """Represents a blocked word with its action and optional description""" keyword: str = Field(description="The keyword to block or mask") @@ -848,7 +849,7 @@ class BlockedWord(BaseModel): ) -class ContentFilterPattern(BaseModel): +class ContentFilterPattern(LiteLLMBaseModel): """Represents a content filter pattern (prebuilt or custom regex)""" pattern_type: Literal["prebuilt", "regex"] = Field( @@ -869,7 +870,7 @@ class ContentFilterPattern(BaseModel): action: ContentFilterAction = Field(description="Action to take when pattern matches (BLOCK or MASK)") -class ContentFilterConfigModel(BaseModel): +class ContentFilterConfigModel(LiteLLMBaseModel): """Configuration parameters for the content filter guardrail""" patterns: list[ContentFilterPattern] | None = Field( @@ -1168,7 +1169,7 @@ class BaseLitellmParams(ContentFilterConfigModel): # works for new and patch up model_config = ConfigDict(extra="allow", protected_namespaces=()) -class Mode(BaseModel): +class Mode(LiteLLMBaseModel): tags: dict[str, str | list[str]] = Field(description="Tags for the guardrail mode") default: str | list[str] | None = Field(default=None, description="Default mode when no tags match") @@ -1287,7 +1288,7 @@ class GUARDRAIL_DEFINITION_LOCATION(str, Enum): CONFIG = "config" -class GuardrailInfoResponse(BaseModel): +class GuardrailInfoResponse(LiteLLMBaseModel): guardrail_id: str | None = None guardrail_name: str litellm_params: BaseLitellmParams | None = None @@ -1300,11 +1301,11 @@ class GuardrailInfoResponse(BaseModel): super().__init__(**kwargs) -class ListGuardrailsResponse(BaseModel): +class ListGuardrailsResponse(LiteLLMBaseModel): guardrails: list[GuardrailInfoResponse] -class GuardrailUIAddGuardrailSettings(BaseModel): +class GuardrailUIAddGuardrailSettings(LiteLLMBaseModel): supported_entities: list[str] supported_actions: list[str] supported_modes: list[str] @@ -1313,7 +1314,7 @@ class GuardrailUIAddGuardrailSettings(BaseModel): content_filter_settings: dict[str, object] | None = None -class PresidioPerRequestConfig(BaseModel): +class PresidioPerRequestConfig(LiteLLMBaseModel): """ presdio params that can be controlled per request, api key """ @@ -1322,7 +1323,7 @@ class PresidioPerRequestConfig(BaseModel): entities: list[PiiEntityType] | None = None -class ApplyGuardrailRequest(BaseModel): +class ApplyGuardrailRequest(LiteLLMBaseModel): guardrail_name: str text: str language: str | None = None @@ -1332,11 +1333,11 @@ class ApplyGuardrailRequest(BaseModel): metadata: dict[str, object] | None = None -class ApplyGuardrailResponse(BaseModel): +class ApplyGuardrailResponse(LiteLLMBaseModel): response_text: str -class PatchGuardrailRequest(BaseModel): +class PatchGuardrailRequest(LiteLLMBaseModel): guardrail_name: str | None = None litellm_params: BaseLitellmParams | None = None guardrail_info: dict[str, object] | None = None diff --git a/litellm/types/integrations/arize.py b/litellm/types/integrations/arize.py index 7ed7b79e8d1..bde3956683b 100644 --- a/litellm/types/integrations/arize.py +++ b/litellm/types/integrations/arize.py @@ -1,6 +1,6 @@ from typing import TYPE_CHECKING, Any, Literal -from pydantic import BaseModel +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: Protocol = Literal["otlp_grpc", "otlp_http"] @@ -8,7 +8,7 @@ else: Protocol = Any -class ArizeConfig(BaseModel): +class ArizeConfig(LiteLLMBaseModel): space_id: str | None = None space_key: str | None = None api_key: str | None = None diff --git a/litellm/types/integrations/arize_phoenix.py b/litellm/types/integrations/arize_phoenix.py index ae91c9945b9..05bff51c48f 100644 --- a/litellm/types/integrations/arize_phoenix.py +++ b/litellm/types/integrations/arize_phoenix.py @@ -1,9 +1,9 @@ -from pydantic import BaseModel +from litellm.types.llms.base import LiteLLMBaseModel from .arize import Protocol -class ArizePhoenixConfig(BaseModel): +class ArizePhoenixConfig(LiteLLMBaseModel): otlp_auth_headers: str | None = None protocol: Protocol endpoint: str diff --git a/litellm/types/integrations/custom_logger.py b/litellm/types/integrations/custom_logger.py index 9a9f3ae34ce..d2db9357349 100644 --- a/litellm/types/integrations/custom_logger.py +++ b/litellm/types/integrations/custom_logger.py @@ -1,9 +1,10 @@ from collections.abc import Mapping from typing import Any, Final -from pydantic import BaseModel, Field +from pydantic import Field from litellm.types.litellm_params import AgenticSurface +from litellm.types.llms.base import LiteLLMBaseModel CHAT_COMPLETION_AGENTIC_SURFACE: Final[AgenticSurface] = "chat_completions" RESPONSES_AGENTIC_SURFACE: Final[AgenticSurface] = "responses" @@ -54,7 +55,7 @@ class AgenticLoopSafetyError(ValueError): """ -class StandardCustomLoggerInitParams(BaseModel): +class StandardCustomLoggerInitParams(LiteLLMBaseModel): """ Params for initializing a CustomLogger. """ @@ -62,7 +63,7 @@ class StandardCustomLoggerInitParams(BaseModel): turn_off_message_logging: bool | None = False -class AgenticLoopRequestPatch(BaseModel): +class AgenticLoopRequestPatch(LiteLLMBaseModel): """ Patch returned by callbacks to request a follow-up LLM call. """ @@ -75,7 +76,7 @@ class AgenticLoopRequestPatch(BaseModel): kwargs: dict[str, Any] = Field(default_factory=dict) -class AgenticLoopPlan(BaseModel): +class AgenticLoopPlan(LiteLLMBaseModel): """ Typed callback response for agentic-loop reruns. """ diff --git a/litellm/types/integrations/langfuse_otel.py b/litellm/types/integrations/langfuse_otel.py index c58dc567cda..4bcd0448c3a 100644 --- a/litellm/types/integrations/langfuse_otel.py +++ b/litellm/types/integrations/langfuse_otel.py @@ -1,7 +1,7 @@ from enum import Enum from typing import TYPE_CHECKING, Any, Literal -from pydantic import BaseModel +from litellm.types.llms.base import LiteLLMBaseModel if TYPE_CHECKING: Protocol = Literal["otlp_grpc", "otlp_http"] @@ -9,7 +9,7 @@ else: Protocol = Any -class LangfuseOtelConfig(BaseModel): +class LangfuseOtelConfig(LiteLLMBaseModel): otlp_auth_headers: str | None = None protocol: Protocol = "otlp_http" diff --git a/litellm/types/integrations/langsmith.py b/litellm/types/integrations/langsmith.py index 17fadfec54d..594190ddb5c 100644 --- a/litellm/types/integrations/langsmith.py +++ b/litellm/types/integrations/langsmith.py @@ -2,11 +2,12 @@ from dataclasses import dataclass from datetime import datetime from typing import Any, NamedTuple -from pydantic import BaseModel from typing_extensions import TypedDict +from litellm.types.llms.base import LiteLLMBaseModel -class LangsmithInputs(BaseModel): + +class LangsmithInputs(LiteLLMBaseModel): model: str | None = None messages: list[Any] | None = None stream: bool | None = None diff --git a/litellm/types/integrations/s3_v2.py b/litellm/types/integrations/s3_v2.py index e8ad28f1a3b..c0f719aacfb 100644 --- a/litellm/types/integrations/s3_v2.py +++ b/litellm/types/integrations/s3_v2.py @@ -1,11 +1,11 @@ from typing import Literal -from pydantic import BaseModel +from litellm.types.llms.base import LiteLLMBaseModel S3PartitionGranularity = Literal["day", "hour"] -class s3BatchLoggingElement(BaseModel): +class s3BatchLoggingElement(LiteLLMBaseModel): """ Type of element stored in self.log_queue in S3Logger """ diff --git a/litellm/types/integrations/slack_alerting.py b/litellm/types/integrations/slack_alerting.py index 770746196e4..4ba7e277cb6 100644 --- a/litellm/types/integrations/slack_alerting.py +++ b/litellm/types/integrations/slack_alerting.py @@ -5,9 +5,10 @@ from datetime import datetime as dt from enum import Enum from typing import Any, Final, Literal, Optional, Union -from pydantic import BaseModel, Field +from pydantic import Field from typing_extensions import NotRequired, ReadOnly, TypedDict +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import LiteLLMPydanticObjectBase DEFAULT_DIGEST_INTERVAL: Final = 86400 # 24 hours in seconds @@ -255,7 +256,7 @@ class AlertQueueItem(TypedDict): format: NotRequired[ReadOnly[str]] -class HangingRequestData(BaseModel): +class HangingRequestData(LiteLLMBaseModel): request_id: str model: str api_base: str | None = None diff --git a/litellm/types/integrations/weave_otel.py b/litellm/types/integrations/weave_otel.py index d3cf489435f..d99ec7dc51a 100644 --- a/litellm/types/integrations/weave_otel.py +++ b/litellm/types/integrations/weave_otel.py @@ -3,10 +3,10 @@ from __future__ import annotations from enum import Enum from typing import Literal -from pydantic import BaseModel +from litellm.types.llms.base import LiteLLMBaseModel -class WeaveOtelConfig(BaseModel): +class WeaveOtelConfig(LiteLLMBaseModel): """Configuration for Weave OpenTelemetry integration.""" otlp_auth_headers: str | None = None diff --git a/litellm/types/integrations/websearch_interception.py b/litellm/types/integrations/websearch_interception.py index 22233404fb3..0ba6e63264a 100644 --- a/litellm/types/integrations/websearch_interception.py +++ b/litellm/types/integrations/websearch_interception.py @@ -5,20 +5,21 @@ Type definitions for WebSearch Interception integration. from dataclasses import dataclass from typing import TYPE_CHECKING, Literal, TypeAlias, TypedDict -from pydantic import BaseModel from typing_extensions import ReadOnly +from litellm.types.llms.base import LiteLLMBaseModel + if TYPE_CHECKING: from litellm.llms.base_llm.search.transformation import SearchResponse -class AnthropicSearchQuery(BaseModel): +class AnthropicSearchQuery(LiteLLMBaseModel): """``input`` of an Anthropic ``server_tool_use`` block for a web search.""" query: str -class AnthropicServerToolUseBlock(BaseModel): +class AnthropicServerToolUseBlock(LiteLLMBaseModel): """ The ``server_tool_use`` block that must accompany a ``web_search_tool_result``. diff --git a/litellm/types/interactions/generated.py b/litellm/types/interactions/generated.py index a666d236e4b..fada4d5728a 100644 --- a/litellm/types/interactions/generated.py +++ b/litellm/types/interactions/generated.py @@ -7,10 +7,12 @@ from __future__ import annotations from enum import Enum from typing import Any, Final, Literal -from pydantic import AwareDatetime, Base64Str, BaseModel, Field, RootModel +from pydantic import AwareDatetime, Base64Str, Field, RootModel + +from litellm.types.llms.base import LiteLLMBaseModel -class Annotation(BaseModel): +class Annotation(LiteLLMBaseModel): start_index: int | None = Field( None, description="Start of segment of the response that is attributed to this source.\n\nIndex indicates the start of the segment, measured in bytes.", @@ -22,14 +24,14 @@ class Annotation(BaseModel): ) -class DocumentContent(BaseModel): +class DocumentContent(LiteLLMBaseModel): data: Base64Str | None = None uri: str | None = None mime_type: str | None = None type: Literal["document"] = Field(..., description="Used as the OpenAPI type discriminator for the content oneof.") -class FunctionCallContent(BaseModel): +class FunctionCallContent(LiteLLMBaseModel): name: str = Field(..., description="The name of the tool to call.") arguments: dict[str, Any] = Field(..., description="The arguments to pass to the function.") type: Literal["function_call"] = Field( @@ -42,16 +44,16 @@ class Language(Enum): python = "python" -class CodeExecutionCallArguments(BaseModel): +class CodeExecutionCallArguments(LiteLLMBaseModel): language: Language | None = Field(None, description="Programming language of the `code`.") code: str | None = Field(None, description="The code to be executed.") -class UrlContextCallArguments(BaseModel): +class UrlContextCallArguments(LiteLLMBaseModel): urls: list[str] | None = Field(None, description="The URLs to fetch.") -class McpServerToolCallContent(BaseModel): +class McpServerToolCallContent(LiteLLMBaseModel): name: str = Field(..., description="The name of the tool which was called.") server_name: str = Field(..., description="The name of the used MCP server.") arguments: dict[str, Any] = Field(..., description="The JSON object of arguments for the function.") @@ -61,11 +63,11 @@ class McpServerToolCallContent(BaseModel): id: str = Field(..., description="A unique ID for this specific tool call.") -class GoogleSearchCallArguments(BaseModel): +class GoogleSearchCallArguments(LiteLLMBaseModel): queries: list[str] | None = Field(None, description="Web search queries for the following-up web search.") -class CodeExecutionResultContent(BaseModel): +class CodeExecutionResultContent(LiteLLMBaseModel): result: str | None = Field(None, description="The output of the code execution.") is_error: bool | None = Field(None, description="Whether the code execution resulted in an error.") signature: str | None = Field(None, description="A signature hash for backend validation.") @@ -82,12 +84,12 @@ class Status(Enum): unsafe = "unsafe" -class UrlContextResult(BaseModel): +class UrlContextResult(LiteLLMBaseModel): url: str | None = Field(None, description="The URL that was fetched.") status: Status | None = Field(None, description="The status of the URL retrieval.") -class GoogleSearchResult(BaseModel): +class GoogleSearchResult(LiteLLMBaseModel): url: str | None = Field(None, description="URI reference of the search result.") title: str | None = Field(None, description="Title of the search result.") rendered_content: str | None = Field( @@ -96,13 +98,13 @@ class GoogleSearchResult(BaseModel): ) -class FileSearchResult(BaseModel): +class FileSearchResult(LiteLLMBaseModel): title: str | None = Field(None, description="The title of the search result.") text: str | None = Field(None, description="The text of the search result.") file_search_store: str | None = Field(None, description="The name of the file search store.") -class SpeechConfig(BaseModel): +class SpeechConfig(LiteLLMBaseModel): voice: str | None = Field(None, description="The voice of the speaker.") language: str | None = Field(None, description="The language of the speech.") speaker: str | None = Field( @@ -111,25 +113,25 @@ class SpeechConfig(BaseModel): ) -class DynamicAgentConfig(BaseModel): +class DynamicAgentConfig(LiteLLMBaseModel): type: Literal["dynamic"] = Field( "dynamic", description="Used as the OpenAPI type discriminator for the content oneof.", ) -class Function(BaseModel): +class Function(LiteLLMBaseModel): name: str | None = Field(None, description="The name of the function.") description: str | None = Field(None, description="A description of the function.") parameters: Any | None = Field(None, description="The JSON Schema for the function's parameters.") type: Literal["function"] -class CodeExecution(BaseModel): +class CodeExecution(LiteLLMBaseModel): type: Literal["code_execution"] -class UrlContext(BaseModel): +class UrlContext(LiteLLMBaseModel): type: Literal["url_context"] @@ -137,7 +139,7 @@ class Environment(Enum): browser = "browser" -class ComputerUse(BaseModel): +class ComputerUse(LiteLLMBaseModel): type: Literal["computer_use"] environment: Environment | None = Field(None, description="The environment being operated.") excludedPredefinedFunctions: list[str] | None = Field( @@ -146,11 +148,11 @@ class ComputerUse(BaseModel): ) -class GoogleSearch(BaseModel): +class GoogleSearch(LiteLLMBaseModel): type: Literal["google_search"] -class FileSearch(BaseModel): +class FileSearch(LiteLLMBaseModel): file_search_store_names: list[str] | None = Field(None, description="The file search store names to search.") top_k: int | None = Field(None, description="The number of semantic retrieval chunks to retrieve.") metadata_filter: str | None = Field( @@ -176,7 +178,7 @@ class Status1(Enum): queued = "queued" -class InteractionStatusUpdate(BaseModel): +class InteractionStatusUpdate(LiteLLMBaseModel): interaction_id: str | None = None status: Status1 | None = None event_type: Literal["interaction.status_update"] = "interaction.status_update" @@ -186,20 +188,20 @@ class InteractionStatusUpdate(BaseModel): ) -class TextDelta(BaseModel): +class TextDelta(LiteLLMBaseModel): text: str | None = None type: Literal["text"] = Field(..., description="Used as the OpenAPI type discriminator for the content oneof.") annotations: list[Annotation] | None = Field(None, description="Citation information for model-generated content.") -class DocumentDelta(BaseModel): +class DocumentDelta(LiteLLMBaseModel): data: Base64Str | None = None uri: str | None = None mime_type: str | None = None type: Literal["document"] = Field(..., description="Used as the OpenAPI type discriminator for the content oneof.") -class ThoughtSignatureDelta(BaseModel): +class ThoughtSignatureDelta(LiteLLMBaseModel): signature: Base64Str | None = Field( None, description="Signature to match the backend source to be part of the generation.", @@ -209,7 +211,7 @@ class ThoughtSignatureDelta(BaseModel): ) -class FunctionCallDelta(BaseModel): +class FunctionCallDelta(LiteLLMBaseModel): name: str | None = None arguments: dict[str, Any] | None = None type: Literal["function_call"] = Field( @@ -218,7 +220,7 @@ class FunctionCallDelta(BaseModel): id: str | None = Field(None, description="A unique ID for this specific tool call.") -class CodeExecutionCallDelta(BaseModel): +class CodeExecutionCallDelta(LiteLLMBaseModel): arguments: CodeExecutionCallArguments | None = None type: Literal["code_execution_call"] = Field( ..., description="Used as the OpenAPI type discriminator for the content oneof." @@ -226,7 +228,7 @@ class CodeExecutionCallDelta(BaseModel): id: str | None = Field(None, description="A unique ID for this specific tool call.") -class UrlContextCallDelta(BaseModel): +class UrlContextCallDelta(LiteLLMBaseModel): arguments: UrlContextCallArguments | None = None type: Literal["url_context_call"] = Field( ..., description="Used as the OpenAPI type discriminator for the content oneof." @@ -234,7 +236,7 @@ class UrlContextCallDelta(BaseModel): id: str | None = Field(None, description="A unique ID for this specific tool call.") -class GoogleSearchCallDelta(BaseModel): +class GoogleSearchCallDelta(LiteLLMBaseModel): arguments: GoogleSearchCallArguments | None = None type: Literal["google_search_call"] = Field( ..., description="Used as the OpenAPI type discriminator for the content oneof." @@ -242,7 +244,7 @@ class GoogleSearchCallDelta(BaseModel): id: str | None = Field(None, description="A unique ID for this specific tool call.") -class McpServerToolCallDelta(BaseModel): +class McpServerToolCallDelta(LiteLLMBaseModel): name: str | None = None server_name: str | None = None arguments: dict[str, Any] | None = None @@ -252,7 +254,7 @@ class McpServerToolCallDelta(BaseModel): id: str | None = Field(None, description="A unique ID for this specific tool call.") -class CodeExecutionResultDelta(BaseModel): +class CodeExecutionResultDelta(LiteLLMBaseModel): result: str | None = None is_error: bool | None = None signature: str | None = None @@ -262,7 +264,7 @@ class CodeExecutionResultDelta(BaseModel): call_id: str | None = Field(None, description="ID to match the ID from the function call block.") -class UrlContextResultDelta(BaseModel): +class UrlContextResultDelta(LiteLLMBaseModel): signature: str | None = None result: list[UrlContextResult] | None = None is_error: bool | None = None @@ -272,7 +274,7 @@ class UrlContextResultDelta(BaseModel): call_id: str | None = Field(None, description="ID to match the ID from the function call block.") -class GoogleSearchResultDelta(BaseModel): +class GoogleSearchResultDelta(LiteLLMBaseModel): signature: str | None = None result: list[GoogleSearchResult] | None = None is_error: bool | None = None @@ -282,14 +284,14 @@ class GoogleSearchResultDelta(BaseModel): call_id: str | None = Field(None, description="ID to match the ID from the function call block.") -class FileSearchResultDelta(BaseModel): +class FileSearchResultDelta(LiteLLMBaseModel): result: list[FileSearchResult] | None = None type: Literal["file_search_result"] = Field( ..., description="Used as the OpenAPI type discriminator for the content oneof." ) -class ContentStop(BaseModel): +class ContentStop(LiteLLMBaseModel): index: int | None = None event_type: Literal["content.stop"] = "content.stop" event_id: str | None = Field( @@ -298,7 +300,7 @@ class ContentStop(BaseModel): ) -class Error(BaseModel): +class Error(LiteLLMBaseModel): code: str | None = Field(None, description="A URI that identifies the error type.") message: str | None = Field(None, description="A human-readable error message.") @@ -367,13 +369,13 @@ class VideoMimeTypeOption(RootModel[str]): root: str = Field(..., description="The mime type of the video.", title="VideoMimeType") -class TextContent(BaseModel): +class TextContent(LiteLLMBaseModel): text: str | None = Field(None, description="The text content.") type: Literal["text"] = Field(..., description="Used as the OpenAPI type discriminator for the content oneof.") annotations: list[Annotation] | None = Field(None, description="Citation information for model-generated content.") -class ImageContent(BaseModel): +class ImageContent(LiteLLMBaseModel): data: Base64Str | None = None uri: str | None = None mime_type: ImageMimeTypeOption | None = None @@ -381,14 +383,14 @@ class ImageContent(BaseModel): resolution: MediaResolution | None = Field(None, description="The resolution of the media.") -class AudioContent(BaseModel): +class AudioContent(LiteLLMBaseModel): data: Base64Str | None = None uri: str | None = None mime_type: AudioMimeTypeOption | None = None type: Literal["audio"] = Field(..., description="Used as the OpenAPI type discriminator for the content oneof.") -class VideoContent(BaseModel): +class VideoContent(LiteLLMBaseModel): data: Base64Str | None = None uri: str | None = None mime_type: VideoMimeTypeOption | None = None @@ -404,7 +406,7 @@ class ThoughtSummary(RootModel[list[ThoughtSummary1]]): root: list[ThoughtSummary1] = Field(..., description="A summary of the thought.") -class CodeExecutionCallContent(BaseModel): +class CodeExecutionCallContent(LiteLLMBaseModel): arguments: CodeExecutionCallArguments | None = Field( None, description="The arguments to pass to the code execution." ) @@ -414,7 +416,7 @@ class CodeExecutionCallContent(BaseModel): id: str | None = Field(None, description="A unique ID for this specific tool call.") -class UrlContextCallContent(BaseModel): +class UrlContextCallContent(LiteLLMBaseModel): arguments: UrlContextCallArguments | None = Field(None, description="The arguments to pass to the URL context.") type: Literal["url_context_call"] = Field( ..., description="Used as the OpenAPI type discriminator for the content oneof." @@ -422,7 +424,7 @@ class UrlContextCallContent(BaseModel): id: str | None = Field(None, description="A unique ID for this specific tool call.") -class GoogleSearchCallContent(BaseModel): +class GoogleSearchCallContent(LiteLLMBaseModel): arguments: GoogleSearchCallArguments | None = Field(None, description="The arguments to pass to Google Search.") type: Literal["google_search_call"] = Field( ..., description="Used as the OpenAPI type discriminator for the content oneof." @@ -430,11 +432,11 @@ class GoogleSearchCallContent(BaseModel): id: str | None = Field(None, description="A unique ID for this specific tool call.") -class Result(BaseModel): +class Result(LiteLLMBaseModel): items: list[str | ImageContent] | None = None -class FunctionResultContent(BaseModel): +class FunctionResultContent(LiteLLMBaseModel): name: str | None = Field(None, description="The name of the tool that was called.") is_error: bool | None = Field(None, description="Whether the tool call resulted in an error.") type: Literal["function_result"] = Field( @@ -444,7 +446,7 @@ class FunctionResultContent(BaseModel): call_id: str = Field(..., description="ID to match the ID from the function call block.") -class UrlContextResultContent(BaseModel): +class UrlContextResultContent(LiteLLMBaseModel): signature: str | None = Field(None, description="The signature of the URL context result.") result: list[UrlContextResult] | None = Field(None, description="The results of the URL context.") is_error: bool | None = Field(None, description="Whether the URL context resulted in an error.") @@ -454,7 +456,7 @@ class UrlContextResultContent(BaseModel): call_id: str | None = Field(None, description="ID to match the ID from the url context call block.") -class GoogleSearchResultContent(BaseModel): +class GoogleSearchResultContent(LiteLLMBaseModel): signature: str | None = Field(None, description="The signature of the Google Search result.") result: list[GoogleSearchResult] | None = Field(None, description="The results of the Google Search.") is_error: bool | None = Field(None, description="Whether the Google Search resulted in an error.") @@ -464,7 +466,7 @@ class GoogleSearchResultContent(BaseModel): call_id: str | None = Field(None, description="ID to match the ID from the google search call block.") -class McpServerToolResultContent(BaseModel): +class McpServerToolResultContent(LiteLLMBaseModel): name: str | None = Field( None, description="Name of the tool which is called for this specific tool call.", @@ -477,19 +479,19 @@ class McpServerToolResultContent(BaseModel): call_id: str = Field(..., description="ID to match the ID from the MCP server tool call block.") -class FileSearchResultContent(BaseModel): +class FileSearchResultContent(LiteLLMBaseModel): result: list[FileSearchResult] | None = Field(None, description="The results of the File Search.") type: Literal["file_search_result"] = Field( ..., description="Used as the OpenAPI type discriminator for the content oneof." ) -class AllowedTools(BaseModel): +class AllowedTools(LiteLLMBaseModel): mode: ToolChoiceType | None = Field(None, description="The mode of the tool choice.") tools: list[str] | None = Field(None, description="The names of the allowed tools.") -class DeepResearchAgentConfig(BaseModel): +class DeepResearchAgentConfig(LiteLLMBaseModel): type: Literal["deep-research"] = Field( "deep-research", description="Used as the OpenAPI type discriminator for the content oneof.", @@ -499,7 +501,7 @@ class DeepResearchAgentConfig(BaseModel): ) -class McpServer(BaseModel): +class McpServer(LiteLLMBaseModel): type: Literal["mcp_server"] name: str | None = Field(None, description="The name of the MCPServer.") url: str | None = Field( @@ -513,12 +515,12 @@ class McpServer(BaseModel): allowed_tools: list[AllowedTools] | None = Field(None, description="The allowed tools.") -class ModalityTokens(BaseModel): +class ModalityTokens(LiteLLMBaseModel): modality: ResponseModality | None = Field(None, description="The modality associated with the token count.") tokens: int | None = Field(None, description="Number of tokens for the modality.") -class ImageDelta(BaseModel): +class ImageDelta(LiteLLMBaseModel): data: Base64Str | None = None uri: str | None = None mime_type: ImageMimeTypeOption | None = None @@ -526,14 +528,14 @@ class ImageDelta(BaseModel): resolution: MediaResolution | None = Field(None, description="The resolution of the media.") -class AudioDelta(BaseModel): +class AudioDelta(LiteLLMBaseModel): data: Base64Str | None = None uri: str | None = None mime_type: AudioMimeTypeOption | None = None type: Literal["audio"] = Field(..., description="Used as the OpenAPI type discriminator for the content oneof.") -class VideoDelta(BaseModel): +class VideoDelta(LiteLLMBaseModel): data: Base64Str | None = None uri: str | None = None mime_type: VideoMimeTypeOption | None = None @@ -541,14 +543,14 @@ class VideoDelta(BaseModel): resolution: MediaResolution | None = Field(None, description="The resolution of the media.") -class ThoughtSummaryDelta(BaseModel): +class ThoughtSummaryDelta(LiteLLMBaseModel): type: Literal["thought_summary"] = Field( ..., description="Used as the OpenAPI type discriminator for the content oneof." ) content: TextContent | ImageContent | None = Field(None, discriminator="type") -class FunctionResultDelta(BaseModel): +class FunctionResultDelta(LiteLLMBaseModel): name: str | None = None is_error: bool | None = None type: Literal["function_result"] = Field( @@ -558,7 +560,7 @@ class FunctionResultDelta(BaseModel): call_id: str | None = Field(None, description="ID to match the ID from the function call block.") -class McpServerToolResultDelta(BaseModel): +class McpServerToolResultDelta(LiteLLMBaseModel): name: str | None = None server_name: str | None = None type: Literal["mcp_server_tool_result"] = Field( @@ -568,7 +570,7 @@ class McpServerToolResultDelta(BaseModel): call_id: str | None = Field(None, description="ID to match the ID from the function call block.") -class ErrorEvent(BaseModel): +class ErrorEvent(LiteLLMBaseModel): event_type: Literal["error"] = "error" error: Error | None = None event_id: str | None = Field( @@ -577,7 +579,7 @@ class ErrorEvent(BaseModel): ) -class ToolChoiceConfig(BaseModel): +class ToolChoiceConfig(LiteLLMBaseModel): allowed_tools: AllowedTools | None = None @@ -587,7 +589,7 @@ class Tool(RootModel[Function | GoogleSearch | CodeExecution | UrlContext | Comp ) -class ThoughtContent(BaseModel): +class ThoughtContent(LiteLLMBaseModel): signature: Base64Str | None = Field( None, description="Signature to match the backend source to be part of the generation.", @@ -600,7 +602,7 @@ class ToolChoice(RootModel[ToolChoiceType | ToolChoiceConfig]): root: ToolChoiceType | ToolChoiceConfig = Field(..., description="The configuration for tool choice.") -class Usage(BaseModel): +class Usage(LiteLLMBaseModel): total_input_tokens: int | None = Field(None, description="Number of tokens in the prompt (context).") input_tokens_by_modality: list[ModalityTokens] | None = Field( None, description="A breakdown of input token usage by modality." @@ -629,7 +631,7 @@ class Usage(BaseModel): ) -class ContentDelta(BaseModel): +class ContentDelta(LiteLLMBaseModel): index: int | None = None event_type: Literal["content.delta"] = "content.delta" event_id: str | None = Field( @@ -701,7 +703,7 @@ class Content( ) = Field(..., description="The content of the response.", discriminator="type") -class Turn(BaseModel): +class Turn(LiteLLMBaseModel): role: str | None = Field( None, description="The originator of this turn. Must be user for input or model for\nmodel output.", @@ -709,7 +711,7 @@ class Turn(BaseModel): content: str | list[Content] | None = Field(None, description="The content of the turn.") -class GenerationConfig(BaseModel): +class GenerationConfig(LiteLLMBaseModel): temperature: float | None = Field(None, description="Controls the randomness of the output.") top_p: float | None = Field( None, @@ -731,7 +733,7 @@ class GenerationConfig(BaseModel): speech_config: list[SpeechConfig] | None = Field(None, description="Configuration for speech interaction.") -class ContentStart(BaseModel): +class ContentStart(LiteLLMBaseModel): index: int | None = None content: Content | None = None event_type: Literal["content.start"] = "content.start" @@ -741,7 +743,7 @@ class ContentStart(BaseModel): ) -class Interaction(BaseModel): +class Interaction(LiteLLMBaseModel): model: ModelOption | None = Field(None, description="The name of the `Model` used for generating the interaction.") agent: AgentOption | None = Field(None, description="The name of the `Agent` used for generating the interaction.") id: str = Field( @@ -797,7 +799,7 @@ class Interaction(BaseModel): ) -class CreateModelInteractionParams(BaseModel): +class CreateModelInteractionParams(LiteLLMBaseModel): model: ModelOption = Field(..., description="The name of the `Model` used for generating the interaction.") stream: bool | None = Field(None, description="Input only. Whether the interaction will be streamed.") store: bool | None = Field( @@ -848,7 +850,7 @@ class CreateModelInteractionParams(BaseModel): ) -class CreateAgentInteractionParams(BaseModel): +class CreateAgentInteractionParams(LiteLLMBaseModel): agent: AgentOption = Field(..., description="The name of the `Agent` used for generating the interaction.") stream: bool | None = Field(None, description="Input only. Whether the interaction will be streamed.") store: bool | None = Field( @@ -898,7 +900,7 @@ class CreateAgentInteractionParams(BaseModel): ) -class InteractionEvent(BaseModel): +class InteractionEvent(LiteLLMBaseModel): event_type: Literal["interaction.start", "interaction.complete"] interaction: Interaction | None = None event_id: str | None = Field( @@ -914,7 +916,7 @@ class InteractionEvent(BaseModel): # --------------------------------------------------------------- -class StepStart(BaseModel): +class StepStart(LiteLLMBaseModel): """Emitted when a new step begins (replaces content.start).""" event_type: Literal["step.start"] = "step.start" @@ -929,7 +931,7 @@ class StepStart(BaseModel): ) -class StepDelta(BaseModel): +class StepDelta(LiteLLMBaseModel): """Emitted for incremental step content (replaces content.delta).""" event_type: Literal["step.delta"] = "step.delta" @@ -944,7 +946,7 @@ class StepDelta(BaseModel): ) -class StepStop(BaseModel): +class StepStop(LiteLLMBaseModel): """Emitted when a step finishes (replaces content.stop).""" event_type: Literal["step.stop"] = "step.stop" @@ -959,7 +961,7 @@ class StepStop(BaseModel): ) -class InteractionCreated(BaseModel): +class InteractionCreated(LiteLLMBaseModel): """Emitted when the interaction is first created (replaces interaction.start).""" event_type: Literal["interaction.created"] = "interaction.created" @@ -970,7 +972,7 @@ class InteractionCreated(BaseModel): ) -class InteractionInProgress(BaseModel): +class InteractionInProgress(LiteLLMBaseModel): """Emitted while the interaction is running.""" event_type: Literal["interaction.in_progress"] = "interaction.in_progress" @@ -981,7 +983,7 @@ class InteractionInProgress(BaseModel): ) -class InteractionCompleted(BaseModel): +class InteractionCompleted(LiteLLMBaseModel): """Emitted when the interaction finishes (replaces interaction.complete).""" event_type: Literal["interaction.completed"] = "interaction.completed" @@ -992,7 +994,7 @@ class InteractionCompleted(BaseModel): ) -class InteractionRequiresAction(BaseModel): +class InteractionRequiresAction(LiteLLMBaseModel): """Emitted when the interaction is paused waiting for a tool result.""" event_type: Literal["interaction.requires_action"] = "interaction.requires_action" diff --git a/litellm/types/lar1.py b/litellm/types/lar1.py index 5998b665ece..2a5f096ba51 100644 --- a/litellm/types/lar1.py +++ b/litellm/types/lar1.py @@ -1,6 +1,8 @@ from enum import Enum -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel class LAR1Act(str, Enum): @@ -31,9 +33,9 @@ class LAR1Evidence(str, Enum): CONFIRMED = "CONFIRMED" -class LAR1Metadata(BaseModel): +class LAR1Metadata(LiteLLMBaseModel): act: LAR1Act = LAR1Act.INF time: LAR1Time = LAR1Time.NOW mind: LAR1Mind = LAR1Mind.REF confidence: float = Field(default=0.5, ge=0.0, le=1.0) - evidence: list[LAR1Evidence] = [] + evidence: list[LAR1Evidence] = Field(default=[]) diff --git a/litellm/types/llms/anthropic.py b/litellm/types/llms/anthropic.py index 46693009bfd..f0b5a1bb84e 100644 --- a/litellm/types/llms/anthropic.py +++ b/litellm/types/llms/anthropic.py @@ -2,9 +2,11 @@ from collections.abc import Iterable, Sequence from enum import Enum from typing import Any, Final, Literal, TypeAlias -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict from typing_extensions import NotRequired, ReadOnly, Required, TypedDict +from litellm.types.llms.base import LiteLLMBaseModel + from .openai import ( ChatCompletionCachedContent, ChatCompletionRedactedThinkingBlock, @@ -639,12 +641,12 @@ class MessageStartBlock(TypedDict): message: MessageChunk -class AnthropicResponseContentBlockText(BaseModel): +class AnthropicResponseContentBlockText(LiteLLMBaseModel): type: Literal["text"] text: str -class AnthropicResponseContentBlockToolUse(BaseModel): +class AnthropicResponseContentBlockToolUse(LiteLLMBaseModel): type: Literal["tool_use"] id: str name: str @@ -654,25 +656,25 @@ class AnthropicResponseContentBlockToolUse(BaseModel): model_config = ConfigDict(extra="allow") # Allow provider_specific_fields -class AnthropicResponseContentBlockThinking(BaseModel): +class AnthropicResponseContentBlockThinking(LiteLLMBaseModel): type: Literal["thinking"] thinking: str signature: str | None -class AnthropicResponseContentBlockRedactedThinking(BaseModel): +class AnthropicResponseContentBlockRedactedThinking(LiteLLMBaseModel): type: Literal["redacted_thinking"] data: str -class AnthropicResponseUsageBlock(BaseModel): +class AnthropicResponseUsageBlock(LiteLLMBaseModel): model_config = ConfigDict(extra="allow") input_tokens: int output_tokens: int -class AnthropicOutputTokensDetails(BaseModel): +class AnthropicOutputTokensDetails(LiteLLMBaseModel): model_config = ConfigDict(extra="allow") thinking_tokens: int | None = None @@ -681,7 +683,7 @@ class AnthropicOutputTokensDetails(BaseModel): AnthropicFinishReason = Literal["end_turn", "max_tokens", "stop_sequence", "tool_use", "refusal"] -class AnthropicResponse(BaseModel): +class AnthropicResponse(LiteLLMBaseModel): id: str """Unique object identifier.""" diff --git a/litellm/types/llms/anthropic_messages/anthropic_request.py b/litellm/types/llms/anthropic_messages/anthropic_request.py index cbdd1c4446a..d1f66394ca5 100644 --- a/litellm/types/llms/anthropic_messages/anthropic_request.py +++ b/litellm/types/llms/anthropic_messages/anthropic_request.py @@ -1,7 +1,7 @@ -from pydantic import BaseModel +from litellm.types.llms.base import LiteLLMBaseModel -class AnthropicMetadata(BaseModel): +class AnthropicMetadata(LiteLLMBaseModel): """ Object with allowed fields for Anthropic API metadata diff --git a/litellm/types/llms/anthropic_skills.py b/litellm/types/llms/anthropic_skills.py index 4b27f9b17ef..d11fd32f88b 100644 --- a/litellm/types/llms/anthropic_skills.py +++ b/litellm/types/llms/anthropic_skills.py @@ -4,9 +4,10 @@ Type definitions for Anthropic Skills API from typing import Any -from pydantic import BaseModel from typing_extensions import TypedDict +from litellm.types.llms.base import LiteLLMBaseModel + # Skills API Request Types class CreateSkillRequest(TypedDict, total=False): @@ -33,7 +34,7 @@ class ListSkillsParams(TypedDict, total=False): # Skills API Response Types -class Skill(BaseModel): +class Skill(LiteLLMBaseModel): """Represents a skill from the Anthropic Skills API""" id: str @@ -67,7 +68,7 @@ class Skill(BaseModel): unless a query was given.""" -class ListSkillsResponse(BaseModel): +class ListSkillsResponse(LiteLLMBaseModel): """Response from listing skills""" data: list[Skill] @@ -80,7 +81,7 @@ class ListSkillsResponse(BaseModel): """Whether there are more skills available""" -class DeleteSkillResponse(BaseModel): +class DeleteSkillResponse(LiteLLMBaseModel): """Response from deleting a skill""" id: str @@ -107,7 +108,7 @@ class CreateSkillVersionRequest(TypedDict, total=False): """Additional metadata""" -class SkillVersion(BaseModel): +class SkillVersion(LiteLLMBaseModel): """Represents a skill version""" id: str @@ -135,7 +136,7 @@ class SkillVersion(BaseModel): """Object type""" -class ListSkillVersionsResponse(BaseModel): +class ListSkillVersionsResponse(LiteLLMBaseModel): """Response from listing skill versions""" object: str = "list" @@ -154,7 +155,7 @@ class ListSkillVersionsResponse(BaseModel): """Whether there are more versions available""" -class DeleteSkillVersionResponse(BaseModel): +class DeleteSkillVersionResponse(LiteLLMBaseModel): """Response from deleting a skill version""" id: str diff --git a/litellm/types/llms/base.py b/litellm/types/llms/base.py index 938aa8064c9..803e7cb44b0 100644 --- a/litellm/types/llms/base.py +++ b/litellm/types/llms/base.py @@ -1,10 +1,28 @@ -from typing import Any, Final +from typing import TYPE_CHECKING, Any, Final from openai._models import BaseModel as OpenAIObject from pydantic import BaseModel, ConfigDict +from litellm.constants import DEFER_PYDANTIC_BUILD -class LiteLLMPydanticObjectBase(BaseModel): + +class LiteLLMBaseModel(BaseModel): + model_config = ConfigDict(defer_build=DEFER_PYDANTIC_BUILD) + + if TYPE_CHECKING: + + def __init__(self, /, **data: object) -> None: ... + + def model_post_init(self, context: object, /) -> None: + # Instances built by a parent's validator or by model_construct skip this class's own + # first-use build, leaving a MockValSer that fails when the instance is serialized as Any + # TODO: drop once pydantic ships a fix for https://github.com/pydantic/pydantic/issues/13647 + model = type(self) + if not model.__pydantic_complete__: + model.model_rebuild(raise_errors=False) + + +class LiteLLMPydanticObjectBase(LiteLLMBaseModel): """ Implements default functions, all pydantic objects should have. """ @@ -26,7 +44,7 @@ class LiteLLMPydanticObjectBase(BaseModel): model_config = ConfigDict(protected_namespaces=()) -class BaseLiteLLMOpenAIResponseObject(BaseModel): +class BaseLiteLLMOpenAIResponseObject(LiteLLMBaseModel): model_config = ConfigDict(extra="allow", protected_namespaces=()) def __getitem__(self, key): @@ -77,7 +95,7 @@ class HiddenParams(OpenAIObject): return data -class CachedTokensDetails(BaseModel): +class CachedTokensDetails(LiteLLMBaseModel): text_tokens: int | None = None audio_tokens: int | None = None image_tokens: int | None = None diff --git a/litellm/types/llms/bedrock.py b/litellm/types/llms/bedrock.py index e4c41c3ee5b..cc420fb9509 100644 --- a/litellm/types/llms/bedrock.py +++ b/litellm/types/llms/bedrock.py @@ -3,9 +3,11 @@ from collections.abc import Sequence from enum import Enum from typing import TYPE_CHECKING, Any, Final, Literal, TypeAlias -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict from typing_extensions import NotRequired, ReadOnly, Required, TypedDict, override +from litellm.types.llms.base import LiteLLMBaseModel + from .openai import ChatCompletionToolCallChunk @@ -1114,7 +1116,7 @@ class AwsSessionTag(TypedDict): Value: str # writable-ok: boto3's STS stubs type assume_role Tags as writable TagTypeDef, which rejects ReadOnly -class AwsAuthParams(BaseModel): +class AwsAuthParams(LiteLLMBaseModel): """Every credential-shaped aws_* param BaseAWSLLM.get_credentials accepts; region is resolved separately.""" model_config = ConfigDict(frozen=True, extra="ignore") diff --git a/litellm/types/llms/gemini.py b/litellm/types/llms/gemini.py index 57fb8b5b0cd..c300c26bcd3 100644 --- a/litellm/types/llms/gemini.py +++ b/litellm/types/llms/gemini.py @@ -151,7 +151,7 @@ class BidiGenerateContentSetup(TypedDict, total=False): # Image Generation Types -from pydantic import BaseModel +from litellm.types.llms.base import LiteLLMBaseModel class GeminiImageGenerationInstance(TypedDict): @@ -160,7 +160,7 @@ class GeminiImageGenerationInstance(TypedDict): prompt: str -class GeminiImageGenerationParameters(BaseModel): +class GeminiImageGenerationParameters(LiteLLMBaseModel): """Parameters for Gemini image generation request""" sampleCount: int | None = None @@ -204,7 +204,7 @@ class GeminiImageGenerationParameters(BaseModel): """User specification""" -class GeminiImageGenerationRequest(BaseModel): +class GeminiImageGenerationRequest(LiteLLMBaseModel): """Complete request body for Gemini image generation""" instances: list[GeminiImageGenerationInstance] @@ -238,7 +238,7 @@ class GeminiVideoGenerationInstance(TypedDict, total=False): image: dict[str, Any] -class GeminiVideoGenerationParameters(BaseModel): +class GeminiVideoGenerationParameters(LiteLLMBaseModel): """ Parameters for Gemini video generation request. @@ -290,7 +290,7 @@ class GeminiVideoGenerationParameters(BaseModel): """ -class GeminiVideoGenerationRequest(BaseModel): +class GeminiVideoGenerationRequest(LiteLLMBaseModel): """Complete request body for Gemini video generation""" instances: list[GeminiVideoGenerationInstance] @@ -298,35 +298,35 @@ class GeminiVideoGenerationRequest(BaseModel): # Video Generation Operation Response Types -class GeminiVideoUri(BaseModel): +class GeminiVideoUri(LiteLLMBaseModel): """Video URI in the generated sample""" uri: str """File URI of the generated video (e.g., 'files/abc123...')""" -class GeminiGeneratedVideoSample(BaseModel): +class GeminiGeneratedVideoSample(LiteLLMBaseModel): """Individual generated video sample""" video: GeminiVideoUri """Video object containing the URI""" -class GeminiGenerateVideoResponse(BaseModel): +class GeminiGenerateVideoResponse(LiteLLMBaseModel): """Generate video response containing the samples""" generatedSamples: list[GeminiGeneratedVideoSample] """List of generated video samples""" -class GeminiOperationResponse(BaseModel): +class GeminiOperationResponse(LiteLLMBaseModel): """Response object in the operation when done""" generateVideoResponse: GeminiGenerateVideoResponse """Video generation response""" -class GeminiOperationMetadata(BaseModel): +class GeminiOperationMetadata(LiteLLMBaseModel): """Metadata for the operation""" createTime: str | None = None @@ -335,7 +335,7 @@ class GeminiOperationMetadata(BaseModel): """Model used for generation""" -class GeminiLongRunningOperationResponse(BaseModel): +class GeminiLongRunningOperationResponse(LiteLLMBaseModel): """ Complete response for a long-running operation. diff --git a/litellm/types/llms/gemini_audio_transcription.py b/litellm/types/llms/gemini_audio_transcription.py index f7e74ba4bf8..c1cf3452945 100644 --- a/litellm/types/llms/gemini_audio_transcription.py +++ b/litellm/types/llms/gemini_audio_transcription.py @@ -1,8 +1,10 @@ from typing import Literal -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict from typing_extensions import ReadOnly, Required, TypedDict +from litellm.types.llms.base import LiteLLMBaseModel + class GeminiTranscriptionAudioInput(TypedDict): type: ReadOnly[Literal["audio"]] @@ -31,7 +33,7 @@ class GeminiTranscriptionInteractionRequest(TypedDict, total=False): generation_config: ReadOnly[GeminiTranscriptionGenerationConfig] -class GeminiTranscriptionWordAnnotation(BaseModel): +class GeminiTranscriptionWordAnnotation(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") type: str | None = None @@ -41,7 +43,7 @@ class GeminiTranscriptionWordAnnotation(BaseModel): end_offset: str | None = None -class GeminiTranscriptionContent(BaseModel): +class GeminiTranscriptionContent(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") type: str | None = None @@ -49,21 +51,21 @@ class GeminiTranscriptionContent(BaseModel): annotations: tuple[GeminiTranscriptionWordAnnotation, ...] = () -class GeminiTranscriptionStep(BaseModel): +class GeminiTranscriptionStep(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") type: str | None = None content: tuple[GeminiTranscriptionContent, ...] = () -class GeminiTranscriptionModalityTokens(BaseModel): +class GeminiTranscriptionModalityTokens(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") modality: str | None = None tokens: int = 0 -class GeminiTranscriptionUsage(BaseModel): +class GeminiTranscriptionUsage(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") total_tokens: int = 0 @@ -72,7 +74,7 @@ class GeminiTranscriptionUsage(BaseModel): input_tokens_by_modality: tuple[GeminiTranscriptionModalityTokens, ...] = () -class GeminiTranscriptionInteractionResponse(BaseModel): +class GeminiTranscriptionInteractionResponse(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") id: str | None = None diff --git a/litellm/types/llms/oci.py b/litellm/types/llms/oci.py index d87e4231337..bd3a0af1dca 100644 --- a/litellm/types/llms/oci.py +++ b/litellm/types/llms/oci.py @@ -3,7 +3,9 @@ from __future__ import annotations from enum import Enum from typing import Literal -from pydantic import BaseModel, SerializeAsAny +from pydantic import SerializeAsAny + +from litellm.types.llms.base import LiteLLMBaseModel OCIRoles = Literal["SYSTEM", "USER", "ASSISTANT", "TOOL"] @@ -21,7 +23,7 @@ class OCIVendors(Enum): # --- Base Models and Content Parts --- -class OCIContentPart(BaseModel): +class OCIContentPart(LiteLLMBaseModel): """Base model for content parts in an OCI message.""" @@ -32,7 +34,7 @@ class OCITextContentPart(OCIContentPart): text: str -class OCIImageUrl(BaseModel): +class OCIImageUrl(LiteLLMBaseModel): """ImageUrl object for OCI API. See: https://docs.oracle.com/en-us/iaas/tools/python/latest/api/generative_ai_inference/models/oci.generative_ai_inference.models.ImageUrl.html""" url: str @@ -51,7 +53,7 @@ OCIContentPartUnion = OCITextContentPart | OCIImageContentPart # --- Models for Tools and Tool Calls --- -class OCIToolCall(BaseModel): +class OCIToolCall(LiteLLMBaseModel): """Represents a tool call made by the model.""" id: str | None = None # absent in some provider responses (e.g. Google via OCI) @@ -60,7 +62,7 @@ class OCIToolCall(BaseModel): arguments: str # Arguments should be a JSON-serialized string -class OCIToolDefinition(BaseModel): +class OCIToolDefinition(LiteLLMBaseModel): """Defines a tool that can be used by the model.""" type: Literal["FUNCTION"] = "FUNCTION" @@ -72,7 +74,7 @@ class OCIToolDefinition(BaseModel): # --- Message Models (Request and Response) --- -class OCIMessage(BaseModel): +class OCIMessage(LiteLLMBaseModel): """Model for a single message in the request/response payload.""" role: OCIRoles @@ -84,7 +86,7 @@ class OCIMessage(BaseModel): # --- Request Payload Models --- -class OCIChatRequestPayload(BaseModel): +class OCIChatRequestPayload(LiteLLMBaseModel): """Internal 'chatRequest' payload for the OCI API.""" apiFormat: str @@ -111,7 +113,7 @@ class OCIChatRequestPayload(BaseModel): logProbs: int | None = None -class OCIServingMode(BaseModel): +class OCIServingMode(LiteLLMBaseModel): """Defines the serving mode and the model to be used.""" servingType: str @@ -119,7 +121,7 @@ class OCIServingMode(BaseModel): modelId: str | None = None -class OCICompletionPayload(BaseModel): +class OCICompletionPayload(LiteLLMBaseModel): """Pydantic model for the complete OCI chat request body.""" compartmentId: str @@ -130,20 +132,20 @@ class OCICompletionPayload(BaseModel): # --- API Response Models (Non-streaming) --- -class OCICompletionTokenDetails(BaseModel): +class OCICompletionTokenDetails(LiteLLMBaseModel): """Completion token details in the OCI response.""" acceptedPredictionTokens: int | None = None reasoningTokens: int | None = None -class OCIPromptTokensDetails(BaseModel): +class OCIPromptTokensDetails(LiteLLMBaseModel): """Prompt token details in the OCI response.""" cachedTokens: int | None = None -class OCIResponseUsage(BaseModel): +class OCIResponseUsage(LiteLLMBaseModel): """Token usage in the OCI response.""" promptTokens: int @@ -155,7 +157,7 @@ class OCIResponseUsage(BaseModel): promptTokensDetails: OCIPromptTokensDetails | None = None -class OCIResponseChoice(BaseModel): +class OCIResponseChoice(LiteLLMBaseModel): """A completion choice in the OCI response.""" index: int @@ -166,7 +168,7 @@ class OCIResponseChoice(BaseModel): logprobs: dict[str, object] | None = None -class OCIChatResponse(BaseModel): +class OCIChatResponse(LiteLLMBaseModel): """The 'chatResponse' object in the OCI response.""" apiFormat: str @@ -175,7 +177,7 @@ class OCIChatResponse(BaseModel): usage: OCIResponseUsage -class OCICompletionResponse(BaseModel): +class OCICompletionResponse(LiteLLMBaseModel): """Model for the complete non-streaming OCI response body.""" modelId: str @@ -186,7 +188,7 @@ class OCICompletionResponse(BaseModel): # --- API Response Models (Streaming) --- -class OCIStreamDelta(BaseModel): +class OCIStreamDelta(LiteLLMBaseModel): """The content delta in a streaming chunk.""" content: list[OCIContentPartUnion] | None = None @@ -194,7 +196,7 @@ class OCIStreamDelta(BaseModel): toolCalls: list[OCIToolCall] | None = None -class OCIStreamChunk(BaseModel): +class OCIStreamChunk(LiteLLMBaseModel): """Model for a single SSE event chunk from OCI.""" finishReason: str | None = None @@ -206,7 +208,7 @@ class OCIStreamChunk(BaseModel): # --- Cohere-Specific Models --- -class CohereStreamChunk(BaseModel): +class CohereStreamChunk(LiteLLMBaseModel): """Model for a single SSE event chunk from OCI Cohere API.""" apiFormat: str @@ -218,7 +220,7 @@ class CohereStreamChunk(BaseModel): index: int | None = None -class CohereMessage(BaseModel): +class CohereMessage(LiteLLMBaseModel): """Base model for Cohere messages.""" role: str @@ -255,7 +257,7 @@ class CohereToolMessage(CohereMessage): toolResults: list[CohereToolResult] -class CohereParameterDefinition(BaseModel): +class CohereParameterDefinition(LiteLLMBaseModel): """Parameter definition for Cohere tools.""" description: str @@ -263,7 +265,7 @@ class CohereParameterDefinition(BaseModel): isRequired: bool = False -class CohereTool(BaseModel): +class CohereTool(LiteLLMBaseModel): """Tool definition for Cohere.""" name: str @@ -271,14 +273,14 @@ class CohereTool(BaseModel): parameterDefinitions: dict[str, CohereParameterDefinition] -class CohereToolCall(BaseModel): +class CohereToolCall(LiteLLMBaseModel): """Tool call made by Cohere model.""" name: str parameters: dict[str, object] -class CohereToolResult(BaseModel): +class CohereToolResult(LiteLLMBaseModel): """Result of a tool call. Matches the OCI SDK's CohereToolResult: each result carries the originating @@ -289,7 +291,7 @@ class CohereToolResult(BaseModel): outputs: list[dict[str, object]] -class CohereChatRequest(BaseModel): +class CohereChatRequest(LiteLLMBaseModel): """Cohere chat request model.""" # Required fields @@ -336,7 +338,7 @@ class CohereChatRequest(BaseModel): streamOptions: dict[str, object] | None = None -class CohereUsage(BaseModel): +class CohereUsage(LiteLLMBaseModel): """Usage information for Cohere response.""" promptTokens: int @@ -346,7 +348,7 @@ class CohereUsage(BaseModel): completionTokensDetails: dict[str, object] | None = None -class CohereCitation(BaseModel): +class CohereCitation(LiteLLMBaseModel): """Citation in Cohere response.""" start: int @@ -355,14 +357,14 @@ class CohereCitation(BaseModel): document_ids: list[str] -class CohereSearchQuery(BaseModel): +class CohereSearchQuery(LiteLLMBaseModel): """Search query generated by Cohere.""" text: str generation_id: str -class CohereChatResponse(BaseModel): +class CohereChatResponse(LiteLLMBaseModel): """Cohere chat response model.""" # Required fields @@ -387,7 +389,7 @@ class CohereChatResponse(BaseModel): usage: CohereUsage | None = None -class CohereChatDetails(BaseModel): +class CohereChatDetails(LiteLLMBaseModel): """Chat details for Cohere request.""" compartmentId: str @@ -395,7 +397,7 @@ class CohereChatDetails(BaseModel): chatRequest: CohereChatRequest -class CohereChatResult(BaseModel): +class CohereChatResult(LiteLLMBaseModel): """Complete Cohere chat result.""" modelId: str @@ -408,7 +410,7 @@ class CohereChatResult(BaseModel): # --------------------------------------------------------------------------- -class OCIEmbedRequest(BaseModel): +class OCIEmbedRequest(LiteLLMBaseModel): """Request body for POST /20231130/actions/embedText.""" compartmentId: str @@ -419,12 +421,12 @@ class OCIEmbedRequest(BaseModel): outputDimensions: int | None = None # cohere.embed-v4.0+; valid: 256, 512, 1024, 1536 -class OCIEmbedUsage(BaseModel): +class OCIEmbedUsage(LiteLLMBaseModel): promptTokens: int totalTokens: int -class OCIEmbedResponse(BaseModel): +class OCIEmbedResponse(LiteLLMBaseModel): """Response body from POST /20231130/actions/embedText.""" id: str | None = None # present in the official SDK response diff --git a/litellm/types/llms/openai.py b/litellm/types/llms/openai.py index 6db7fd68292..f241c4a7a27 100644 --- a/litellm/types/llms/openai.py +++ b/litellm/types/llms/openai.py @@ -63,7 +63,6 @@ from openai.types.responses.response_create_params import ( from openai.types.responses.response_function_tool_call import ResponseFunctionToolCall from openai.types.responses.response_function_web_search import ResponseFunctionWebSearch from pydantic import ( - BaseModel, ConfigDict, Discriminator, Field, @@ -82,7 +81,7 @@ from typing_extensions import ( override, ) -from litellm.types.llms.base import BaseLiteLLMOpenAIResponseObject +from litellm.types.llms.base import BaseLiteLLMOpenAIResponseObject, LiteLLMBaseModel from litellm.types.responses.main import ( CustomToolCallOutputItem, GenericResponseOutputItem, @@ -283,7 +282,7 @@ class MessageData(TypedDict): metadata: dict | None -class Thread(BaseModel): +class Thread(LiteLLMBaseModel): id: str """The identifier, which can be referenced in API endpoints.""" @@ -318,7 +317,7 @@ OpenAIFilesPurpose = Literal[ ] -class BatchGuardrailRecord(BaseModel): +class BatchGuardrailRecord(LiteLLMBaseModel): """One batch input record a guardrail acted on.""" line: int @@ -342,7 +341,7 @@ class BatchGuardrailRecord(BaseModel): """ -class BatchGuardrailReport(BaseModel): +class BatchGuardrailReport(LiteLLMBaseModel): """What guardrails did to a batch input file, per record.""" submitted_records: int @@ -359,7 +358,7 @@ _JsonValue: TypeAlias = object BATCH_GUARDRAIL_RESPONSE_FIELD: Final = "litellm_batch_guardrail" -class OpenAIFileObject(BaseModel): +class OpenAIFileObject(LiteLLMBaseModel): id: str """The file identifier, which can be referenced in the API endpoints.""" @@ -405,7 +404,7 @@ class OpenAIFileObject(BaseModel): Absent on every other upload, so OpenAI-shaped clients see an unchanged response. """ - _hidden_params: dict = {"response_cost": 0.0} # no cost for writing a file + _hidden_params: dict = PrivateAttr(default={"response_cost": 0.0}) # no cost for writing a file @model_serializer(mode="wrap") def _omit_absent_batch_guardrail( # noqa: ANN202 # annotating it replaces the model's serialization schema @@ -436,7 +435,7 @@ class OpenAIFileObject(BaseModel): return self.dict() -class FileListPage(BaseModel): +class FileListPage(LiteLLMBaseModel): """A page of files, as `GET /v1/files` returns it. Post-call hooks and logging callbacks are handed the listing response, and @@ -1115,7 +1114,7 @@ class OpenAIChatCompletionChunk(ChatCompletionChunk): super().__init__(**kwargs) -class Hyperparameters(BaseModel): +class Hyperparameters(LiteLLMBaseModel): batch_size: str | int | None = None # "Number of examples in each batch." learning_rate_multiplier: str | float | None = None # Scaling factor for the learning rate n_epochs: str | int | None = None # "The number of epochs to train the model for" @@ -1123,7 +1122,7 @@ class Hyperparameters(BaseModel): model_config = {"extra": "allow"} -class FineTuningJobCreate(BaseModel): +class FineTuningJobCreate(LiteLLMBaseModel): """ FineTuningJobCreate - Create a fine-tuning job @@ -1157,7 +1156,7 @@ class FineTuningJobCreate(BaseModel): class LiteLLMFineTuningJobCreate(FineTuningJobCreate): custom_llm_provider: Literal["openai", "azure", "vertex_ai"] | None = None - model_config = {"extra": "allow"} # This allows the model to accept additional fields + model_config = ConfigDict(extra="allow") # This allows the model to accept additional fields AllEmbeddingInputValues = str | list[str] | list[int] | list[list[int]] @@ -1363,16 +1362,16 @@ class ResponseAPIUsage(BaseLiteLLMOpenAIResponseObject): return v.get("total_cost") return v - model_config = {"extra": "allow"} + model_config = ConfigDict(extra="allow") -class WebSearchToolUsage(BaseModel): +class WebSearchToolUsage(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) num_requests: NonNegativeInt -class ResponsesToolUsage(BaseModel): +class ResponsesToolUsage(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) web_search: WebSearchToolUsage | None = None @@ -2519,7 +2518,7 @@ class CreateVideoRequest(TypedDict, total=False): timeout: float | None -class OpenAIVideoObject(BaseModel): +class OpenAIVideoObject(LiteLLMBaseModel): """OpenAI Video Object representing a video generation job.""" id: str @@ -2558,7 +2557,7 @@ class OpenAIVideoObject(BaseModel): model: str | None = None """The video generation model that produced the job.""" - _hidden_params: dict[str, _JsonValue] = {} + _hidden_params: dict[str, _JsonValue] = PrivateAttr(default={}) def __contains__(self, key) -> bool: return hasattr(self, key) diff --git a/litellm/types/llms/openai_evals.py b/litellm/types/llms/openai_evals.py index 519e3e82fff..b753d17e719 100644 --- a/litellm/types/llms/openai_evals.py +++ b/litellm/types/llms/openai_evals.py @@ -5,9 +5,10 @@ Type definitions for OpenAI Evals API import builtins from typing import Literal -from pydantic import BaseModel from typing_extensions import Required, TypedDict +from litellm.types.llms.base import LiteLLMBaseModel + # Evals API Request Types class DataSourceConfigCustom(TypedDict, total=False): @@ -128,7 +129,7 @@ class ListEvalsParams(TypedDict, total=False): # Evals API Response Types -class Eval(BaseModel): +class Eval(LiteLLMBaseModel): """Represents an evaluation from the OpenAI Evals API""" id: str @@ -156,7 +157,7 @@ class Eval(BaseModel): """Additional metadata""" -class ListEvalsResponse(BaseModel): +class ListEvalsResponse(LiteLLMBaseModel): """Response from listing evaluations""" object: str = "list" @@ -175,7 +176,7 @@ class ListEvalsResponse(BaseModel): """Whether there are more evaluations available""" -class DeleteEvalResponse(BaseModel): +class DeleteEvalResponse(LiteLLMBaseModel): """Response from deleting an evaluation""" eval_id: str @@ -188,7 +189,7 @@ class DeleteEvalResponse(BaseModel): """Whether the evaluation was successfully deleted""" -class CancelEvalResponse(BaseModel): +class CancelEvalResponse(LiteLLMBaseModel): """Response from cancelling an evaluation""" id: str @@ -287,7 +288,7 @@ class ListRunsParams(TypedDict, total=False): # Run API Response Types -class ResultCounts(BaseModel): +class ResultCounts(LiteLLMBaseModel): """Result counts for a run""" total: int @@ -303,7 +304,7 @@ class ResultCounts(BaseModel): """Number of error results""" -class PerTestingCriteriaResult(BaseModel): +class PerTestingCriteriaResult(LiteLLMBaseModel): """Results for a specific testing criteria""" testing_criteria_index: int @@ -316,7 +317,7 @@ class PerTestingCriteriaResult(BaseModel): """Average score for this criteria""" -class Run(BaseModel): +class Run(LiteLLMBaseModel): """Represents a run from the OpenAI Evals API""" id: str @@ -371,7 +372,7 @@ class Run(BaseModel): """Error details if the run failed""" -class ListRunsResponse(BaseModel): +class ListRunsResponse(LiteLLMBaseModel): """Response from listing runs""" object: str = "list" @@ -390,7 +391,7 @@ class ListRunsResponse(BaseModel): """Whether there are more runs available""" -class CancelRunResponse(BaseModel): +class CancelRunResponse(LiteLLMBaseModel): """Response from cancelling a run""" id: str @@ -403,7 +404,7 @@ class CancelRunResponse(BaseModel): """Status after cancellation, always 'cancelled'""" -class RunDeleteResponse(BaseModel): +class RunDeleteResponse(LiteLLMBaseModel): """Response from deleting a run""" run_id: str diff --git a/litellm/types/llms/vertex_ai_gemini_transcription.py b/litellm/types/llms/vertex_ai_gemini_transcription.py index e039bc8f2eb..e78aafaca9f 100644 --- a/litellm/types/llms/vertex_ai_gemini_transcription.py +++ b/litellm/types/llms/vertex_ai_gemini_transcription.py @@ -1,8 +1,10 @@ from typing import Literal -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict from typing_extensions import ReadOnly, TypedDict +from litellm.types.llms.base import LiteLLMBaseModel + class VertexGeminiTranscriptionInlineData(TypedDict): mimeType: ReadOnly[str] @@ -31,32 +33,32 @@ class VertexGeminiTranscriptionRequest(TypedDict): generationConfig: ReadOnly[VertexGeminiTranscriptionGenerationConfig] -class VertexGeminiTranscriptionResponsePart(BaseModel): +class VertexGeminiTranscriptionResponsePart(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") text: str | None = None -class VertexGeminiTranscriptionResponseContent(BaseModel): +class VertexGeminiTranscriptionResponseContent(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") parts: tuple[VertexGeminiTranscriptionResponsePart, ...] = () -class VertexGeminiTranscriptionCandidate(BaseModel): +class VertexGeminiTranscriptionCandidate(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") content: VertexGeminiTranscriptionResponseContent | None = None -class VertexGeminiTranscriptionModalityTokens(BaseModel): +class VertexGeminiTranscriptionModalityTokens(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") modality: str | None = None tokenCount: int = 0 -class VertexGeminiTranscriptionUsageMetadata(BaseModel): +class VertexGeminiTranscriptionUsageMetadata(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") promptTokenCount: int = 0 @@ -65,7 +67,7 @@ class VertexGeminiTranscriptionUsageMetadata(BaseModel): promptTokensDetails: tuple[VertexGeminiTranscriptionModalityTokens, ...] = () -class VertexGeminiTranscriptionResponse(BaseModel): +class VertexGeminiTranscriptionResponse(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") candidates: tuple[VertexGeminiTranscriptionCandidate, ...] = () diff --git a/litellm/types/llms/vertex_ai_gemma.py b/litellm/types/llms/vertex_ai_gemma.py index f64f4d1d4fc..06fa64bbe4f 100644 --- a/litellm/types/llms/vertex_ai_gemma.py +++ b/litellm/types/llms/vertex_ai_gemma.py @@ -1,9 +1,11 @@ from typing import Annotated, Literal -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field + +from litellm.types.llms.base import LiteLLMBaseModel -class VertexGemmaContainerError(BaseModel): +class VertexGemmaContainerError(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) object: Literal["error"] message: str diff --git a/litellm/types/llms/vertex_ai_speech_to_text.py b/litellm/types/llms/vertex_ai_speech_to_text.py index d07a5bbc192..f3d343d13ce 100644 --- a/litellm/types/llms/vertex_ai_speech_to_text.py +++ b/litellm/types/llms/vertex_ai_speech_to_text.py @@ -1,8 +1,10 @@ from typing import Annotated, Literal -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field from typing_extensions import TypedDict +from litellm.types.llms.base import LiteLLMBaseModel + class VertexSpeechToTextAutoDecodingConfig(TypedDict): pass @@ -24,25 +26,25 @@ class VertexSpeechToTextRecognizeRequest(TypedDict): content: str -class VertexSpeechToTextAlternative(BaseModel): +class VertexSpeechToTextAlternative(LiteLLMBaseModel): transcript: str | None = None -class VertexSpeechToTextResult(BaseModel): - alternatives: list[VertexSpeechToTextAlternative] = [] +class VertexSpeechToTextResult(LiteLLMBaseModel): + alternatives: list[VertexSpeechToTextAlternative] = Field(default=[]) languageCode: str | None = None -class VertexSpeechToTextResponseMetadata(BaseModel): +class VertexSpeechToTextResponseMetadata(LiteLLMBaseModel): totalBilledDuration: str | None = None -class VertexSpeechToTextRecognizeResponse(BaseModel): - results: list[VertexSpeechToTextResult] = [] +class VertexSpeechToTextRecognizeResponse(LiteLLMBaseModel): + results: list[VertexSpeechToTextResult] = Field(default=[]) metadata: VertexSpeechToTextResponseMetadata | None = None -class VertexSpeechStreamingConfigure(BaseModel): +class VertexSpeechStreamingConfigure(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) kind: Literal["configure"] = "configure" model: str @@ -50,12 +52,12 @@ class VertexSpeechStreamingConfigure(BaseModel): sample_rate_hertz: int -class VertexSpeechStreamingFinishTurn(BaseModel): +class VertexSpeechStreamingFinishTurn(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) kind: Literal["finish_turn"] = "finish_turn" -class VertexSpeechStreamingDiscardTurn(BaseModel): +class VertexSpeechStreamingDiscardTurn(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) kind: Literal["discard_turn"] = "discard_turn" @@ -66,13 +68,13 @@ VertexSpeechStreamingCommandUnion = ( VertexSpeechStreamingCommand = Annotated[VertexSpeechStreamingCommandUnion, Field(discriminator="kind")] -class VertexSpeechStreamingResult(BaseModel): +class VertexSpeechStreamingResult(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) transcript: str is_final: bool -class VertexSpeechStreamingResponse(BaseModel): +class VertexSpeechStreamingResponse(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) kind: Literal["response"] = "response" speech_event: Literal["none", "begin", "end"] @@ -80,17 +82,17 @@ class VertexSpeechStreamingResponse(BaseModel): billed_seconds: float -class VertexSpeechStreamingConfigured(BaseModel): +class VertexSpeechStreamingConfigured(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) kind: Literal["configured"] = "configured" -class VertexSpeechStreamingTurnFinished(BaseModel): +class VertexSpeechStreamingTurnFinished(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) kind: Literal["turn_finished"] = "turn_finished" -class VertexSpeechStreamingTurnDiscarded(BaseModel): +class VertexSpeechStreamingTurnDiscarded(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) kind: Literal["turn_discarded"] = "turn_discarded" billed_seconds: float diff --git a/litellm/types/management_endpoints/auto_router_endpoints.py b/litellm/types/management_endpoints/auto_router_endpoints.py index ded971f6705..0738f7bc737 100644 --- a/litellm/types/management_endpoints/auto_router_endpoints.py +++ b/litellm/types/management_endpoints/auto_router_endpoints.py @@ -7,9 +7,10 @@ from datetime import datetime, timezone from types import MappingProxyType from typing import Final, Literal, TypeAlias -from pydantic import BaseModel, Field, computed_field, field_validator, model_validator +from pydantic import Field, computed_field, field_validator, model_validator from litellm.router_strategy.complexity_router.config import ComplexityRouterConfig +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import StandardLoggingRoutingDecision DEFAULT_ROUTING_TEST_ROUTER_NAME: Final[str] = "auto_router_routing_test" @@ -28,7 +29,7 @@ class RequestComplexityRouterConfig(ComplexityRouterConfig): ) -class ComplexityRouterConfigValidationRequest(BaseModel): +class ComplexityRouterConfigValidationRequest(LiteLLMBaseModel): """A complexity-router config to validate without saving, so a form can surface the backend's own verdict inline instead of a raw 400 at write time.""" @@ -39,18 +40,18 @@ class ComplexityRouterConfigValidationRequest(BaseModel): ) -class ComplexityRouterConfigValidationResponse(BaseModel): +class ComplexityRouterConfigValidationResponse(LiteLLMBaseModel): valid: bool error: str | None = None -class AutoRouterAvailabilityRequest(BaseModel): +class AutoRouterAvailabilityRequest(LiteLLMBaseModel): team_id: str | None = None saved_model_id: str | None = None complexity_router_config: Mapping[str, object] | None = None -class AutoRouterAllowance(BaseModel): +class AutoRouterAllowance(LiteLLMBaseModel): key: str limit: int | None remaining: int | None @@ -58,12 +59,12 @@ class AutoRouterAllowance(BaseModel): available: bool = True -class AutoRouterAvailabilityResponse(BaseModel): +class AutoRouterAvailabilityResponse(LiteLLMBaseModel): allowances: tuple[AutoRouterAllowance, ...] error: str | None = None -class AutoRouterRoutingTestRequest(BaseModel): +class AutoRouterRoutingTestRequest(LiteLLMBaseModel): """A single request to classify against a complexity-router config that need not be saved yet. Carries the same fields the serving path carries, so a dry run classifies what a real turn @@ -158,7 +159,7 @@ class AutoRouterRoutingTestRequest(BaseModel): ) -class AutoRouterRoutingTestResponse(BaseModel): +class AutoRouterRoutingTestResponse(LiteLLMBaseModel): """Where one prompt would have been routed, and why.""" routed_model: str = Field(description="The model group the router picked") @@ -170,7 +171,7 @@ class AutoRouterRoutingTestResponse(BaseModel): ) -class AutoRouterCacheBucket(BaseModel): +class AutoRouterCacheBucket(LiteLLMBaseModel): """One prompt-caching bucket of turns, with how often those turns hit the cache.""" turns: int = Field(description="Turns classified into this bucket") @@ -178,7 +179,7 @@ class AutoRouterCacheBucket(BaseModel): hit_rate_pct: float = Field(description="hits over this bucket's turns, as a percentage") -class AutoRouterCacheStats(BaseModel): +class AutoRouterCacheStats(LiteLLMBaseModel): """Prompt-caching behaviour of auto-routed turns, bucketed by what the router did. Every in-order turn falls in exactly one bucket: the session stayed on the same model, @@ -204,7 +205,7 @@ class AutoRouterCacheStats(BaseModel): ttl_1h_turns: int = Field(description="Turns whose cache write used the one-hour TTL") -class AutoRouterBenchmarkTotals(BaseModel): +class AutoRouterBenchmarkTotals(LiteLLMBaseModel): """Auto-routed traffic in the window. Turns, spend and savings count requests on the selected UTC days; the session averages and cache stats describe every session overlapping the window, whole.""" @@ -266,7 +267,7 @@ class AutoRouterBenchmarkGroup(AutoRouterBenchmarkTotals): ) -class AutoRouterSessionResponse(BaseModel): +class AutoRouterSessionResponse(LiteLLMBaseModel): """One auto-routed session as its own key sees it: what the last turn ran on, and what the session cost against the router's savings baseline (the priciest model in its hardest tier).""" @@ -299,7 +300,7 @@ class AutoRouterSessionResponse(BaseModel): ) -class AutoRouterBenchmarksResponse(BaseModel): +class AutoRouterBenchmarksResponse(LiteLLMBaseModel): """Benchmarks for the auto-router dashboard, aggregated from the per-session and per-day rollups.""" start_date: str = Field(description="Window start day, YYYY-MM-DD UTC, inclusive") @@ -335,7 +336,7 @@ SHADOW_EVAL_TURN_VALVE: Final[int] = 10_000 SHADOW_EVAL_MAX_ROUTERS: Final[int] = 4 -class StartShadowEvalRequest(BaseModel): +class StartShadowEvalRequest(LiteLLMBaseModel): """Start duplicating one or more targets' traffic for blind comparison against an auto-router. A target is a virtual key, a team, or a user; each becomes its own leg with its own @@ -522,7 +523,7 @@ class StartShadowEvalRequest(BaseModel): return self -class ShadowEvalSlice(BaseModel): +class ShadowEvalSlice(LiteLLMBaseModel): """Judge outcomes for one slice of a job's verdicts: a router tier, one of the models that served the real arm, or one scoped target (embedded on that target's own entry, so slices never need re-joining to a target by id).""" @@ -566,7 +567,7 @@ class ShadowEvalSlice(BaseModel): ) -class ShadowEvalResult(BaseModel): +class ShadowEvalResult(LiteLLMBaseModel): """Stratified results of a shadow-eval job's verdicts so far.""" by_tier: tuple[ShadowEvalSlice, ...] @@ -624,7 +625,7 @@ class ShadowEvalResult(BaseModel): ) -class ShadowEvalJobTargetResponse(BaseModel): +class ShadowEvalJobTargetResponse(LiteLLMBaseModel): """One target a job shadows (a key, team, or user), with its own budget and stop state.""" target_type: ShadowEvalTargetType = Field(description="What kind of entity this entry scopes") @@ -690,7 +691,7 @@ class ShadowEvalJobTargetResponse(BaseModel): ) -class ShadowEvalJobResponse(BaseModel): +class ShadowEvalJobResponse(LiteLLMBaseModel): """A shadow-eval job over one or more targets, each with its own budget and stop state; status is derived from stopped_by, the targets' stop and budget state, and ends_at, never stored, so no writer anywhere can produce an inconsistent one. Aggregate diff --git a/litellm/types/management_endpoints/cache_settings_endpoints.py b/litellm/types/management_endpoints/cache_settings_endpoints.py index cb05f3a50ac..f6394f52c99 100644 --- a/litellm/types/management_endpoints/cache_settings_endpoints.py +++ b/litellm/types/management_endpoints/cache_settings_endpoints.py @@ -4,10 +4,10 @@ Types and field definitions for cache settings management endpoints from typing import Any, Final -from pydantic import BaseModel +from litellm.types.llms.base import LiteLLMBaseModel -class CacheSettingsField(BaseModel): +class CacheSettingsField(LiteLLMBaseModel): field_name: str field_type: str field_value: Any diff --git a/litellm/types/management_endpoints/coordination_redis_endpoints.py b/litellm/types/management_endpoints/coordination_redis_endpoints.py index d70a921a22f..5d429b670dc 100644 --- a/litellm/types/management_endpoints/coordination_redis_endpoints.py +++ b/litellm/types/management_endpoints/coordination_redis_endpoints.py @@ -4,14 +4,14 @@ Types and field definitions for coordination Redis settings management endpoints from typing import Final, Literal -from pydantic import BaseModel +from litellm.types.llms.base import LiteLLMBaseModel CoordinationRedisSection = Literal["connection", "cluster", "sentinel"] CoordinationRedisSource = Literal["coordination_redis", "cache_backend", "environment"] -class CoordinationRedisSettingsField(BaseModel): +class CoordinationRedisSettingsField(LiteLLMBaseModel): field_name: str field_type: str field_value: object | None = None diff --git a/litellm/types/management_endpoints/prompt_cache_prediction.py b/litellm/types/management_endpoints/prompt_cache_prediction.py index 3789607b021..b337d53f1ef 100644 --- a/litellm/types/management_endpoints/prompt_cache_prediction.py +++ b/litellm/types/management_endpoints/prompt_cache_prediction.py @@ -1,12 +1,14 @@ from collections.abc import Mapping from typing import Annotated, Literal, TypeAlias -from pydantic import BaseModel, ConfigDict, Field, JsonValue, StrictInt +from pydantic import ConfigDict, Field, JsonValue, StrictInt + +from litellm.types.llms.base import LiteLLMBaseModel TokenCount: TypeAlias = Annotated[StrictInt, Field(ge=0)] -class CacheTokenBuckets(BaseModel): +class CacheTokenBuckets(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="forbid") uncached_input_tokens: TokenCount = 0 @@ -24,7 +26,7 @@ class CacheTokenBuckets(BaseModel): ) -class CacheEvidence(BaseModel): +class CacheEvidence(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) observed_at: float @@ -33,12 +35,12 @@ class CacheEvidence(BaseModel): confidence: Literal["observed"] = "observed" -class CacheCostScenario(BaseModel): +class CacheCostScenario(LiteLLMBaseModel): tokens: CacheTokenBuckets input_cost: float -class CachePredictionArm(BaseModel): +class CachePredictionArm(LiteLLMBaseModel): deployment_id: str model: str | None = None cache_state: Literal["warm", "partial", "stale", "unknown", "disabled"] = "unknown" @@ -50,7 +52,7 @@ class CachePredictionArm(BaseModel): token_count_source: Literal["anthropic_count_tokens"] | None = None -class CachePredictionRequest(BaseModel): +class CachePredictionRequest(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid") current_deployment_id: str = Field(min_length=1, max_length=256) @@ -58,7 +60,7 @@ class CachePredictionRequest(BaseModel): request: Mapping[str, JsonValue] -class CachePredictionResponse(BaseModel): +class CachePredictionResponse(LiteLLMBaseModel): stay: CachePredictionArm switch: CachePredictionArm switch_delta: float | None diff --git a/litellm/types/management_endpoints/prompt_caching_requests.py b/litellm/types/management_endpoints/prompt_caching_requests.py index e72183a113b..fbf5f20826e 100644 --- a/litellm/types/management_endpoints/prompt_caching_requests.py +++ b/litellm/types/management_endpoints/prompt_caching_requests.py @@ -1,12 +1,14 @@ from datetime import datetime from typing import Literal, TypeAlias -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict + +from litellm.types.llms.base import LiteLLMBaseModel PromptCachingRequestFilter: TypeAlias = Literal["all", "injected", "hits"] -class PromptCachingRequest(BaseModel): +class PromptCachingRequest(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) request_id: str @@ -19,14 +21,14 @@ class PromptCachingRequest(BaseModel): net_savings: float | None -class PromptCachingRequestCursor(BaseModel): +class PromptCachingRequestCursor(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) start_time: datetime request_id: str -class PromptCachingRequestsResponse(BaseModel): +class PromptCachingRequestsResponse(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) requests: tuple[PromptCachingRequest, ...] diff --git a/litellm/types/management_endpoints/router_settings_endpoints.py b/litellm/types/management_endpoints/router_settings_endpoints.py index 4d1ac58edb0..9c8fe446d72 100644 --- a/litellm/types/management_endpoints/router_settings_endpoints.py +++ b/litellm/types/management_endpoints/router_settings_endpoints.py @@ -4,12 +4,14 @@ Types and field definitions for router settings management endpoints from typing import Any, Final, Literal -from pydantic import BaseModel, Field, field_validator +from pydantic import Field, field_validator + +from litellm.types.llms.base import LiteLLMBaseModel # Fallback Management Types -class FallbackCreateRequest(BaseModel): +class FallbackCreateRequest(LiteLLMBaseModel): """Request model for creating/updating fallbacks""" model: str = Field(description="The model name to configure fallbacks for (e.g., 'gpt-3.5-turbo')") @@ -39,7 +41,7 @@ class FallbackCreateRequest(BaseModel): return v.strip() -class FallbackResponse(BaseModel): +class FallbackResponse(LiteLLMBaseModel): """Response model for fallback operations""" model: str = Field(description="The model name") @@ -48,7 +50,7 @@ class FallbackResponse(BaseModel): message: str = Field(description="Success message") -class FallbackGetResponse(BaseModel): +class FallbackGetResponse(LiteLLMBaseModel): """Response model for getting fallbacks""" model: str = Field(description="The model name") @@ -56,7 +58,7 @@ class FallbackGetResponse(BaseModel): fallback_type: str = Field(description="Type of fallback") -class FallbackDeleteResponse(BaseModel): +class FallbackDeleteResponse(LiteLLMBaseModel): """Response model for deleting fallbacks""" model: str = Field(description="The model name") @@ -67,7 +69,7 @@ class FallbackDeleteResponse(BaseModel): # Router Settings Types -class RouterSettingsField(BaseModel): +class RouterSettingsField(LiteLLMBaseModel): field_name: str field_type: str field_value: Any diff --git a/litellm/types/mcp.py b/litellm/types/mcp.py index 949506898b1..556cb6712ae 100644 --- a/litellm/types/mcp.py +++ b/litellm/types/mcp.py @@ -8,10 +8,10 @@ from typing import TYPE_CHECKING, Annotated, Any, Final, Literal from urllib.parse import urlsplit import httpx -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field from typing_extensions import ReadOnly, TypedDict -from litellm.types.llms.base import HiddenParams +from litellm.types.llms.base import HiddenParams, LiteLLMBaseModel if TYPE_CHECKING: import httpx2 @@ -98,7 +98,7 @@ MCPAuthType = ( ) -class MCPPublicServer(BaseModel): +class MCPPublicServer(LiteLLMBaseModel): """ Safe params for public MCP servers """ @@ -113,7 +113,7 @@ class MCPPublicServer(BaseModel): mcp_info: dict[str, Any] | None = None -class MCPAllowedClient(BaseModel): +class MCPAllowedClient(LiteLLMBaseModel): """One entry of `general_settings.mcp_allowed_clients`.""" model_config = ConfigDict(frozen=True) @@ -129,7 +129,7 @@ class MCPAllowedClient(BaseModel): ) -class MCPToolSearchSettings(BaseModel): +class MCPToolSearchSettings(LiteLLMBaseModel): """`litellm_settings.mcp_tool_search`: how the native `mcp_tool_search` virtual tool ranks the caller's tools.""" model_config = ConfigDict(frozen=True) @@ -424,7 +424,7 @@ class MCPStdioConfig(TypedDict, total=False): """ -class MCPPreCallRequestObject(BaseModel): +class MCPPreCallRequestObject(LiteLLMBaseModel): """ Pydantic object used for MCP pre_call_hook request validation and modification """ @@ -438,7 +438,7 @@ class MCPPreCallRequestObject(BaseModel): hidden_params: HiddenParams = HiddenParams() -class MCPPreCallResponseObject(BaseModel): +class MCPPreCallResponseObject(LiteLLMBaseModel): """ Pydantic object used for MCP pre_call_hook response """ @@ -449,7 +449,7 @@ class MCPPreCallResponseObject(BaseModel): hidden_params: HiddenParams = HiddenParams() -class MCPDuringCallRequestObject(BaseModel): +class MCPDuringCallRequestObject(LiteLLMBaseModel): """ Pydantic object used for MCP during_call_hook request """ @@ -463,7 +463,7 @@ class MCPDuringCallRequestObject(BaseModel): hidden_params: HiddenParams = HiddenParams() -class MCPDuringCallResponseObject(BaseModel): +class MCPDuringCallResponseObject(LiteLLMBaseModel): """ Pydantic object used for MCP during_call_hook response """ @@ -473,7 +473,7 @@ class MCPDuringCallResponseObject(BaseModel): hidden_params: HiddenParams = HiddenParams() -class MCPPostCallResponseObject(BaseModel): +class MCPPostCallResponseObject(LiteLLMBaseModel): """ Pydantic object used for MCP post_call_hook response """ @@ -482,7 +482,7 @@ class MCPPostCallResponseObject(BaseModel): hidden_params: HiddenParams -class MCPGatewaySession(BaseModel): +class MCPGatewaySession(LiteLLMBaseModel): """One live stateful Streamable HTTP session held by this proxy worker.""" session_id_prefix: str @@ -498,12 +498,12 @@ class MCPGatewaySession(BaseModel): in_flight_requests: int -class MCPGatewaySessionGroupCount(BaseModel): +class MCPGatewaySessionGroupCount(LiteLLMBaseModel): label: str | None = None count: int -class MCPGatewaySessionsResponse(BaseModel): +class MCPGatewaySessionsResponse(LiteLLMBaseModel): worker_pid: int total_sessions: int by_client: list[MCPGatewaySessionGroupCount] = Field(default_factory=list) @@ -511,7 +511,7 @@ class MCPGatewaySessionsResponse(BaseModel): sessions: list[MCPGatewaySession] = Field(default_factory=list) -class MCPGatewaySessionsTerminateResponse(BaseModel): +class MCPGatewaySessionsTerminateResponse(LiteLLMBaseModel): """Stateful sessions an administrator force-closed on this proxy worker.""" worker_pid: int diff --git a/litellm/types/mcp_server/mcp_server_manager.py b/litellm/types/mcp_server/mcp_server_manager.py index 343fb731b06..c54eda505df 100644 --- a/litellm/types/mcp_server/mcp_server_manager.py +++ b/litellm/types/mcp_server/mcp_server_manager.py @@ -2,9 +2,10 @@ import json from datetime import datetime from typing import Annotated, Any, Final, Literal -from pydantic import AfterValidator, BaseModel, ConfigDict, Field, TypeAdapter, field_validator, model_validator +from pydantic import AfterValidator, ConfigDict, Field, TypeAdapter, field_validator, model_validator from typing_extensions import Self +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.mcp import ( DEFAULT_SUBJECT_TOKEN_TYPE, MCPAuth, @@ -27,7 +28,7 @@ def _validate_mcp_protocol_metadata(value: dict[str, object]) -> dict[str, objec MCPInfo = Annotated[dict[str, Any], AfterValidator(_validate_mcp_protocol_metadata)] -class MCPOAuthMetadata(BaseModel): +class MCPOAuthMetadata(LiteLLMBaseModel): scopes: list[str] | None = None """Resource-driven scopes for the authorization request: the RFC 9728 protected-resource ``scopes_supported``, or the ``scope`` from the WWW-Authenticate 401 challenge when the resource @@ -50,7 +51,7 @@ class MCPOAuthMetadata(BaseModel): usable in memory but must never be persisted as configuration.""" -class MCPOAuthIdentityBinding(BaseModel): +class MCPOAuthIdentityBinding(LiteLLMBaseModel): """Per-server policy binding stored per-user OAuth credentials to the authenticated LiteLLM caller. When enabled for an interactive oauth2 server, the token relay validates the upstream OIDC @@ -70,7 +71,7 @@ class MCPOAuthIdentityBinding(BaseModel): require_email_verified: bool = True -class PinnedMCPTool(BaseModel): +class PinnedMCPTool(LiteLLMBaseModel): """One tool of an admin-pinned catalog: the description and input schema tools/list keeps serving.""" model_config = ConfigDict(frozen=True, extra="forbid") @@ -87,7 +88,7 @@ def parse_pinned_tools(value: object) -> dict[str, PinnedMCPTool] | None: return _PINNED_TOOLS.validate_python(decoded or None) -class MCPServer(BaseModel): +class MCPServer(LiteLLMBaseModel): server_id: str name: str alias: str | None = None @@ -213,7 +214,7 @@ class MCPServer(BaseModel): dcr_bridge: bool | None = None per_server_oauth_discovery: bool = False is_byok: bool = False - byok_description: list[str] = [] + byok_description: list[str] = Field(default=[]) byok_api_key_help_url: str | None = None source_url: str | None = None created_at: datetime | None = None diff --git a/litellm/types/mcp_server/mcp_toolset.py b/litellm/types/mcp_server/mcp_toolset.py index 7e9e03e48ed..2eab0af161f 100644 --- a/litellm/types/mcp_server/mcp_toolset.py +++ b/litellm/types/mcp_server/mcp_toolset.py @@ -1,32 +1,34 @@ from datetime import datetime -from pydantic import BaseModel +from pydantic import Field from typing_extensions import TypedDict +from litellm.types.llms.base import LiteLLMBaseModel + class MCPToolsetTool(TypedDict): server_id: str tool_name: str -class MCPToolset(BaseModel): +class MCPToolset(LiteLLMBaseModel): toolset_id: str toolset_name: str description: str | None = None - tools: list[MCPToolsetTool] = [] + tools: list[MCPToolsetTool] = Field(default=[]) created_at: datetime | None = None created_by: str | None = None updated_at: datetime | None = None updated_by: str | None = None -class NewMCPToolsetRequest(BaseModel): +class NewMCPToolsetRequest(LiteLLMBaseModel): toolset_name: str description: str | None = None - tools: list[MCPToolsetTool] = [] + tools: list[MCPToolsetTool] = Field(default=[]) -class UpdateMCPToolsetRequest(BaseModel): +class UpdateMCPToolsetRequest(LiteLLMBaseModel): toolset_id: str toolset_name: str | None = None description: str | None = None diff --git a/litellm/types/mcp_server/tool_registry.py b/litellm/types/mcp_server/tool_registry.py index 79dedfd7653..df2dda27a38 100644 --- a/litellm/types/mcp_server/tool_registry.py +++ b/litellm/types/mcp_server/tool_registry.py @@ -1,10 +1,12 @@ from collections.abc import Callable from typing import Any, ClassVar -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict + +from litellm.types.llms.base import LiteLLMBaseModel -class MCPTool(BaseModel): +class MCPTool(LiteLLMBaseModel): model_config: ClassVar[ConfigDict] = ConfigDict(arbitrary_types_allowed=True) name: str description: str @@ -12,23 +14,23 @@ class MCPTool(BaseModel): handler: Callable -class ToolSchema(BaseModel): +class ToolSchema(LiteLLMBaseModel): name: str description: str inputSchema: dict[str, Any] -class ListToolsResponse(BaseModel): +class ListToolsResponse(LiteLLMBaseModel): tools: list[ToolSchema] nextCursor: str | None = None _meta: dict[str, Any] | None = None -class CallToolRequest(BaseModel): +class CallToolRequest(LiteLLMBaseModel): method: str = "tools/call" params: dict[str, Any] -class ContentItem(BaseModel): +class ContentItem(LiteLLMBaseModel): type: str text: str | None = None diff --git a/litellm/types/memory_management.py b/litellm/types/memory_management.py index 153de0c6cb9..ad2b328fd1c 100644 --- a/litellm/types/memory_management.py +++ b/litellm/types/memory_management.py @@ -4,10 +4,12 @@ Pydantic models for Memory management endpoints. from datetime import datetime -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel -class LiteLLM_MemoryRow(BaseModel): +class LiteLLM_MemoryRow(LiteLLMBaseModel): memory_id: str key: str value: str @@ -20,7 +22,7 @@ class LiteLLM_MemoryRow(BaseModel): updated_by: str | None = None -class MemoryCreateRequest(BaseModel): +class MemoryCreateRequest(LiteLLMBaseModel): key: str = Field(..., description="Memory key (acts as the namespace in the URL).") value: str = Field(..., description="Memory content. Typically markdown/text for LLM context.") metadata: object | None = Field( @@ -37,7 +39,7 @@ class MemoryCreateRequest(BaseModel): ) -class MemoryUpdateRequest(BaseModel): +class MemoryUpdateRequest(LiteLLMBaseModel): value: str | None = None metadata: object | None = None # Only honored on create (when the row doesn't yet exist) and only for @@ -47,11 +49,11 @@ class MemoryUpdateRequest(BaseModel): team_id: str | None = None -class MemoryListResponse(BaseModel): +class MemoryListResponse(LiteLLMBaseModel): memories: list[LiteLLM_MemoryRow] total: int -class MemoryDeleteResponse(BaseModel): +class MemoryDeleteResponse(LiteLLMBaseModel): key: str deleted: bool diff --git a/litellm/types/model_insights.py b/litellm/types/model_insights.py index 8d4fbbff9d3..5b5a9efed37 100644 --- a/litellm/types/model_insights.py +++ b/litellm/types/model_insights.py @@ -1,11 +1,11 @@ from typing import Literal -from pydantic import BaseModel +from litellm.types.llms.base import LiteLLMBaseModel ModelInsightsMetric = Literal["requests", "spend", "tokens"] -class ModelInsightMetric(BaseModel): +class ModelInsightMetric(LiteLLMBaseModel): model_group: str model: str provider: str @@ -21,7 +21,7 @@ class ModelInsightDailyMetric(ModelInsightMetric): date: str -class ModelInsightDailyTotal(BaseModel): +class ModelInsightDailyTotal(LiteLLMBaseModel): date: str spend: float prompt_tokens: int @@ -29,7 +29,7 @@ class ModelInsightDailyTotal(BaseModel): requests: int -class ModelInsightTask(BaseModel): +class ModelInsightTask(LiteLLMBaseModel): task_type: str label: str category: str @@ -42,7 +42,7 @@ class ModelInsightTaskSummary(ModelInsightTask): provider: str -class ModelInsightsResponse(BaseModel): +class ModelInsightsResponse(LiteLLMBaseModel): start_date: str end_date: str daily: list[ModelInsightDailyMetric] @@ -50,7 +50,7 @@ class ModelInsightsResponse(BaseModel): top_models: list[ModelInsightMetric] -class ModelInsightTasksResponse(BaseModel): +class ModelInsightTasksResponse(LiteLLMBaseModel): start_date: str end_date: str tasks: list[ModelInsightTaskSummary] diff --git a/litellm/types/passthrough_endpoints/vertex_ai.py b/litellm/types/passthrough_endpoints/vertex_ai.py index d1affd7be2c..e350470881f 100644 --- a/litellm/types/passthrough_endpoints/vertex_ai.py +++ b/litellm/types/passthrough_endpoints/vertex_ai.py @@ -2,12 +2,12 @@ Used for /vertex_ai/ pass through endpoints """ -from pydantic import BaseModel +from litellm.types.llms.base import LiteLLMBaseModel from ..llms.vertex_ai import VERTEX_CREDENTIALS_TYPES -class VertexPassThroughCredentials(BaseModel): +class VertexPassThroughCredentials(LiteLLMBaseModel): # Example: vertex_project = "my-project-123" vertex_project: str | None = None diff --git a/litellm/types/prompts/init_prompts.py b/litellm/types/prompts/init_prompts.py index f1a926f9ae0..fc4c36e760a 100644 --- a/litellm/types/prompts/init_prompts.py +++ b/litellm/types/prompts/init_prompts.py @@ -2,7 +2,9 @@ from datetime import datetime from enum import Enum from typing import Any, Literal -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict + +from litellm.types.llms.base import LiteLLMBaseModel class SupportedPromptIntegrations(str, Enum): @@ -15,14 +17,14 @@ class SupportedPromptIntegrations(str, Enum): ARIZE_PHOENIX = "arize_phoenix" -class PromptInfo(BaseModel): +class PromptInfo(LiteLLMBaseModel): prompt_type: Literal["config", "db"] environment: str | None = "development" model_config = ConfigDict(extra="allow", protected_namespaces=()) -class PromptLiteLLMParams(BaseModel): +class PromptLiteLLMParams(LiteLLMBaseModel): prompt_id: str | None = None prompt_integration: str @@ -42,7 +44,7 @@ class PromptLiteLLMParams(BaseModel): model_config = ConfigDict(extra="allow", protected_namespaces=()) -class PromptSpec(BaseModel): +class PromptSpec(LiteLLMBaseModel): prompt_id: str litellm_params: PromptLiteLLMParams prompt_info: PromptInfo @@ -61,17 +63,17 @@ class PromptSpec(BaseModel): super().__init__(**data) -class PromptTemplateBase(BaseModel): +class PromptTemplateBase(LiteLLMBaseModel): litellm_prompt_id: str content: str metadata: dict[str, Any] | None = None -class PromptInfoResponse(BaseModel): +class PromptInfoResponse(LiteLLMBaseModel): prompt_spec: PromptSpec raw_prompt_template: PromptTemplateBase | None = None environments: list[str] | None = None # All environments this prompt is deployed to -class ListPromptsResponse(BaseModel): +class ListPromptsResponse(LiteLLMBaseModel): prompts: list[PromptSpec] diff --git a/litellm/types/proxy/agent_identity.py b/litellm/types/proxy/agent_identity.py index a7fe0be37e1..4492773cdc0 100644 --- a/litellm/types/proxy/agent_identity.py +++ b/litellm/types/proxy/agent_identity.py @@ -2,12 +2,14 @@ from datetime import datetime from typing import Literal, TypeAlias from uuid import UUID -from pydantic import BaseModel, ConfigDict, Field, field_validator +from pydantic import ConfigDict, Field, field_validator + +from litellm.types.llms.base import LiteLLMBaseModel AgentExecutionMode: TypeAlias = Literal["autonomous", "delegated", "both"] -class EntraIdentityConfig(BaseModel): +class EntraIdentityConfig(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="forbid") provider: Literal["microsoft_entra"] @@ -30,7 +32,7 @@ class EntraIdentityConfig(BaseModel): return f"https://login.microsoftonline.com/{self.tenant_id}/v2.0" -class AgentIdentityBinding(BaseModel): +class AgentIdentityBinding(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) agent_id: str @@ -46,7 +48,7 @@ class AgentIdentityBinding(BaseModel): last_authenticated_at: datetime | None = None -class AgentSubject(BaseModel): +class AgentSubject(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) kind: Literal["application", "delegated_subject"] @@ -54,14 +56,14 @@ class AgentSubject(BaseModel): mode: Literal["autonomous", "delegated"] -class AgentIdentityFailure(BaseModel): +class AgentIdentityFailure(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) code: Literal["identity_denied", "policy_unavailable"] = "identity_denied" message: str -class ManagedAgentContext(BaseModel): +class ManagedAgentContext(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) agent_id: str @@ -71,7 +73,7 @@ class ManagedAgentContext(BaseModel): subject_oid: str | None = None -class VerifiedHumanSubject(BaseModel): +class VerifiedHumanSubject(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) issuer: str @@ -80,7 +82,7 @@ class VerifiedHumanSubject(BaseModel): user_id: str -class MicrosoftInteractiveSubject(BaseModel): +class MicrosoftInteractiveSubject(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) issuer: str @@ -88,7 +90,7 @@ class MicrosoftInteractiveSubject(BaseModel): oid: str -class ManagedAgentIdentityStatus(BaseModel): +class ManagedAgentIdentityStatus(LiteLLMBaseModel): identity: AgentIdentityBinding | None = None identity_managed: bool = False enabled: bool = True diff --git a/litellm/types/proxy/callback_logs_endpoints.py b/litellm/types/proxy/callback_logs_endpoints.py index 0ff1d5a2273..b2519d97122 100644 --- a/litellm/types/proxy/callback_logs_endpoints.py +++ b/litellm/types/proxy/callback_logs_endpoints.py @@ -7,12 +7,13 @@ payloads here; the proxy replays them through the standard callback fan-out. from typing import Any, Literal -from pydantic import BaseModel, Field +from pydantic import Field from litellm.constants import MAX_CALLBACK_LOG_RECORDS +from litellm.types.llms.base import LiteLLMBaseModel -class CallbackLogRecord(BaseModel): +class CallbackLogRecord(LiteLLMBaseModel): """A single finished logging event to replay through the callbacks.""" status: Literal["success", "failure"] @@ -20,7 +21,7 @@ class CallbackLogRecord(BaseModel): error: str | None = None -class CallbackLogsRequest(BaseModel): +class CallbackLogsRequest(LiteLLMBaseModel): """A batch of logging events posted by an external producer.""" # Bounded so one POST can't trigger an unbounded callback/DB fan-out (each @@ -28,14 +29,14 @@ class CallbackLogsRequest(BaseModel): records: list[CallbackLogRecord] = Field(..., max_length=MAX_CALLBACK_LOG_RECORDS) -class CallbackLogFailure(BaseModel): +class CallbackLogFailure(LiteLLMBaseModel): """A record that failed to replay, identified by its index in the batch.""" index: int error: str -class CallbackLogsResponse(BaseModel): +class CallbackLogsResponse(LiteLLMBaseModel): """Per-batch result: counts plus per-record failure detail so the caller can distinguish a transient callback error from a structurally bad payload.""" diff --git a/litellm/types/proxy/carried_budget_state.py b/litellm/types/proxy/carried_budget_state.py index 0e64b91645d..1a0c55a38ff 100644 --- a/litellm/types/proxy/carried_budget_state.py +++ b/litellm/types/proxy/carried_budget_state.py @@ -10,11 +10,13 @@ from collections.abc import Mapping from datetime import datetime from types import MappingProxyType -from pydantic import BaseModel, ConfigDict, Field, ValidationError +from pydantic import ConfigDict, Field, ValidationError from typing_extensions import Self +from litellm.types.llms.base import LiteLLMBaseModel -class _BudgetSnapshot(BaseModel): + +class _BudgetSnapshot(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, populate_by_name=True, extra="ignore") def metadata_entries(self) -> Mapping[str, object]: diff --git a/litellm/types/proxy/claude_code_endpoints.py b/litellm/types/proxy/claude_code_endpoints.py index dcb5561cfeb..28285838637 100644 --- a/litellm/types/proxy/claude_code_endpoints.py +++ b/litellm/types/proxy/claude_code_endpoints.py @@ -2,24 +2,26 @@ Claude Code Marketplace endpoint types for LiteLLM Proxy """ -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel -class PluginAuthor(BaseModel): +class PluginAuthor(LiteLLMBaseModel): """Plugin author information.""" name: str = Field(..., description="Author name") email: str | None = Field(None, description="Author email") -class PluginOwner(BaseModel): +class PluginOwner(LiteLLMBaseModel): """Marketplace owner information.""" name: str = Field(..., description="Owner name") email: str | None = Field(None, description="Owner email") -class PluginSpec(BaseModel): +class PluginSpec(LiteLLMBaseModel): """Mutable fields shared by plugin create and update requests.""" source: dict[str, str] = Field( @@ -71,7 +73,7 @@ class UpdatePluginRequest(PluginSpec): version: str | None = Field(None, description="Semantic version; cleared if omitted") -class PluginResponse(BaseModel): +class PluginResponse(LiteLLMBaseModel): """Plugin information in API responses.""" id: str = Field(..., description="Plugin unique ID") @@ -82,7 +84,7 @@ class PluginResponse(BaseModel): enabled: bool = Field(..., description="Whether plugin is enabled") -class RegisterPluginResponse(BaseModel): +class RegisterPluginResponse(LiteLLMBaseModel): """Response from plugin registration.""" status: str = Field(..., description="Operation status") @@ -90,7 +92,7 @@ class RegisterPluginResponse(BaseModel): plugin: PluginResponse = Field(..., description="Plugin information") -class PluginListItem(BaseModel): +class PluginListItem(LiteLLMBaseModel): """Plugin item in list responses.""" id: str @@ -109,14 +111,14 @@ class PluginListItem(BaseModel): updated_at: str | None -class ListPluginsResponse(BaseModel): +class ListPluginsResponse(LiteLLMBaseModel): """Response from listing plugins.""" plugins: list[PluginListItem] count: int -class MarketplacePluginEntry(BaseModel): +class MarketplacePluginEntry(LiteLLMBaseModel): """Plugin entry in marketplace.json.""" name: str @@ -129,7 +131,7 @@ class MarketplacePluginEntry(BaseModel): category: str | None = None -class MarketplaceResponse(BaseModel): +class MarketplaceResponse(LiteLLMBaseModel): """ Marketplace catalog response. diff --git a/litellm/types/proxy/cloudzero_endpoints.py b/litellm/types/proxy/cloudzero_endpoints.py index 70b779338f8..ece294674b9 100644 --- a/litellm/types/proxy/cloudzero_endpoints.py +++ b/litellm/types/proxy/cloudzero_endpoints.py @@ -5,10 +5,12 @@ CloudZero endpoint types for LiteLLM Proxy from datetime import datetime from typing import Any -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel -class CloudZeroInitRequest(BaseModel): +class CloudZeroInitRequest(LiteLLMBaseModel): """Request model for initializing CloudZero settings""" api_key: str = Field(..., description="CloudZero API key for authentication") @@ -16,14 +18,14 @@ class CloudZeroInitRequest(BaseModel): timezone: str = Field(default="UTC", description="Timezone for date handling (default: UTC)") -class CloudZeroInitResponse(BaseModel): +class CloudZeroInitResponse(LiteLLMBaseModel): """Response model for CloudZero initialization""" message: str status: str -class CloudZeroExportRequest(BaseModel): +class CloudZeroExportRequest(LiteLLMBaseModel): """Request model for CloudZero export operations""" limit: int | None = Field(None, description="Optional limit on number of records to export") @@ -35,7 +37,7 @@ class CloudZeroExportRequest(BaseModel): end_time_utc: datetime | None = Field(None, description="End time for data export in UTC") -class CloudZeroExportResponse(BaseModel): +class CloudZeroExportResponse(LiteLLMBaseModel): """Response model for CloudZero export operations""" message: str @@ -47,7 +49,7 @@ class CloudZeroExportResponse(BaseModel): summary: dict[str, Any] | None = Field(None, description="Summary statistics for dry run") -class CloudZeroSettingsView(BaseModel): +class CloudZeroSettingsView(LiteLLMBaseModel): """Response model for viewing CloudZero settings with masked API key""" api_key_masked: str | None = Field(None, description="Masked API key showing only first 4 and last 4 characters") @@ -56,7 +58,7 @@ class CloudZeroSettingsView(BaseModel): status: str | None = Field(None, description="Configuration status") -class CloudZeroSettingsUpdate(BaseModel): +class CloudZeroSettingsUpdate(LiteLLMBaseModel): """Request model for updating CloudZero settings""" api_key: str | None = Field(None, description="New CloudZero API key for authentication") diff --git a/litellm/types/proxy/compliance_endpoints.py b/litellm/types/proxy/compliance_endpoints.py index 0c1a11bf594..ef3fc73ef9a 100644 --- a/litellm/types/proxy/compliance_endpoints.py +++ b/litellm/types/proxy/compliance_endpoints.py @@ -1,7 +1,7 @@ -from pydantic import BaseModel +from litellm.types.llms.base import LiteLLMBaseModel -class ComplianceCheckResult(BaseModel): +class ComplianceCheckResult(LiteLLMBaseModel): """Result of a single compliance check.""" check_name: str @@ -10,7 +10,7 @@ class ComplianceCheckResult(BaseModel): detail: str -class ComplianceResponse(BaseModel): +class ComplianceResponse(LiteLLMBaseModel): """Response from a compliance check endpoint.""" compliant: bool @@ -18,7 +18,7 @@ class ComplianceResponse(BaseModel): checks: list[ComplianceCheckResult] -class ComplianceCheckRequest(BaseModel): +class ComplianceCheckRequest(LiteLLMBaseModel): """Request payload for compliance check endpoints. Mirrors the spend log fields needed for compliance evaluation. diff --git a/litellm/types/proxy/control_plane_endpoints.py b/litellm/types/proxy/control_plane_endpoints.py index 8bf4c44b205..d75fd0a38b4 100644 --- a/litellm/types/proxy/control_plane_endpoints.py +++ b/litellm/types/proxy/control_plane_endpoints.py @@ -1,7 +1,9 @@ -from pydantic import BaseModel, field_validator +from pydantic import field_validator + +from litellm.types.llms.base import LiteLLMBaseModel -class WorkerRegistryEntry(BaseModel): +class WorkerRegistryEntry(LiteLLMBaseModel): worker_id: str name: str url: str diff --git a/litellm/types/proxy/discovery_endpoints/agent_skills_endpoints.py b/litellm/types/proxy/discovery_endpoints/agent_skills_endpoints.py index 0d8bb29e172..c3275c7a1cc 100644 --- a/litellm/types/proxy/discovery_endpoints/agent_skills_endpoints.py +++ b/litellm/types/proxy/discovery_endpoints/agent_skills_endpoints.py @@ -5,14 +5,16 @@ Schema: https://schemas.agentskills.io/discovery/0.2.0/schema.json from typing import Final, Literal -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel AGENT_SKILLS_DISCOVERY_SCHEMA_URL: Final = "https://schemas.agentskills.io/discovery/0.2.0/schema.json" MAX_SKILL_NAME_LENGTH: Final = 64 MAX_SKILL_DESCRIPTION_LENGTH: Final = 1024 -class AgentSkillsIndexEntry(BaseModel): +class AgentSkillsIndexEntry(LiteLLMBaseModel): name: str type: Literal["archive"] description: str @@ -20,6 +22,6 @@ class AgentSkillsIndexEntry(BaseModel): digest: str -class AgentSkillsIndex(BaseModel): +class AgentSkillsIndex(LiteLLMBaseModel): discovery_schema: str = Field(default=AGENT_SKILLS_DISCOVERY_SCHEMA_URL, alias="$schema") skills: tuple[AgentSkillsIndexEntry, ...] diff --git a/litellm/types/proxy/discovery_endpoints/ui_discovery_endpoints.py b/litellm/types/proxy/discovery_endpoints/ui_discovery_endpoints.py index 4e0faabc132..c30fb7caf2e 100644 --- a/litellm/types/proxy/discovery_endpoints/ui_discovery_endpoints.py +++ b/litellm/types/proxy/discovery_endpoints/ui_discovery_endpoints.py @@ -1,9 +1,10 @@ -from pydantic import BaseModel +from pydantic import Field +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.control_plane_endpoints import WorkerRegistryEntry -class UiDiscoveryEndpoints(BaseModel): +class UiDiscoveryEndpoints(LiteLLMBaseModel): server_root_path: str proxy_base_url: str | None auto_redirect_to_sso: bool @@ -12,4 +13,4 @@ class UiDiscoveryEndpoints(BaseModel): hide_default_credentials_hint: bool = False is_control_plane: bool = False mcp_stdio_enabled: bool = False - workers: list[WorkerRegistryEntry] = [] + workers: list[WorkerRegistryEntry] = Field(default=[]) diff --git a/litellm/types/proxy/gateway_requests.py b/litellm/types/proxy/gateway_requests.py index f0abeb3c950..77607899dde 100644 --- a/litellm/types/proxy/gateway_requests.py +++ b/litellm/types/proxy/gateway_requests.py @@ -4,7 +4,7 @@ from collections.abc import Mapping from dataclasses import dataclass from typing import TypeAlias -from pydantic import BaseModel +from litellm.types.llms.base import LiteLLMBaseModel @dataclass(frozen=True, slots=True) @@ -29,20 +29,20 @@ class GatewayRequestCounts: GatewayRequestSnapshot: TypeAlias = Mapping[GatewayRequestKey, GatewayRequestCounts] -class GatewayRequestBreakdownEntry(BaseModel): +class GatewayRequestBreakdownEntry(LiteLLMBaseModel): category: str route: str successful_requests: int = 0 failed_requests: int = 0 -class GatewayRequestDailyEntry(BaseModel): +class GatewayRequestDailyEntry(LiteLLMBaseModel): date: str successful_requests: int = 0 failed_requests: int = 0 -class GatewayRequestActivityResponse(BaseModel): +class GatewayRequestActivityResponse(LiteLLMBaseModel): """Response for GET /gateway/daily/activity.""" total_successful_requests: int = 0 diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/azure/azure_text_moderation.py b/litellm/types/proxy/guardrails/guardrail_hooks/azure/azure_text_moderation.py index 83b8d281100..90662e84ed5 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/azure/azure_text_moderation.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/azure/azure_text_moderation.py @@ -1,8 +1,10 @@ from typing import Any, Final, Literal -from pydantic import BaseModel, Field +from pydantic import Field from typing_extensions import Required, TypedDict +from litellm.types.llms.base import LiteLLMBaseModel + from ..base import GuardrailConfigModel from .base import AzureContentSafetyConfigModel @@ -42,7 +44,7 @@ class AzureTextModerationGuardrailResponse(TypedDict): AzureHarmCategories = Literal["Hate", "SelfHarm", "Sexual", "Violence"] -class AzureTextModerationOptionalParams(BaseModel): +class AzureTextModerationOptionalParams(LiteLLMBaseModel): severity_threshold: int | None = Field( default=None, description="Severity threshold for the Azure Content Safety Text Moderation guardrail across all categories", diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/azure/base.py b/litellm/types/proxy/guardrails/guardrail_hooks/azure/base.py index c72888f33e1..cc09e2b679d 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/azure/base.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/azure/base.py @@ -1,7 +1,9 @@ -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel -class AzureContentSafetyConfigModel(BaseModel): +class AzureContentSafetyConfigModel(LiteLLMBaseModel): """Configuration parameters for the Azure Content Safety Prompt Shield guardrail""" api_key: str | None = Field( diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/base.py b/litellm/types/proxy/guardrails/guardrail_hooks/base.py index d965ad361bc..a3c5e74d701 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/base.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/base.py @@ -3,10 +3,12 @@ from typing import Generic, TypeVar from pydantic import BaseModel, Field +from litellm.types.llms.base import LiteLLMBaseModel + T = TypeVar("T", bound=BaseModel) -class GuardrailConfigModel(BaseModel, Generic[T], ABC): +class GuardrailConfigModel(LiteLLMBaseModel, Generic[T], ABC): """Base model for guardrail configuration""" optional_params: T | None = Field( diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/cisco_ai_defense.py b/litellm/types/proxy/guardrails/guardrail_hooks/cisco_ai_defense.py index 4d6d28dd07b..46f1bd33e47 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/cisco_ai_defense.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/cisco_ai_defense.py @@ -4,7 +4,9 @@ Cisco AI Defense Guardrail Config Model from typing import Literal -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field + +from litellm.types.llms.base import LiteLLMBaseModel from .base import GuardrailConfigModel @@ -30,7 +32,7 @@ CISCO_AI_DEFENSE_RULE_NAMES = Literal[ CISCO_AI_DEFENSE_INSPECTION_TYPE = Literal["chat", "mcp"] -class CiscoAIDefenseRule(BaseModel): +class CiscoAIDefenseRule(LiteLLMBaseModel): """A single rule to enable for Cisco AI Defense inspection.""" rule_name: CISCO_AI_DEFENSE_RULE_NAMES = Field( @@ -45,7 +47,7 @@ class CiscoAIDefenseRule(BaseModel): ) -class CiscoAIDefenseGuardrailConfigModelOptionalParams(BaseModel): +class CiscoAIDefenseGuardrailConfigModelOptionalParams(LiteLLMBaseModel): """Optional parameters for the Cisco AI Defense guardrail.""" model_config = ConfigDict(extra="allow") diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/compresr.py b/litellm/types/proxy/guardrails/guardrail_hooks/compresr.py index 9efc2fbff55..6598f1de62b 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/compresr.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/compresr.py @@ -1,11 +1,13 @@ from typing import Any, Literal -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel from .base import GuardrailConfigModel -class CompresrGuardrailOptionalParams(BaseModel): +class CompresrGuardrailOptionalParams(LiteLLMBaseModel): """Optional tuning knobs for the Compresr guardrail.""" target_compression_ratio: float | None = Field( diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/conduct.py b/litellm/types/proxy/guardrails/guardrail_hooks/conduct.py index fbff4363351..3c541e289e1 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/conduct.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/conduct.py @@ -2,12 +2,14 @@ from __future__ import annotations from typing import Literal -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel from .base import GuardrailConfigModel -class ConductGuardrailConfigModelOptionalParams(BaseModel): +class ConductGuardrailConfigModelOptionalParams(LiteLLMBaseModel): workspace_id: str | None = Field( default=None, description="Conduct workspace id, sent as the X-Workspace-Id header. Env: CONDUCT_WORKSPACE_ID.", diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/crowdstrike_aidr.py b/litellm/types/proxy/guardrails/guardrail_hooks/crowdstrike_aidr.py index df1caab6af6..66e1e12e99c 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/crowdstrike_aidr.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/crowdstrike_aidr.py @@ -1,9 +1,11 @@ -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel from .base import GuardrailConfigModel -class CrowdStrikeAIDRGuardrailConfigModelOptionalParams(BaseModel): +class CrowdStrikeAIDRGuardrailConfigModelOptionalParams(LiteLLMBaseModel): streaming_buffer_until_moderated: bool | None = Field( default=None, description="When True, withhold streamed chunks until moderation passes. Defaults to False when unset.", diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/deepkeep.py b/litellm/types/proxy/guardrails/guardrail_hooks/deepkeep.py index 9830faffc23..67a3466919a 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/deepkeep.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/deepkeep.py @@ -1,9 +1,11 @@ -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel from .base import GuardrailConfigModel -class DeepKeepGuardrailConfigModelOptionalParams(BaseModel): +class DeepKeepGuardrailConfigModelOptionalParams(LiteLLMBaseModel): unreachable_fallback: str | None = Field( default="fail_closed", description=( diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/enkryptai.py b/litellm/types/proxy/guardrails/guardrail_hooks/enkryptai.py index 9b0d448ded2..d1eba1dd4a9 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/enkryptai.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/enkryptai.py @@ -1,8 +1,10 @@ from typing import Any -from pydantic import BaseModel, Field +from pydantic import Field from typing_extensions import TypedDict +from litellm.types.llms.base import LiteLLMBaseModel + from .base import GuardrailConfigModel # TypedDicts for EnkryptAI API Response Structure @@ -110,7 +112,7 @@ class EnkryptAIProcessedResult(TypedDict): # Pydantic Config Model -class EnkryptAIGuardrailConfigs(BaseModel): +class EnkryptAIGuardrailConfigs(LiteLLMBaseModel): """Configuration parameters for the EnkryptAI guardrail""" api_key: str | None = Field( diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/generic_guardrail_api.py b/litellm/types/proxy/guardrails/guardrail_hooks/generic_guardrail_api.py index 44e2cc2404f..49eaa154fec 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/generic_guardrail_api.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/generic_guardrail_api.py @@ -1,9 +1,10 @@ from collections.abc import Mapping, Sequence from typing import Any, Final, Literal, cast # noqa: TID251 # JSON chat rows have no typed constructor across roles -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field from typing_extensions import TypedDict +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.llms.openai import ( AllMessageValues, ChatCompletionToolCallChunk, @@ -12,7 +13,7 @@ from litellm.types.proxy.guardrails.guardrail_hooks.base import GuardrailConfigM from litellm.types.utils import ChatCompletionMessageToolCall -class GuardrailToolParam(BaseModel): +class GuardrailToolParam(LiteLLMBaseModel): """A tool forwarded verbatim to the guardrail for inspection. Built-in tools (code_interpreter, file_search, ...) have no ``function`` block @@ -35,7 +36,7 @@ class GenericGuardrailAPIMetadata(TypedDict, total=False): user_api_key_org_id: str | None -class GenericGuardrailAPIOptionalParams(BaseModel): +class GenericGuardrailAPIOptionalParams(LiteLLMBaseModel): """Optional parameters for the Generic Guardrail API""" additional_provider_specific_params: dict[str, Any] | None = Field( @@ -119,7 +120,7 @@ class GenericGuardrailAPIConfigModel( return "Generic Guardrail API" -class GenericGuardrailAPIRequest(BaseModel): +class GenericGuardrailAPIRequest(LiteLLMBaseModel): """Request model for the Generic Guardrail API""" input_type: Literal["request", "response"] diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/grayswan.py b/litellm/types/proxy/guardrails/guardrail_hooks/grayswan.py index 796ff2818a4..9c2cb1e517e 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/grayswan.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/grayswan.py @@ -1,11 +1,13 @@ """Gray Swan guardrail configuration models.""" -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel from .base import GuardrailConfigModel -class GraySwanGuardrailConfigModelOptionalParams(BaseModel): +class GraySwanGuardrailConfigModelOptionalParams(LiteLLMBaseModel): """Optional parameters for the Gray Swan guardrail.""" on_flagged_action: str | None = Field( diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/ibm/base.py b/litellm/types/proxy/guardrails/guardrail_hooks/ibm/base.py index 22f6b2fd7dc..e695ab0b4b8 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/ibm/base.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/ibm/base.py @@ -1,7 +1,9 @@ -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel -class IBMGuardrailsBaseConfigModel(BaseModel): +class IBMGuardrailsBaseConfigModel(LiteLLMBaseModel): """Base configuration parameters for IBM Guardrails""" auth_token: str | None = Field( diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/ibm/ibm_detector.py b/litellm/types/proxy/guardrails/guardrail_hooks/ibm/ibm_detector.py index 5226d5fe6de..b58d1bff8a2 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/ibm/ibm_detector.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/ibm/ibm_detector.py @@ -1,8 +1,10 @@ from typing import Any -from pydantic import BaseModel, Field +from pydantic import Field from typing_extensions import TypedDict +from litellm.types.llms.base import LiteLLMBaseModel + from ..base import GuardrailConfigModel from .base import IBMGuardrailsBaseConfigModel @@ -52,7 +54,7 @@ class IBMDetectorResponseOrchestrator(TypedDict): # Pydantic Config Models -class IBMDetectorOptionalParams(BaseModel): +class IBMDetectorOptionalParams(LiteLLMBaseModel): """Optional parameters for IBM Detector guardrail""" detector_params: dict[str, Any] | None = Field( diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/lasso.py b/litellm/types/proxy/guardrails/guardrail_hooks/lasso.py index e562e79dd45..77b13ad5f5d 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/lasso.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/lasso.py @@ -1,9 +1,11 @@ -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel from .base import GuardrailConfigModel -class LassoGuardrailConfigModelOptionalParams(BaseModel): +class LassoGuardrailConfigModelOptionalParams(LiteLLMBaseModel): user_id: str | None = Field( default=None, description="The user ID for the Lasso guardrail. If not provided, the `LASSO_USER_ID` environment variable is checked.", diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/pangea.py b/litellm/types/proxy/guardrails/guardrail_hooks/pangea.py index e9a01810151..55c65158e30 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/pangea.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/pangea.py @@ -1,9 +1,11 @@ -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel from .base import GuardrailConfigModel -class PangeaGuardrailConfigModelOptionalParams(BaseModel): +class PangeaGuardrailConfigModelOptionalParams(LiteLLMBaseModel): pangea_input_recipe: str | None = Field( default=None, description="The Pangea input recipe for the Pangea guardrail. Used for pre-call hook.", diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/pillar.py b/litellm/types/proxy/guardrails/guardrail_hooks/pillar.py index 248f3f6d2d6..e4c7ca0f589 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/pillar.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/pillar.py @@ -2,12 +2,14 @@ Pillar Security Guardrail Config Model """ -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel from .base import GuardrailConfigModel -class PillarGuardrailConfigModelOptionalParams(BaseModel): +class PillarGuardrailConfigModelOptionalParams(LiteLLMBaseModel): """Optional parameters for the Pillar Security guardrail""" on_flagged_action: str | None = Field( diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/singulr.py b/litellm/types/proxy/guardrails/guardrail_hooks/singulr.py index ea1e6238181..68713bf1a55 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/singulr.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/singulr.py @@ -1,34 +1,36 @@ from collections.abc import Mapping, Sequence from typing import Literal -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel from .base import GuardrailConfigModel -class ContentBlock(BaseModel): +class ContentBlock(LiteLLMBaseModel): type: str | None = None text: str | None = None -class ToolCallFunction(BaseModel): +class ToolCallFunction(LiteLLMBaseModel): name: str arguments: str -class ToolCall(BaseModel): +class ToolCall(LiteLLMBaseModel): id: str type: str = "function" function: ToolCallFunction -class AssistantMessage(BaseModel): +class AssistantMessage(LiteLLMBaseModel): role: Literal["assistant"] = "assistant" content: str | Sequence[ContentBlock] | None = None tool_calls: Sequence[ToolCall] | None = None -class SingulrGuardrailPayload(BaseModel): +class SingulrGuardrailPayload(LiteLLMBaseModel): correlation_id: str | None = None model_name: str | None = None model_provider_name: str | None = None @@ -40,7 +42,7 @@ class SingulrGuardrailPayload(BaseModel): metadata: Mapping[str, str] | None = None -class SingulrMcpGuardrailPayload(BaseModel): +class SingulrMcpGuardrailPayload(LiteLLMBaseModel): model_name: str | None = None guardrail_scope: str | None = None tool_name: str | None = None @@ -50,7 +52,7 @@ class SingulrMcpGuardrailPayload(BaseModel): metadata: Mapping[str, str] | None = None -class SingulrGuardrailResponse(BaseModel): +class SingulrGuardrailResponse(LiteLLMBaseModel): """Response returned by the Singulr guardrail API.""" should_block: bool = False diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/straiker.py b/litellm/types/proxy/guardrails/guardrail_hooks/straiker.py index 18a4608c46c..e90bd3a1796 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/straiker.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/straiker.py @@ -2,7 +2,9 @@ from __future__ import annotations from typing import Final, Literal -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field + +from litellm.types.llms.base import LiteLLMBaseModel from .base import GuardrailConfigModel @@ -13,18 +15,18 @@ StraikerWebhookAction = Literal["NONE", "BLOCKED", "GUARDRAIL_INTERVENED"] STRAIKER_WEBHOOK_SCHEMA_VERSION: Final = "1" -class StraikerWebhookStream(BaseModel): +class StraikerWebhookStream(LiteLLMBaseModel): phase: StraikerWebhookStreamPhase = "none" index: int | None = None -class StraikerWebhookEvent(BaseModel): +class StraikerWebhookEvent(LiteLLMBaseModel): type: StraikerWebhookEventType id: str stream: StraikerWebhookStream = Field(default_factory=StraikerWebhookStream) -class StraikerWebhookContent(BaseModel): +class StraikerWebhookContent(LiteLLMBaseModel): model_config = ConfigDict(extra="ignore") texts: list[str] = Field(default_factory=list) @@ -35,12 +37,12 @@ class StraikerWebhookContent(BaseModel): finish_reason: str | None = None -class StraikerWebhookUsage(BaseModel): +class StraikerWebhookUsage(LiteLLMBaseModel): input_tokens: int | None = None output_tokens: int | None = None -class StraikerWebhookContext(BaseModel): +class StraikerWebhookContext(LiteLLMBaseModel): call_surface: str mode: list[str] | None = None model: str | None = None @@ -52,7 +54,7 @@ class StraikerWebhookContext(BaseModel): litellm_version: str | None = None -class StraikerWebhookIdentity(BaseModel): +class StraikerWebhookIdentity(LiteLLMBaseModel): litellm_key: str | None = None litellm_team: str | None = None litellm_user_id: str | None = None @@ -61,12 +63,12 @@ class StraikerWebhookIdentity(BaseModel): end_user_id: str | None = None -class StraikerWebhookApplication(BaseModel): +class StraikerWebhookApplication(LiteLLMBaseModel): source: str name: str | None = None -class StraikerWebhookRequest(BaseModel): +class StraikerWebhookRequest(LiteLLMBaseModel): schema_version: str = STRAIKER_WEBHOOK_SCHEMA_VERSION event: StraikerWebhookEvent request: StraikerWebhookContent @@ -78,7 +80,7 @@ class StraikerWebhookRequest(BaseModel): metadata: dict[str, object] | None = None -class StraikerWebhookResponse(BaseModel): +class StraikerWebhookResponse(LiteLLMBaseModel): model_config = ConfigDict(extra="allow") action: StraikerWebhookAction = "NONE" @@ -91,7 +93,7 @@ class StraikerWebhookResponse(BaseModel): turn_id: str | None = Field(default=None, alias="turnId") -class StraikerGuardrailConfigModelOptionalParams(BaseModel): +class StraikerGuardrailConfigModelOptionalParams(LiteLLMBaseModel): timeout: float | None = Field( default=5.0, gt=0.0, diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/tool_permission.py b/litellm/types/proxy/guardrails/guardrail_hooks/tool_permission.py index a31d198d605..6f521d1fd1b 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/tool_permission.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/tool_permission.py @@ -1,12 +1,14 @@ # Tool Permission Guardrail Type Definitions from typing import Final, Literal -from pydantic import BaseModel, Field, field_validator, model_validator +from pydantic import Field, field_validator, model_validator + +from litellm.types.llms.base import LiteLLMBaseModel from .base import GuardrailConfigModel -class ToolPermissionRule(BaseModel): +class ToolPermissionRule(LiteLLMBaseModel): """ A rule defining permission for a specific tool or tool pattern """ @@ -53,7 +55,7 @@ class ToolPermissionRule(BaseModel): return self -class ToolResult(BaseModel): +class ToolResult(LiteLLMBaseModel): """ Represents a tool_result block to be added to the response """ @@ -64,7 +66,7 @@ class ToolResult(BaseModel): is_error: bool = Field(default=True, description="Whether this is an error result") -class PermissionError(BaseModel): +class PermissionError(LiteLLMBaseModel): """ Error information for permission denial """ diff --git a/litellm/types/proxy/guardrails/guardrail_hooks/typesafe.py b/litellm/types/proxy/guardrails/guardrail_hooks/typesafe.py index 59482d2e190..d79d65760ce 100644 --- a/litellm/types/proxy/guardrails/guardrail_hooks/typesafe.py +++ b/litellm/types/proxy/guardrails/guardrail_hooks/typesafe.py @@ -1,11 +1,13 @@ from typing import Literal -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel from .base import GuardrailConfigModel -class TypeSafeGuardrailOptionalParams(BaseModel): +class TypeSafeGuardrailOptionalParams(LiteLLMBaseModel): """Optional tuning knobs for the TypeSafe (Jev) compaction guardrail.""" relevance_threshold: float | None = Field( diff --git a/litellm/types/proxy/management_endpoints/common_daily_activity.py b/litellm/types/proxy/management_endpoints/common_daily_activity.py index 37804032569..9f7f666f494 100644 --- a/litellm/types/proxy/management_endpoints/common_daily_activity.py +++ b/litellm/types/proxy/management_endpoints/common_daily_activity.py @@ -2,9 +2,11 @@ from datetime import date from enum import Enum from typing import Any -from pydantic import BaseModel, Field +from pydantic import Field from typing_extensions import TypedDict +from litellm.types.llms.base import LiteLLMBaseModel + class GroupByDimension(str, Enum): DATE = "date" @@ -16,7 +18,7 @@ class GroupByDimension(str, Enum): PROVIDER = "custom_llm_provider" -class SpendMetrics(BaseModel): +class SpendMetrics(LiteLLMBaseModel): spend: float = Field(default=0.0) flat_cost: float = Field(default=0.0) prompt_tokens: int = Field(default=0) @@ -36,11 +38,11 @@ class SpendMetrics(BaseModel): timed_requests: int = Field(default=0) -class MetricBase(BaseModel): +class MetricBase(LiteLLMBaseModel): metrics: SpendMetrics -class KeyMetadata(BaseModel): +class KeyMetadata(LiteLLMBaseModel): """Metadata for a key""" key_alias: str | None = None @@ -62,7 +64,7 @@ class MetricWithMetadata(MetricBase): api_key_breakdown: dict[str, KeyMetricWithMetadata] = Field(default_factory=dict) # api_key -> {metrics, metadata} -class BreakdownMetrics(BaseModel): +class BreakdownMetrics(LiteLLMBaseModel): """Breakdown of spend by different dimensions""" mcp_servers: dict[str, MetricWithMetadata] = Field(default_factory=dict) # mcp_server -> {metrics, metadata} @@ -74,13 +76,13 @@ class BreakdownMetrics(BaseModel): entities: dict[str, MetricWithMetadata] = Field(default_factory=dict) # entity -> {metrics, metadata} -class DailySpendData(BaseModel): +class DailySpendData(LiteLLMBaseModel): date: date metrics: SpendMetrics breakdown: BreakdownMetrics = Field(default_factory=BreakdownMetrics) -class DailySpendMetadata(BaseModel): +class DailySpendMetadata(LiteLLMBaseModel): total_spend: float = Field(default=0.0) total_flat_cost: float = Field(default=0.0) total_prompt_tokens: int = Field(default=0) @@ -119,18 +121,18 @@ class DailySpendMetadata(BaseModel): ) -class SpendAnalyticsPaginatedResponse(BaseModel): +class SpendAnalyticsPaginatedResponse(LiteLLMBaseModel): results: list[DailySpendData] metadata: DailySpendMetadata = Field(default_factory=DailySpendMetadata) -class KeyActivityRow(BaseModel): +class KeyActivityRow(LiteLLMBaseModel): api_key: str metrics: SpendMetrics metadata: KeyMetadata -class KeySpendMetrics(BaseModel): +class KeySpendMetrics(LiteLLMBaseModel): spend: float = 0.0 prompt_tokens: int = 0 completion_tokens: int = 0 @@ -142,34 +144,34 @@ class KeySpendMetrics(BaseModel): cache_creation_input_tokens: int = 0 -class KeySpendActivityRow(BaseModel): +class KeySpendActivityRow(LiteLLMBaseModel): api_key: str metrics: KeySpendMetrics metadata: KeyMetadata -class DailyActivityKeySearchResponse(BaseModel): +class DailyActivityKeySearchResponse(LiteLLMBaseModel): api_keys: list[KeyActivityRow] -class DailyActivityKeyPageResponse(BaseModel): +class DailyActivityKeyPageResponse(LiteLLMBaseModel): api_keys: list[KeySpendActivityRow] total_api_keys: int offset: int limit: int -class ModelTopKeysResponse(BaseModel): +class ModelTopKeysResponse(LiteLLMBaseModel): model: str by_model_group: bool api_keys: list[KeySpendActivityRow] -class CacheLeakageKeysResponse(BaseModel): +class CacheLeakageKeysResponse(LiteLLMBaseModel): api_keys: list[KeySpendActivityRow] -class LiteLLM_DailyUserSpend(BaseModel): +class LiteLLM_DailyUserSpend(LiteLLMBaseModel): id: str user_id: str date: str diff --git a/litellm/types/proxy/management_endpoints/config_overrides.py b/litellm/types/proxy/management_endpoints/config_overrides.py index 2e0fce08545..c82e616cf9a 100644 --- a/litellm/types/proxy/management_endpoints/config_overrides.py +++ b/litellm/types/proxy/management_endpoints/config_overrides.py @@ -1,9 +1,11 @@ from typing import Any -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel -class HashicorpVaultConfig(BaseModel): +class HashicorpVaultConfig(LiteLLMBaseModel): """Configuration for Hashicorp Vault secret manager integration.""" vault_addr: str | None = Field( @@ -60,7 +62,7 @@ class HashicorpVaultConfig(BaseModel): ) -class CyberArkConfig(BaseModel): +class CyberArkConfig(LiteLLMBaseModel): """Configuration for CyberArk Conjur secret manager integration.""" cyberark_api_base: str | None = Field( @@ -97,7 +99,7 @@ class CyberArkConfig(BaseModel): ) -class ConfigOverrideSettingsResponse(BaseModel): +class ConfigOverrideSettingsResponse(LiteLLMBaseModel): """Response model for config override settings GET endpoints.""" config_type: str = Field(description="The type of config override") diff --git a/litellm/types/proxy/management_endpoints/customer_endpoints.py b/litellm/types/proxy/management_endpoints/customer_endpoints.py index 73fbf711556..c1c4c496ede 100644 --- a/litellm/types/proxy/management_endpoints/customer_endpoints.py +++ b/litellm/types/proxy/management_endpoints/customer_endpoints.py @@ -1,7 +1,8 @@ -from pydantic import BaseModel, Field +from pydantic import Field from litellm.models.budget import LiteLLM_BudgetTableFull from litellm.models.end_user import LiteLLM_EndUserTable +from litellm.types.llms.base import LiteLLMBaseModel class CustomerResponse(LiteLLM_EndUserTable): @@ -15,14 +16,14 @@ class CustomerResponse(LiteLLM_EndUserTable): litellm_budget_table: LiteLLM_BudgetTableFull | None = None # pyright: ignore -class BlockUsersResponse(BaseModel): +class BlockUsersResponse(LiteLLMBaseModel): blocked_users: list[LiteLLM_EndUserTable] -class UnblockUsersResponse(BaseModel): +class UnblockUsersResponse(LiteLLMBaseModel): blocked_users: list[str] = Field(description="User IDs that remain blocked after this unblock call") -class DeleteCustomersResponse(BaseModel): +class DeleteCustomersResponse(LiteLLMBaseModel): deleted_customers: int message: str diff --git a/litellm/types/proxy/management_endpoints/internal_user_endpoints.py b/litellm/types/proxy/management_endpoints/internal_user_endpoints.py index 43e3899d523..1fd3e7dca53 100644 --- a/litellm/types/proxy/management_endpoints/internal_user_endpoints.py +++ b/litellm/types/proxy/management_endpoints/internal_user_endpoints.py @@ -1,7 +1,7 @@ from collections.abc import Mapping, Sequence from typing import Any, Final, Literal -from pydantic import BaseModel, ConfigDict, Field, field_validator +from pydantic import ConfigDict, Field, field_validator from typing_extensions import ReadOnly, TypedDict from litellm.proxy._types import ( @@ -10,6 +10,7 @@ from litellm.proxy._types import ( UpdateUserRequest, UpdateUserRequestNoUserIDorEmail, ) +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.management_endpoints.management_v1 import ResourceResponse MAX_BULK_DELETE_USERS: Final = 500 @@ -28,7 +29,7 @@ class UserSearchWhere(TypedDict): OR: ReadOnly[tuple[Mapping[Literal["user_id", "user_email"], InsensitiveContains], ...]] -class UserListResponse(BaseModel): +class UserListResponse(LiteLLMBaseModel): """ Response model for the user list endpoint """ @@ -40,7 +41,7 @@ class UserListResponse(BaseModel): total_pages: int -class BulkUpdateUserRequest(BaseModel): +class BulkUpdateUserRequest(LiteLLMBaseModel): """Request for bulk user updates""" users: list[UpdateUserRequest] | None = None # List of specific user update requests @@ -72,7 +73,7 @@ class BulkUpdateUserRequest(BaseModel): return v -class UserUpdateResult(BaseModel): +class UserUpdateResult(LiteLLMBaseModel): """Result of a single user update operation""" user_id: str | None = None @@ -82,7 +83,7 @@ class UserUpdateResult(BaseModel): updated_user: dict[str, Any] | None = None -class BulkUpdateUserResponse(BaseModel): +class BulkUpdateUserResponse(LiteLLMBaseModel): """Response for bulk user update operations""" results: list[UserUpdateResult] @@ -91,7 +92,7 @@ class BulkUpdateUserResponse(BaseModel): failed_updates: int -class BulkDeleteUserRequest(BaseModel): +class BulkDeleteUserRequest(LiteLLMBaseModel): """Body of `POST /management/v1/users/bulk_delete`.""" model_config = ConfigDict(extra="forbid") @@ -99,7 +100,7 @@ class BulkDeleteUserRequest(BaseModel): user_ids: tuple[str, ...] = Field(min_length=1, max_length=MAX_BULK_DELETE_USERS) -class UserDeleteResult(BaseModel): +class UserDeleteResult(LiteLLMBaseModel): """Outcome for one requested user, in request order. `teams_removed` lists the teams the user left.""" user_id: str @@ -129,13 +130,13 @@ class BulkNewUserItem(NewUserRequest): return value -class BulkNewUserRequest(BaseModel): +class BulkNewUserRequest(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid") users: Sequence[BulkNewUserItem] = Field(min_length=1, max_length=MAX_BULK_NEW_USERS) -class UserCreateResult(BaseModel): +class UserCreateResult(LiteLLMBaseModel): """Outcome for one row of `POST /management/v1/users/bulk`. `teams` lists the teams the user was actually added to.""" @@ -147,13 +148,13 @@ class UserCreateResult(BaseModel): error: str | None = None -class BulkNewUserMeta(BaseModel): +class BulkNewUserMeta(LiteLLMBaseModel): total_requested: int created: int failed: int -class BulkNewUserResponse(BaseModel): +class BulkNewUserResponse(LiteLLMBaseModel): """`data` holds one result per input row, in input order.""" data: tuple[UserCreateResult, ...] diff --git a/litellm/types/proxy/management_endpoints/key_management_endpoints.py b/litellm/types/proxy/management_endpoints/key_management_endpoints.py index 001bc3c0d51..05b63100ea4 100644 --- a/litellm/types/proxy/management_endpoints/key_management_endpoints.py +++ b/litellm/types/proxy/management_endpoints/key_management_endpoints.py @@ -1,7 +1,7 @@ from datetime import datetime from typing import Any, Final, Literal, TypeAlias -from pydantic import BaseModel, ConfigDict, model_validator +from pydantic import ConfigDict, model_validator from typing_extensions import ReadOnly, TypedDict from litellm.models.verification_token import LiteLLM_VerificationToken @@ -11,7 +11,7 @@ from litellm.proxy._types import ( RegenerateKeyRequest, UpdateKeyRequest, ) -from litellm.types.llms.base import LiteLLMPydanticObjectBase +from litellm.types.llms.base import LiteLLMBaseModel, LiteLLMPydanticObjectBase from litellm.types.proxy.management_endpoints.internal_user_endpoints import InsensitiveContains @@ -29,7 +29,7 @@ class KeySearchWhere(TypedDict): OR: ReadOnly[tuple[KeyTokenWhere, KeyAliasContainsWhere]] -class BulkUpdateKeyRequestItem(BaseModel): +class BulkUpdateKeyRequestItem(LiteLLMBaseModel): """One /key/bulk_update item; only the fields it carries are written.""" key: str # Key identifier (token) @@ -40,20 +40,20 @@ class BulkUpdateKeyRequestItem(BaseModel): object_permission: LiteLLM_ObjectPermissionBase | None = None -class BulkUpdateKeyRequest(BaseModel): +class BulkUpdateKeyRequest(LiteLLMBaseModel): """Request for bulk key updates""" keys: list[BulkUpdateKeyRequestItem] -class SuccessfulKeyUpdate(BaseModel): +class SuccessfulKeyUpdate(LiteLLMBaseModel): """Successfully updated key with its updated information""" key: str key_info: dict[str, Any] -class FailedKeyUpdate(BaseModel): +class FailedKeyUpdate(LiteLLMBaseModel): """Failed key update with reason""" key: str @@ -61,7 +61,7 @@ class FailedKeyUpdate(BaseModel): failed_reason: str -class BulkUpdateKeyResponse(BaseModel): +class BulkUpdateKeyResponse(LiteLLMBaseModel): """Response for bulk key update operations""" total_requested: int @@ -69,7 +69,7 @@ class BulkUpdateKeyResponse(BaseModel): failed_updates: list[FailedKeyUpdate] -class KeyUpdateFields(BaseModel): +class KeyUpdateFields(LiteLLMBaseModel): """Allowlist of bulk-broadcastable fields for /team/key/bulk_update; `extra="forbid"` blocks RBAC/ownership/scope mutations even by team admins.""" model_config = ConfigDict(extra="forbid", protected_namespaces=()) @@ -116,7 +116,7 @@ class KeyUpdateFields(BaseModel): return self -class BulkUpdateTeamKeysRequest(BaseModel): +class BulkUpdateTeamKeysRequest(LiteLLMBaseModel): """Apply one update payload to many keys inside a team; provide either `key_ids` or `all_keys_in_team=True`.""" team_id: str diff --git a/litellm/types/proxy/management_endpoints/management_v1.py b/litellm/types/proxy/management_endpoints/management_v1.py index c23d0ecfb54..6fd12e00381 100644 --- a/litellm/types/proxy/management_endpoints/management_v1.py +++ b/litellm/types/proxy/management_endpoints/management_v1.py @@ -3,12 +3,14 @@ from collections.abc import Sequence from typing import Generic, TypeVar -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field + +from litellm.types.llms.base import LiteLLMBaseModel TOut = TypeVar("TOut") -class ProblemDetail(BaseModel): +class ProblemDetail(LiteLLMBaseModel): """RFC 9457 problem details, served as `application/problem+json`.""" type: str @@ -18,7 +20,7 @@ class ProblemDetail(BaseModel): allowed: list[str] | None = None -class PageLinks(BaseModel): +class PageLinks(LiteLLMBaseModel): """Hypermedia for a paginated list. No `first`/`last`: without a total count the last page is unknown.""" model_config = ConfigDict(populate_by_name=True) @@ -28,7 +30,7 @@ class PageLinks(BaseModel): next: str | None = None -class PageMeta(BaseModel): +class PageMeta(LiteLLMBaseModel): """`has_more` rather than `total_count`, which would need a COUNT(*) over the whole match set per keystroke.""" page: int @@ -36,7 +38,7 @@ class PageMeta(BaseModel): has_more: bool -class FacetListResponse(BaseModel): +class FacetListResponse(LiteLLMBaseModel): """The distinct values one column takes over a filtered query. `data` holds bare values, not entity rows.""" data: Sequence[str] @@ -44,7 +46,7 @@ class FacetListResponse(BaseModel): links: PageLinks -class ListMeta(BaseModel): +class ListMeta(LiteLLMBaseModel): """Page-mode counterpart to `PageMeta`: an entity list pays for the COUNT(*) so the table can show a page count.""" total_count: int @@ -53,7 +55,7 @@ class ListMeta(BaseModel): total_pages: int -class ListLinks(BaseModel): +class ListLinks(LiteLLMBaseModel): """Page-mode counterpart to `PageLinks`. `first`/`last` are knowable here because the total count is.""" model_config = ConfigDict(populate_by_name=True) @@ -65,13 +67,13 @@ class ListLinks(BaseModel): last: str -class ResourceResponse(BaseModel, Generic[TOut]): +class ResourceResponse(LiteLLMBaseModel, Generic[TOut]): """Envelope for a single resource or an action's result: `{data: ...}`, no `meta` or `links`.""" data: TOut -class ListResponse(BaseModel, Generic[TOut]): +class ListResponse(LiteLLMBaseModel, Generic[TOut]): """Rows stay flat: JSON:API's `{type, id, attributes}` wrapper is a deliberate deviation, so every dashboard column accessor would otherwise have to go through `.attributes`.""" diff --git a/litellm/types/proxy/management_endpoints/model_management_endpoints.py b/litellm/types/proxy/management_endpoints/model_management_endpoints.py index 8315ac0d4d2..3cc85a9427e 100644 --- a/litellm/types/proxy/management_endpoints/model_management_endpoints.py +++ b/litellm/types/proxy/management_endpoints/model_management_endpoints.py @@ -1,7 +1,9 @@ from datetime import datetime from typing import Any -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field + +from litellm.types.llms.base import LiteLLMBaseModel from ...router import ModelGroupInfo @@ -13,14 +15,14 @@ class ModelGroupInfoProxy(ModelGroupInfo): health_checked_at: str | None = Field(default=None) -class UpdateUsefulLinksRequest(BaseModel): +class UpdateUsefulLinksRequest(LiteLLMBaseModel): # Supports both old format (Dict[str, str]) and new format (Dict[str, Dict[str, Any]]) # New format: { "displayName": { "url": "...", "index": 0 } } # Old format: { "displayName": "url" } (for backward compatibility) useful_links: dict[str, str | dict[str, Any]] -class AutoRouterClassifierDefaultPromptResponse(BaseModel): +class AutoRouterClassifierDefaultPromptResponse(LiteLLMBaseModel): """The built-in system prompt an auto-router's LLM classifier uses when none is configured. Served so the dashboard's prompt editor prefills the rubric the proxy actually sends, rather than @@ -30,31 +32,31 @@ class AutoRouterClassifierDefaultPromptResponse(BaseModel): system_prompt: str -class NewModelGroupRequest(BaseModel): +class NewModelGroupRequest(LiteLLMBaseModel): access_group: str # The access group name (e.g., "production-models") model_names: list[str] | None = None # Existing model groups to include - tags ALL deployments for each name model_ids: list[str] | None = None # Specific deployment IDs to tag (more precise than model_names) -class NewModelGroupResponse(BaseModel): +class NewModelGroupResponse(LiteLLMBaseModel): access_group: str model_names: list[str] | None = None model_ids: list[str] | None = None models_updated: int # Number of models updated -class UpdateModelGroupRequest(BaseModel): +class UpdateModelGroupRequest(LiteLLMBaseModel): model_names: list[str] | None = None # Updated list of model groups to include - tags ALL deployments for each name model_ids: list[str] | None = None # Specific deployment IDs to tag (more precise than model_names) -class DeleteModelGroupResponse(BaseModel): +class DeleteModelGroupResponse(LiteLLMBaseModel): access_group: str models_updated: int # Number of deployments where the access group was removed message: str -class AccessGroupBudget(BaseModel): +class AccessGroupBudget(LiteLLMBaseModel): budget_id: str max_budget: float | None = None soft_budget: float | None = None @@ -62,7 +64,7 @@ class AccessGroupBudget(BaseModel): budget_reset_at: datetime | None = None -class AccessGroupBudgetRequest(BaseModel): +class AccessGroupBudgetRequest(LiteLLMBaseModel): budget_id: str | None = None # Link an existing budget instead of creating one max_budget: float | None = Field(default=None, ge=0) soft_budget: float | None = Field(default=None, ge=0) @@ -72,19 +74,19 @@ class AccessGroupBudgetRequest(BaseModel): model_config = ConfigDict(extra="forbid") -class AccessGroupBudgetResponse(BaseModel): +class AccessGroupBudgetResponse(LiteLLMBaseModel): access_group: str spend: float # Shared spend accrued by every key that can reach this access group budget: AccessGroupBudget | None = None -class DeleteAccessGroupBudgetResponse(BaseModel): +class DeleteAccessGroupBudgetResponse(LiteLLMBaseModel): access_group: str budget_deleted: bool # False when the access group had no budget to begin with message: str -class AccessGroupInfo(BaseModel): +class AccessGroupInfo(LiteLLMBaseModel): access_group: str model_names: list[str] # List of model names in this access group deployment_count: int # Total number of deployments with this access group @@ -92,5 +94,5 @@ class AccessGroupInfo(BaseModel): budget: AccessGroupBudget | None = None -class ListAccessGroupsResponse(BaseModel): +class ListAccessGroupsResponse(LiteLLMBaseModel): access_groups: list[AccessGroupInfo] diff --git a/litellm/types/proxy/management_endpoints/scim_v2.py b/litellm/types/proxy/management_endpoints/scim_v2.py index 6f2c48ab283..9b519f9af4f 100644 --- a/litellm/types/proxy/management_endpoints/scim_v2.py +++ b/litellm/types/proxy/management_endpoints/scim_v2.py @@ -2,7 +2,6 @@ from typing import Any, Final, Literal, Optional, Union from fastapi import HTTPException from pydantic import ( - BaseModel, ConfigDict, EmailStr, Field, @@ -13,6 +12,8 @@ from pydantic import ( ) from pydantic_core.core_schema import SerializerFunctionWrapHandler +from litellm.types.llms.base import LiteLLMBaseModel + SCIM_ENTERPRISE_USER_SCHEMA: Final = "urn:ietf:params:scim:schemas:extension:enterprise:2.0:User" SCIM_ENTERPRISE_METADATA_KEY: Final = "scim_enterprise" SCIM_ENTITLEMENTS_METADATA_KEY: Final = "scim_entitlements" @@ -22,7 +23,7 @@ SCIM_MANAGED_TEAM_METADATA_KEY: Final = "scim_managed" SCIM_TEAM_DATA_METADATA_KEY: Final = "scim_data" -class LiteLLM_UserScimMetadata(BaseModel): +class LiteLLM_UserScimMetadata(LiteLLMBaseModel): """ Scim metadata stored in LiteLLM_UserTable.metadata """ @@ -32,14 +33,14 @@ class LiteLLM_UserScimMetadata(BaseModel): # SCIM Resource Models -class SCIMResource(BaseModel): +class SCIMResource(LiteLLMBaseModel): schemas: list[str] id: str | None = None externalId: str | None = None meta: dict[str, object] | None = None -class SCIMUserName(BaseModel): +class SCIMUserName(LiteLLMBaseModel): familyName: str | None = None givenName: str | None = None formatted: str | None = None @@ -48,19 +49,19 @@ class SCIMUserName(BaseModel): honorificSuffix: str | None = None -class SCIMUserEmail(BaseModel): +class SCIMUserEmail(LiteLLMBaseModel): value: EmailStr type: str | None = None primary: bool | None = None -class SCIMUserGroup(BaseModel): +class SCIMUserGroup(LiteLLMBaseModel): value: str # Group ID display: str | None = None # Group display name type: str | None = "direct" # direct or indirect -class SCIMMultiValuedAttribute(BaseModel): +class SCIMMultiValuedAttribute(LiteLLMBaseModel): model_config = ConfigDict(extra="allow") value: str | None = None @@ -84,7 +85,7 @@ SCIM_MULTI_VALUED_ATTRIBUTE_METADATA_KEYS: Final = { } -class SCIMUserManager(BaseModel): +class SCIMUserManager(LiteLLMBaseModel): model_config = ConfigDict(populate_by_name=True) value: str | None = None @@ -92,7 +93,7 @@ class SCIMUserManager(BaseModel): ref: str | None = Field(default=None, alias="$ref") -class SCIMEnterpriseUser(BaseModel): +class SCIMEnterpriseUser(LiteLLMBaseModel): model_config = ConfigDict(populate_by_name=True) employeeNumber: str | None = None @@ -133,7 +134,7 @@ class SCIMUser(SCIMResource): return dumped -class SCIMMember(BaseModel): +class SCIMMember(LiteLLMBaseModel): value: str # User ID display: str | None = None # Username or email type: str | None = None @@ -152,15 +153,15 @@ class SCIMGroup(SCIMResource): members: list[SCIMMember] | None = None -class SCIMPlaceholderMergeResult(BaseModel): +class SCIMPlaceholderMergeResult(LiteLLMBaseModel): placeholder_user_id: str merged_into_user_id: str team_ids: tuple[str, ...] # SCIM List Response Models -class SCIMListResponse(BaseModel): - schemas: list[str] = ["urn:ietf:params:scim:api:messages:2.0:ListResponse"] +class SCIMListResponse(LiteLLMBaseModel): + schemas: list[str] = Field(default=["urn:ietf:params:scim:api:messages:2.0:ListResponse"]) totalResults: int startIndex: int | None = 1 itemsPerPage: int | None = 10 @@ -168,7 +169,7 @@ class SCIMListResponse(BaseModel): # SCIM PATCH Operation Models -class SCIMPatchOperation(BaseModel): +class SCIMPatchOperation(LiteLLMBaseModel): op: str path: str | None = None value: object | None = None @@ -184,21 +185,21 @@ class SCIMPatchOperation(BaseModel): return v -class SCIMPatchOp(BaseModel): - schemas: list[str] = ["urn:ietf:params:scim:api:messages:2.0:PatchOp"] +class SCIMPatchOp(LiteLLMBaseModel): + schemas: list[str] = Field(default=["urn:ietf:params:scim:api:messages:2.0:PatchOp"]) Operations: list[SCIMPatchOperation] # SCIM Service Provider Configuration Models -class SCIMFeature(BaseModel): +class SCIMFeature(LiteLLMBaseModel): supported: bool maxOperations: int | None = None maxPayloadSize: int | None = None maxResults: int | None = None -class SCIMServiceProviderConfig(BaseModel): - schemas: list[str] = ["urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig"] +class SCIMServiceProviderConfig(LiteLLMBaseModel): + schemas: list[str] = Field(default=["urn:ietf:params:scim:schemas:core:2.0:ServiceProviderConfig"]) patch: SCIMFeature = SCIMFeature(supported=True) bulk: SCIMFeature = SCIMFeature(supported=False) filter: SCIMFeature = SCIMFeature(supported=False) @@ -210,7 +211,7 @@ class SCIMServiceProviderConfig(BaseModel): # SCIM ResourceType Models (RFC 7643 Section 6) -class SCIMSchemaExtension(BaseModel): +class SCIMSchemaExtension(LiteLLMBaseModel): model_config = ConfigDict(populate_by_name=True) schema_: str # aliased to "schema" in serialization @@ -222,10 +223,10 @@ class SCIMSchemaExtension(BaseModel): return d -class SCIMResourceType(BaseModel): +class SCIMResourceType(LiteLLMBaseModel): model_config = ConfigDict(populate_by_name=True) - schemas: list[str] = ["urn:ietf:params:scim:schemas:core:2.0:ResourceType"] + schemas: list[str] = Field(default=["urn:ietf:params:scim:schemas:core:2.0:ResourceType"]) id: str name: str description: str | None = None @@ -244,7 +245,7 @@ class SCIMResourceType(BaseModel): # SCIM Schema Models (RFC 7643 Section 7) -class SCIMSchemaAttribute(BaseModel): +class SCIMSchemaAttribute(LiteLLMBaseModel): name: str type: str multiValued: bool = False @@ -262,10 +263,10 @@ class SCIMSchemaAttribute(BaseModel): return d -class SCIMSchema(BaseModel): - schemas: list[str] = ["urn:ietf:params:scim:schemas:core:2.0:Schema"] +class SCIMSchema(LiteLLMBaseModel): + schemas: list[str] = Field(default=["urn:ietf:params:scim:schemas:core:2.0:Schema"]) id: str name: str description: str | None = None - attributes: list[SCIMSchemaAttribute] = [] + attributes: list[SCIMSchemaAttribute] = Field(default=[]) meta: dict[str, object] | None = None diff --git a/litellm/types/proxy/management_endpoints/team_endpoints.py b/litellm/types/proxy/management_endpoints/team_endpoints.py index 4524c47ec38..6731b826ebd 100644 --- a/litellm/types/proxy/management_endpoints/team_endpoints.py +++ b/litellm/types/proxy/management_endpoints/team_endpoints.py @@ -1,6 +1,6 @@ from typing import Any, Final, Literal -from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator +from pydantic import ConfigDict, Field, field_validator, model_validator from litellm.proxy._types import ( KeyManagementRoutes, @@ -11,6 +11,7 @@ from litellm.proxy._types import ( MemberDeleteRequest, ) from litellm.proxy.common_utils.timezone_utils import budget_duration_error +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.management_endpoints.management_v1 import ResourceResponse TeamIdSearchMatch = Literal["exact", "prefix"] @@ -20,13 +21,13 @@ MAX_BULK_TEAM_MEMBER_DELETES: Final = 500 MAX_BULK_TEAM_MEMBER_BUDGET_UPDATES: Final = 500 -class GetTeamMemberPermissionsRequest(BaseModel): +class GetTeamMemberPermissionsRequest(LiteLLMBaseModel): """Request to get the team member permissions for a team""" team_id: str -class GetTeamMemberPermissionsResponse(BaseModel): +class GetTeamMemberPermissionsResponse(LiteLLMBaseModel): """Response to get the team member permissions for a team""" team_id: str @@ -34,7 +35,7 @@ class GetTeamMemberPermissionsResponse(BaseModel): The team id that the permissions are for """ - team_member_permissions: list[str] | None = [] + team_member_permissions: list[str] | None = Field(default=[]) """ The team member permissions currently set for the team """ @@ -45,14 +46,14 @@ class GetTeamMemberPermissionsResponse(BaseModel): """ -class UpdateTeamMemberPermissionsRequest(BaseModel): +class UpdateTeamMemberPermissionsRequest(LiteLLMBaseModel): """Request to update the team member permissions for a team""" team_id: str team_member_permissions: list[str] -class BulkUpdateTeamMemberPermissionsRequest(BaseModel): +class BulkUpdateTeamMemberPermissionsRequest(LiteLLMBaseModel): """Request to bulk-update team member permissions across teams.""" permissions: list[KeyManagementRoutes] @@ -65,7 +66,7 @@ class BulkUpdateTeamMemberPermissionsRequest(BaseModel): """When True, update all teams. Mutually exclusive with team_ids.""" -class BulkUpdateTeamMemberPermissionsResponse(BaseModel): +class BulkUpdateTeamMemberPermissionsResponse(LiteLLMBaseModel): """Response for bulk team member permissions update.""" message: str @@ -84,7 +85,7 @@ class TeamListItem(LiteLLM_TeamTable): access_group_agent_ids: list[str] | None = None -class TeamListResponse(BaseModel): +class TeamListResponse(LiteLLMBaseModel): """Response to get the list of teams""" teams: list[TeamListItem | LiteLLM_TeamTable | LiteLLM_DeletedTeamTable] @@ -94,7 +95,7 @@ class TeamListResponse(BaseModel): total_pages: int -class BulkTeamMemberAddRequest(BaseModel): +class BulkTeamMemberAddRequest(LiteLLMBaseModel): """Request for bulk team member addition""" team_id: str @@ -103,7 +104,7 @@ class BulkTeamMemberAddRequest(BaseModel): max_budget_in_team: float | None = None -class TeamMemberAddResult(BaseModel): +class TeamMemberAddResult(LiteLLMBaseModel): """Result of a single team member add operation""" user_id: str | None = None @@ -114,7 +115,7 @@ class TeamMemberAddResult(BaseModel): updated_team_membership: dict[str, Any] | None = None -class BulkTeamMemberAddResponse(BaseModel): +class BulkTeamMemberAddResponse(LiteLLMBaseModel): """Response for bulk team member add operations""" team_id: str @@ -137,7 +138,7 @@ class TeamMemberRef(MemberDeleteRequest): return self -class BulkTeamMemberDeleteRequest(BaseModel): +class BulkTeamMemberDeleteRequest(LiteLLMBaseModel): """Body of `POST /management/v1/teams/{team_id}/members/bulk_delete`.""" model_config = ConfigDict(extra="forbid") @@ -145,7 +146,7 @@ class BulkTeamMemberDeleteRequest(BaseModel): members: tuple[TeamMemberRef, ...] = Field(min_length=1, max_length=MAX_BULK_TEAM_MEMBER_DELETES) -class TeamMemberDeleteResult(BaseModel): +class TeamMemberDeleteResult(LiteLLMBaseModel): """Outcome for one requested member, in request order.""" user_id: str | None = None @@ -178,7 +179,7 @@ class TeamMemberBudgetPatch(TeamMemberRef): return value -class BulkTeamMemberBudgetUpdateRequest(BaseModel): +class BulkTeamMemberBudgetUpdateRequest(LiteLLMBaseModel): """Body of `POST /management/v1/teams/{team_id}/members/bulk_update`.""" model_config = ConfigDict(extra="forbid") @@ -186,7 +187,7 @@ class BulkTeamMemberBudgetUpdateRequest(BaseModel): members: tuple[TeamMemberBudgetPatch, ...] = Field(min_length=1, max_length=MAX_BULK_TEAM_MEMBER_BUDGET_UPDATES) -class TeamMemberBudgetUpdateResult(BaseModel): +class TeamMemberBudgetUpdateResult(LiteLLMBaseModel): """Outcome for one requested member, in request order, carrying the limits in force after the write rather than the ones that were asked for.""" @@ -215,7 +216,7 @@ class TeamMemberInfoResponse(LiteLLM_TeamMembership): team_alias: str | None = None -class TeamMetadataFieldSchema(BaseModel): +class TeamMetadataFieldSchema(LiteLLMBaseModel): """One declared team metadata field from ``general_settings.team_metadata_schema``. Advisory only: the UI uses it to prepopulate the team metadata form. @@ -228,13 +229,13 @@ class TeamMetadataFieldSchema(BaseModel): label: str | None = None -class TeamMetadataSchemaResponse(BaseModel): +class TeamMetadataSchemaResponse(LiteLLMBaseModel): """Response for GET /team/metadata_schema; ``fields`` is empty when no schema is configured.""" fields: tuple[TeamMetadataFieldSchema, ...] -class TeamUserSpendRow(BaseModel): +class TeamUserSpendRow(LiteLLMBaseModel): team_id: str team_alias: str | None = None user_id: str @@ -249,7 +250,7 @@ class TeamUserSpendRow(BaseModel): failed_requests: int = 0 -class TeamUserSpendResponse(BaseModel): +class TeamUserSpendResponse(LiteLLMBaseModel): start_date: str end_date: str results: tuple[TeamUserSpendRow, ...] diff --git a/litellm/types/proxy/model_access_group_budget.py b/litellm/types/proxy/model_access_group_budget.py index cccbe92b5d6..08ea04f44f3 100644 --- a/litellm/types/proxy/model_access_group_budget.py +++ b/litellm/types/proxy/model_access_group_budget.py @@ -2,10 +2,10 @@ from __future__ import annotations -from pydantic import BaseModel +from litellm.types.llms.base import LiteLLMBaseModel -class ModelAccessGroupBudget(BaseModel): +class ModelAccessGroupBudget(LiteLLMBaseModel): """One model access group's budget, flattened out of its joined ``LiteLLM_ModelAccessGroupBudgetTable`` row. Both readers want only the recorded spend and the ceiling, and this sits on the per-request hot diff --git a/litellm/types/proxy/model_deprecation.py b/litellm/types/proxy/model_deprecation.py index bbad63a278d..0b0cd2d7024 100644 --- a/litellm/types/proxy/model_deprecation.py +++ b/litellm/types/proxy/model_deprecation.py @@ -3,7 +3,9 @@ from __future__ import annotations from datetime import date, datetime from typing import Final, Literal -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel DEFAULT_DEPRECATION_WARN_DAYS: Final = 30 @@ -14,7 +16,7 @@ DEPRECATION_IDLE_POLL_SECONDS: Final = 30 DeprecationStatus = Literal["upcoming", "imminent", "deprecated"] -class ModelDeprecationInfo(BaseModel): +class ModelDeprecationInfo(LiteLLMBaseModel): model_name: str = Field(description="The public name of the model on the proxy (model_group).") litellm_model: str | None = Field( default=None, @@ -32,7 +34,7 @@ class ModelDeprecationInfo(BaseModel): litellm_provider: str | None = Field(default=None, description="The provider this model belongs to.") -class ModelDeprecationResponse(BaseModel): +class ModelDeprecationResponse(LiteLLMBaseModel): deprecated: list[ModelDeprecationInfo] = Field( default_factory=list, description="Models whose deprecation date has already passed.", diff --git a/litellm/types/proxy/policy_engine/pipeline_types.py b/litellm/types/proxy/policy_engine/pipeline_types.py index 063edb0a264..5278754701d 100644 --- a/litellm/types/proxy/policy_engine/pipeline_types.py +++ b/litellm/types/proxy/policy_engine/pipeline_types.py @@ -8,13 +8,15 @@ with configurable actions on pass/fail, rather than independently. from typing import Any, Final, Literal -from pydantic import BaseModel, ConfigDict, Field, field_validator +from pydantic import ConfigDict, Field, field_validator + +from litellm.types.llms.base import LiteLLMBaseModel VALID_PIPELINE_ACTIONS: Final = {"allow", "block", "next", "modify_response"} VALID_PIPELINE_MODES: Final = {"pre_call", "post_call"} -class PipelineStep(BaseModel): +class PipelineStep(LiteLLMBaseModel): """ A single step in a guardrail pipeline. @@ -57,7 +59,7 @@ class PipelineStep(BaseModel): return v -class GuardrailPipeline(BaseModel): +class GuardrailPipeline(LiteLLMBaseModel): """ Defines ordered execution of guardrails with conditional actions. @@ -81,7 +83,7 @@ class GuardrailPipeline(BaseModel): return v -class PipelineStepResult(BaseModel): +class PipelineStepResult(LiteLLMBaseModel): """Result of executing a single pipeline step.""" guardrail_name: str @@ -92,7 +94,7 @@ class PipelineStepResult(BaseModel): duration_seconds: float | None = None -class PipelineExecutionResult(BaseModel): +class PipelineExecutionResult(LiteLLMBaseModel): """Result of executing an entire pipeline.""" model_config = ConfigDict(arbitrary_types_allowed=True) diff --git a/litellm/types/proxy/policy_engine/policy_types.py b/litellm/types/proxy/policy_engine/policy_types.py index 73eeffa3585..5e806556a4f 100644 --- a/litellm/types/proxy/policy_engine/policy_types.py +++ b/litellm/types/proxy/policy_engine/policy_types.py @@ -29,8 +29,9 @@ Key concepts: - `condition`: Optional model condition for when guardrails apply """ -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.proxy.policy_engine.pipeline_types import GuardrailPipeline # ───────────────────────────────────────────────────────────────────────────── @@ -38,7 +39,7 @@ from litellm.types.proxy.policy_engine.pipeline_types import GuardrailPipeline # ───────────────────────────────────────────────────────────────────────────── -class PolicyCondition(BaseModel): +class PolicyCondition(LiteLLMBaseModel): """ Condition for when a policy's guardrails apply. @@ -66,7 +67,7 @@ class PolicyCondition(BaseModel): # ───────────────────────────────────────────────────────────────────────────── -class PolicyScope(BaseModel): +class PolicyScope(LiteLLMBaseModel): """ Defines the scope for matching requests. @@ -130,7 +131,7 @@ class PolicyScope(BaseModel): # ───────────────────────────────────────────────────────────────────────────── -class PolicyGuardrails(BaseModel): +class PolicyGuardrails(LiteLLMBaseModel): """ Defines guardrails to add or remove in a policy. @@ -167,7 +168,7 @@ class PolicyGuardrails(BaseModel): # ───────────────────────────────────────────────────────────────────────────── -class Policy(BaseModel): +class Policy(LiteLLMBaseModel): """ A policy that defines WHAT guardrails to apply. @@ -244,7 +245,7 @@ class Policy(BaseModel): # ───────────────────────────────────────────────────────────────────────────── -class PolicyAttachment(BaseModel): +class PolicyAttachment(LiteLLMBaseModel): """ Attaches a policy to a scope - defines WHERE a policy applies. @@ -317,7 +318,7 @@ class PolicyAttachment(BaseModel): ) -class PolicyConfig(BaseModel): +class PolicyConfig(LiteLLMBaseModel): """ Root configuration for all policies. diff --git a/litellm/types/proxy/policy_engine/resolver_types.py b/litellm/types/proxy/policy_engine/resolver_types.py index ebdedb98b12..248e669e83a 100644 --- a/litellm/types/proxy/policy_engine/resolver_types.py +++ b/litellm/types/proxy/policy_engine/resolver_types.py @@ -8,10 +8,12 @@ the final guardrails list. from datetime import datetime from typing import Any, Literal -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field + +from litellm.types.llms.base import LiteLLMBaseModel -class PolicyMatchContext(BaseModel): +class PolicyMatchContext(LiteLLMBaseModel): """ Context used to match a request against policies. @@ -38,7 +40,7 @@ class PolicyMatchContext(BaseModel): model_config = ConfigDict(extra="forbid") -class ResolvedPolicy(BaseModel): +class ResolvedPolicy(LiteLLMBaseModel): """ Result of resolving a policy with its inheritance chain. @@ -63,7 +65,7 @@ class ResolvedPolicy(BaseModel): # ───────────────────────────────────────────────────────────────────────────── -class PolicyScopeResponse(BaseModel): +class PolicyScopeResponse(LiteLLMBaseModel): """Scope configuration for a policy.""" teams: list[str] = Field(default_factory=list) @@ -72,14 +74,14 @@ class PolicyScopeResponse(BaseModel): tags: list[str] = Field(default_factory=list) -class PolicyGuardrailsResponse(BaseModel): +class PolicyGuardrailsResponse(LiteLLMBaseModel): """Guardrails configuration for a policy.""" add: list[str] = Field(default_factory=list) remove: list[str] = Field(default_factory=list) -class PolicyInfoResponse(BaseModel): +class PolicyInfoResponse(LiteLLMBaseModel): """Response for /policy/info/{policy_name} endpoint.""" policy_name: str @@ -90,7 +92,7 @@ class PolicyInfoResponse(BaseModel): inheritance_chain: list[str] -class PolicySummaryItem(BaseModel): +class PolicySummaryItem(LiteLLMBaseModel): """Summary of a single policy for list endpoint.""" inherit: str | None = None @@ -100,14 +102,14 @@ class PolicySummaryItem(BaseModel): inheritance_chain: list[str] -class PolicyListResponse(BaseModel): +class PolicyListResponse(LiteLLMBaseModel): """Response for /policy/list endpoint.""" policies: dict[str, PolicySummaryItem] total_count: int -class PolicyTestResponse(BaseModel): +class PolicyTestResponse(LiteLLMBaseModel): """Response for /policy/test endpoint.""" context: PolicyMatchContext @@ -121,7 +123,7 @@ class PolicyTestResponse(BaseModel): # ───────────────────────────────────────────────────────────────────────────── -class PolicyConditionRequest(BaseModel): +class PolicyConditionRequest(LiteLLMBaseModel): """Condition for when a policy applies.""" model: str | None = Field( @@ -130,7 +132,7 @@ class PolicyConditionRequest(BaseModel): ) -class PolicyCreateRequest(BaseModel): +class PolicyCreateRequest(LiteLLMBaseModel): """Request body for creating a new policy.""" policy_name: str = Field(description="Unique name for the policy.") @@ -160,7 +162,7 @@ class PolicyCreateRequest(BaseModel): ) -class PolicyUpdateRequest(BaseModel): +class PolicyUpdateRequest(LiteLLMBaseModel): """Request body for updating a policy.""" policy_name: str | None = Field( @@ -193,7 +195,7 @@ class PolicyUpdateRequest(BaseModel): ) -class PolicyDBResponse(BaseModel): +class PolicyDBResponse(LiteLLMBaseModel): """Response for a policy from the database.""" policy_id: str = Field(description="Unique ID of the policy.") @@ -226,7 +228,7 @@ class PolicyDBResponse(BaseModel): ) -class PolicyListDBResponse(BaseModel): +class PolicyListDBResponse(LiteLLMBaseModel): """Response for listing policies from the database.""" policies: list[PolicyDBResponse] = Field(default_factory=list, description="List of policies.") @@ -238,7 +240,7 @@ class PolicyListDBResponse(BaseModel): # ───────────────────────────────────────────────────────────────────────────── -class PolicyVersionCreateRequest(BaseModel): +class PolicyVersionCreateRequest(LiteLLMBaseModel): """Request body for creating a new policy version (draft).""" source_policy_id: str | None = Field( @@ -247,7 +249,7 @@ class PolicyVersionCreateRequest(BaseModel): ) -class PolicyVersionStatusUpdateRequest(BaseModel): +class PolicyVersionStatusUpdateRequest(LiteLLMBaseModel): """Request body for updating a policy version's status.""" version_status: str = Field( @@ -255,7 +257,7 @@ class PolicyVersionStatusUpdateRequest(BaseModel): ) -class PolicyVersionListResponse(BaseModel): +class PolicyVersionListResponse(LiteLLMBaseModel): """Response for listing all versions of a policy.""" policy_name: str = Field(description="Name of the policy.") @@ -265,7 +267,7 @@ class PolicyVersionListResponse(BaseModel): total_count: int = Field(default=0, description="Total number of versions.") -class PolicyVersionCompareResponse(BaseModel): +class PolicyVersionCompareResponse(LiteLLMBaseModel): """Response for comparing two policy versions.""" version_a: PolicyDBResponse = Field(description="First version.") @@ -281,7 +283,7 @@ class PolicyVersionCompareResponse(BaseModel): # ───────────────────────────────────────────────────────────────────────────── -class PolicyAttachmentCreateRequest(BaseModel): +class PolicyAttachmentCreateRequest(LiteLLMBaseModel): """Request body for creating a policy attachment.""" policy_name: str = Field(description="Name of the policy to attach.") @@ -317,7 +319,7 @@ class PolicyAttachmentCreateRequest(BaseModel): ) -class PolicyAttachmentDBResponse(BaseModel): +class PolicyAttachmentDBResponse(LiteLLMBaseModel): """Response for a policy attachment from the database.""" attachment_id: str = Field(description="Unique ID of the attachment.") @@ -345,7 +347,7 @@ class PolicyAttachmentDBResponse(BaseModel): ) -class PolicyAttachmentListResponse(BaseModel): +class PolicyAttachmentListResponse(LiteLLMBaseModel): """Response for listing policy attachments.""" attachments: list[PolicyAttachmentDBResponse] = Field( @@ -359,7 +361,7 @@ class PolicyAttachmentListResponse(BaseModel): # ───────────────────────────────────────────────────────────────────────────── -class PipelineTestRequest(BaseModel): +class PipelineTestRequest(LiteLLMBaseModel): """Request body for testing a guardrail pipeline with sample messages.""" pipeline: dict[str, Any] = Field( @@ -370,7 +372,7 @@ class PipelineTestRequest(BaseModel): ) -class PolicyResolveRequest(BaseModel): +class PolicyResolveRequest(LiteLLMBaseModel): """Request body for resolving effective policies/guardrails for a context.""" team_alias: str | None = Field(default=None, description="Team alias to resolve for.") @@ -379,7 +381,7 @@ class PolicyResolveRequest(BaseModel): tags: list[str] | None = Field(default=None, description="Tags to resolve for.") -class PolicyMatchDetail(BaseModel): +class PolicyMatchDetail(LiteLLMBaseModel): """Details about why a specific policy matched.""" policy_name: str = Field(description="Name of the matched policy.") @@ -392,7 +394,7 @@ class PolicyMatchDetail(BaseModel): ) -class PolicyResolveResponse(BaseModel): +class PolicyResolveResponse(LiteLLMBaseModel): """Response for resolving effective policies/guardrails for a context.""" effective_guardrails: list[str] = Field( @@ -410,7 +412,7 @@ class PolicyResolveResponse(BaseModel): # ───────────────────────────────────────────────────────────────────────────── -class AttachmentImpactResponse(BaseModel): +class AttachmentImpactResponse(LiteLLMBaseModel): """Response for estimating the impact of a policy attachment.""" affected_keys_count: int = Field( diff --git a/litellm/types/proxy/policy_engine/validation_types.py b/litellm/types/proxy/policy_engine/validation_types.py index 1e4925e1d08..d9537c34084 100644 --- a/litellm/types/proxy/policy_engine/validation_types.py +++ b/litellm/types/proxy/policy_engine/validation_types.py @@ -8,7 +8,9 @@ validation results. from enum import Enum from typing import Any -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field + +from litellm.types.llms.base import LiteLLMBaseModel class PolicyValidationErrorType(str, Enum): @@ -24,7 +26,7 @@ class PolicyValidationErrorType(str, Enum): INVALID_SYNTAX = "invalid_syntax" -class PolicyValidationError(BaseModel): +class PolicyValidationError(LiteLLMBaseModel): """ Represents a validation error or warning for a policy. """ @@ -44,7 +46,7 @@ class PolicyValidationError(BaseModel): model_config = ConfigDict(extra="forbid") -class PolicyValidationResponse(BaseModel): +class PolicyValidationResponse(LiteLLMBaseModel): """ Response from policy validation. @@ -66,7 +68,7 @@ class PolicyValidationResponse(BaseModel): model_config = ConfigDict(extra="forbid") -class PolicyValidateRequest(BaseModel): +class PolicyValidateRequest(LiteLLMBaseModel): """ Request body for the /policy/validate endpoint. """ diff --git a/litellm/types/proxy/prompt_endpoints.py b/litellm/types/proxy/prompt_endpoints.py index ba2c5d3c373..930713663a1 100644 --- a/litellm/types/proxy/prompt_endpoints.py +++ b/litellm/types/proxy/prompt_endpoints.py @@ -1,9 +1,9 @@ from typing import Any -from pydantic import BaseModel +from litellm.types.llms.base import LiteLLMBaseModel -class TestPromptRequest(BaseModel): +class TestPromptRequest(LiteLLMBaseModel): dotprompt_content: str prompt_variables: dict[str, Any] | None = None conversation_history: list[dict[str, str]] | None = None diff --git a/litellm/types/proxy/public_endpoints/public_endpoints.py b/litellm/types/proxy/public_endpoints/public_endpoints.py index fa73926305b..c487ce8b6c5 100644 --- a/litellm/types/proxy/public_endpoints/public_endpoints.py +++ b/litellm/types/proxy/public_endpoints/public_endpoints.py @@ -1,10 +1,12 @@ from collections.abc import Mapping, Sequence from typing import Any, Literal -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict + +from litellm.types.llms.base import LiteLLMBaseModel -class PublicModelHubInfo(BaseModel): +class PublicModelHubInfo(LiteLLMBaseModel): docs_title: str custom_docs_description: str | None litellm_version: str @@ -14,7 +16,7 @@ class PublicModelHubInfo(BaseModel): useful_links: dict[str, str | dict[str, Any]] | None -class ProviderCredentialField(BaseModel): +class ProviderCredentialField(LiteLLMBaseModel): key: str label: str placeholder: str | None = None @@ -25,7 +27,7 @@ class ProviderCredentialField(BaseModel): default_value: str | None = None -class ProviderCreateInfo(BaseModel): +class ProviderCreateInfo(LiteLLMBaseModel): provider: str provider_display_name: str litellm_provider: str @@ -33,7 +35,7 @@ class ProviderCreateInfo(BaseModel): default_model_placeholder: str | None = None -class AgentCredentialField(BaseModel): +class AgentCredentialField(LiteLLMBaseModel): key: str label: str placeholder: str | None = None @@ -47,7 +49,7 @@ class AgentCredentialField(BaseModel): validation_message: str | None = None -class AgentCreateInfo(BaseModel): +class AgentCreateInfo(LiteLLMBaseModel): agent_type: str agent_type_display_name: str description: str | None = None @@ -57,23 +59,23 @@ class AgentCreateInfo(BaseModel): model_template: str | None = None -class EndpointProvider(BaseModel): +class EndpointProvider(LiteLLMBaseModel): slug: str display_name: str -class SupportedEndpoint(BaseModel): +class SupportedEndpoint(LiteLLMBaseModel): key: str label: str endpoint: str providers: list[EndpointProvider] -class SupportedEndpointsResponse(BaseModel): +class SupportedEndpointsResponse(LiteLLMBaseModel): endpoints: list[SupportedEndpoint] -class AutoRouterPresetTiers(BaseModel): +class AutoRouterPresetTiers(LiteLLMBaseModel): """Exactly the four built-in tiers the dashboard's preset prefill can apply. extra="forbid" on purpose: a tier name this dashboard cannot apply would grey out or crash the @@ -88,7 +90,7 @@ class AutoRouterPresetTiers(BaseModel): REASONING: Sequence[str] -class AutoRouterPresetConfig(BaseModel): +class AutoRouterPresetConfig(LiteLLMBaseModel): """The complexity_router_config a preset prefills. Only tiers is validated, because every dashboard consumer dereferences it; everything else @@ -101,7 +103,7 @@ class AutoRouterPresetConfig(BaseModel): tiers: AutoRouterPresetTiers -class AutoRouterPresetRecord(BaseModel): +class AutoRouterPresetRecord(LiteLLMBaseModel): """One auto-router preset as served to the dashboard's template picker.""" model_config = ConfigDict(extra="allow") @@ -111,7 +113,7 @@ class AutoRouterPresetRecord(BaseModel): complexity_router_config: AutoRouterPresetConfig -class ComplexityScorerDefaults(BaseModel): +class ComplexityScorerDefaults(LiteLLMBaseModel): """The complexity router's shipped heuristic scorer defaults. The dashboard prefills its Advanced scoring controls from these rather than keeping its own copy, so diff --git a/litellm/types/proxy/spend_capture_rate.py b/litellm/types/proxy/spend_capture_rate.py index ccc9daf8a9f..54fa6daf8d1 100644 --- a/litellm/types/proxy/spend_capture_rate.py +++ b/litellm/types/proxy/spend_capture_rate.py @@ -7,14 +7,15 @@ higher means LiteLLM prices above the bill. ``None`` means the provider billed n from typing import Literal -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field from litellm.constants import SPEND_CAPTURE_RATE_MAX_RANGE_DAYS +from litellm.types.llms.base import LiteLLMBaseModel SpendCaptureProvider = Literal["openai"] -class SpendCaptureRateCheckSettings(BaseModel): +class SpendCaptureRateCheckSettings(LiteLLMBaseModel): """``general_settings.spend_capture_rate_check``: the daily check of captured spend against the provider bill.""" model_config = ConfigDict(frozen=True, extra="forbid") @@ -31,7 +32,7 @@ class SpendCaptureRateCheckSettings(BaseModel): ) -class CaptureRateDay(BaseModel): +class CaptureRateDay(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) date: str @@ -40,7 +41,7 @@ class CaptureRateDay(BaseModel): capture_rate: float | None -class CaptureRateReport(BaseModel): +class CaptureRateReport(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) provider: SpendCaptureProvider diff --git a/litellm/types/proxy/vantage_endpoints.py b/litellm/types/proxy/vantage_endpoints.py index 83bd5c4c61b..1833d8b8386 100644 --- a/litellm/types/proxy/vantage_endpoints.py +++ b/litellm/types/proxy/vantage_endpoints.py @@ -5,10 +5,12 @@ Vantage endpoint types for LiteLLM Proxy from datetime import datetime from typing import Any -from pydantic import BaseModel, Field, field_validator +from pydantic import Field, field_validator + +from litellm.types.llms.base import LiteLLMBaseModel -class VantageInitRequest(BaseModel): +class VantageInitRequest(LiteLLMBaseModel): """Request model for initializing Vantage settings""" api_key: str = Field(..., description="Vantage API key for authentication") @@ -26,14 +28,14 @@ class VantageInitRequest(BaseModel): return v -class VantageInitResponse(BaseModel): +class VantageInitResponse(LiteLLMBaseModel): """Response model for Vantage initialization""" message: str status: str -class VantageExportRequest(BaseModel): +class VantageExportRequest(LiteLLMBaseModel): """Request model for Vantage export operations (actual export, no default limit)""" limit: int | None = Field( @@ -44,13 +46,13 @@ class VantageExportRequest(BaseModel): end_time_utc: datetime | None = Field(None, description="End time for data export in UTC") -class VantageDryRunRequest(BaseModel): +class VantageDryRunRequest(LiteLLMBaseModel): """Request model for Vantage dry-run operations (capped for preview)""" limit: int | None = Field(500, description="Limit on number of records to preview (default: 500)") -class VantageExportResponse(BaseModel): +class VantageExportResponse(LiteLLMBaseModel): """Response model for Vantage export operations""" message: str @@ -61,7 +63,7 @@ class VantageExportResponse(BaseModel): summary: dict[str, Any] | None = Field(None, description="Summary statistics for dry run") -class VantageSettingsView(BaseModel): +class VantageSettingsView(LiteLLMBaseModel): """Response model for viewing Vantage settings with masked API key""" api_key_masked: str | None = Field( @@ -76,7 +78,7 @@ class VantageSettingsView(BaseModel): status: str | None = Field(None, description="Configuration status") -class VantageSettingsUpdate(BaseModel): +class VantageSettingsUpdate(LiteLLMBaseModel): """Request model for updating Vantage settings""" api_key: str | None = Field(None, description="New Vantage API key for authentication") diff --git a/litellm/types/rag.py b/litellm/types/rag.py index 629979afde9..00c070b0996 100644 --- a/litellm/types/rag.py +++ b/litellm/types/rag.py @@ -5,9 +5,10 @@ Type definitions for RAG (Retrieval Augmented Generation) Ingest API. from collections.abc import Mapping from typing import Any, Literal -from pydantic import BaseModel, ConfigDict +from pydantic import ConfigDict from typing_extensions import ReadOnly, TypedDict +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.utils import ModelResponse @@ -225,7 +226,7 @@ class RAGIngestResponse(TypedDict, total=False): error: str | None # Error message if status is "failed" -class RAGIngestRequest(BaseModel): +class RAGIngestRequest(LiteLLMBaseModel): """Request body for RAG ingest API (for validation).""" file_url: str | None = None # URL to fetch file from @@ -254,7 +255,7 @@ class RAGRerankConfig(TypedDict, total=False): return_documents: bool | None -class RAGQueryRequest(BaseModel): +class RAGQueryRequest(LiteLLMBaseModel): """Request body for RAG query API.""" model: str diff --git a/litellm/types/realtime.py b/litellm/types/realtime.py index 855cccc8ddd..6da73982291 100644 --- a/litellm/types/realtime.py +++ b/litellm/types/realtime.py @@ -1,8 +1,10 @@ from typing import Any, Literal -from pydantic import BaseModel +from pydantic import ConfigDict from typing_extensions import ReadOnly, TypedDict +from litellm.types.llms.base import LiteLLMBaseModel + from .llms.openai import ( OpenAIRealtimeEvents, OpenAIRealtimeOutputItemDone, @@ -57,14 +59,14 @@ class RealtimeQueryParams(TypedDict, total=False): # --------------------------------------------------------------------------- -class RealtimeExpiresAfter(BaseModel): +class RealtimeExpiresAfter(LiteLLMBaseModel): """Expiration config for a client secret.""" anchor: str | None = "created_at" seconds: int | None = None -class RealtimeSessionConfig(BaseModel): +class RealtimeSessionConfig(LiteLLMBaseModel): """ Session configuration nested inside the client_secrets request body. @@ -73,7 +75,7 @@ class RealtimeSessionConfig(BaseModel): Extra/unknown fields are passed through unchanged. """ - model_config = {"extra": "allow"} + model_config = ConfigDict(extra="allow") type: str | None = None model: str | None = None @@ -89,7 +91,7 @@ class RealtimeSessionConfig(BaseModel): prompt: dict[str, object] | None = None -class RealtimeClientSecretRequest(BaseModel): +class RealtimeClientSecretRequest(LiteLLMBaseModel): """ Request body for POST /v1/realtime/client_secrets. @@ -103,7 +105,7 @@ class RealtimeClientSecretRequest(BaseModel): model: str | None = None -class RealtimeClientSecretResponse(BaseModel): +class RealtimeClientSecretResponse(LiteLLMBaseModel): """ Response from POST /v1/realtime/client_secrets. @@ -117,7 +119,7 @@ class RealtimeClientSecretResponse(BaseModel): session: dict[str, object] | None = None -class RealtimeTranscriptionSessionRequest(BaseModel): +class RealtimeTranscriptionSessionRequest(LiteLLMBaseModel): """ Request body for POST /v1/realtime/transcription_sessions. @@ -127,7 +129,7 @@ class RealtimeTranscriptionSessionRequest(BaseModel): unchanged to the provider. """ - model_config = {"extra": "allow"} + model_config = ConfigDict(extra="allow") # LiteLLM-only routing hint — stripped before forwarding upstream. model: str | None = None @@ -141,7 +143,7 @@ class RealtimeTranscriptionSessionRequest(BaseModel): return None -class RealtimeTranscriptionSessionResponse(BaseModel): +class RealtimeTranscriptionSessionResponse(LiteLLMBaseModel): """ Response from POST /v1/realtime/transcription_sessions. @@ -149,7 +151,7 @@ class RealtimeTranscriptionSessionResponse(BaseModel): ephemeral key. Unknown fields pass through unchanged. """ - model_config = {"extra": "allow"} + model_config = ConfigDict(extra="allow") client_secret: dict[str, object] | None = None diff --git a/litellm/types/rerank.py b/litellm/types/rerank.py index a76e6cf1187..81cb1b7e315 100644 --- a/litellm/types/rerank.py +++ b/litellm/types/rerank.py @@ -6,11 +6,13 @@ https://docs.cohere.com/reference/rerank from typing import Literal -from pydantic import BaseModel, ConfigDict, PrivateAttr +from pydantic import ConfigDict, PrivateAttr from typing_extensions import ReadOnly, Required, TypedDict +from litellm.types.llms.base import LiteLLMBaseModel -class RerankRequest(BaseModel): + +class RerankRequest(LiteLLMBaseModel): model: str query: str top_n: int | None = None @@ -28,7 +30,7 @@ class RerankRequest(BaseModel): max_tokens_per_query: int | None = None -class HostedVLLMRerankTruncationParams(BaseModel): +class HostedVLLMRerankTruncationParams(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) truncate_prompt_tokens: int | None = None @@ -77,7 +79,7 @@ class RerankResponseResult(TypedDict, total=False): document: RerankResponseDocument -class RerankResponse(BaseModel): +class RerankResponse(LiteLLMBaseModel): id: str | None = None results: list[RerankResponseResult] | None = None # Contains index and relevance_score meta: RerankResponseMeta | None = None # Contains api_version and billed_units diff --git a/litellm/types/roi_calculator.py b/litellm/types/roi_calculator.py index 7a6cd8ab2e1..d8c0f27a895 100644 --- a/litellm/types/roi_calculator.py +++ b/litellm/types/roi_calculator.py @@ -3,9 +3,11 @@ from datetime import datetime from types import MappingProxyType from typing import Final, Literal -from pydantic import BaseModel, ConfigDict, Field, SecretStr, StrictFloat, StrictInt, ValidationInfo, field_validator +from pydantic import ConfigDict, Field, SecretStr, StrictFloat, StrictInt, ValidationInfo, field_validator from typing_extensions import NotRequired, ReadOnly, TypedDict +from litellm.types.llms.base import LiteLLMBaseModel + DEFAULT_PROMPT: Final = ( "Estimate how many hours it would take an engineer to complete the work in this pull request without AI assistance. " "Explain your estimate briefly." @@ -22,7 +24,7 @@ def normalize_source_login(value: str, provider: str = "github") -> str: return login -class ROISettings(BaseModel): +class ROISettings(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) report_mode: Literal["legacy", "observed"] = "legacy" @@ -129,7 +131,7 @@ class ROISettings(BaseModel): return normalized -class ROISettingsUpdate(BaseModel): +class ROISettingsUpdate(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid") report_mode: Literal["legacy", "observed"] | None = None @@ -146,12 +148,12 @@ class ROISettingsUpdate(BaseModel): update_interval_minutes: float | None = Field(default=None, ge=0, le=43200, allow_inf_nan=False) -class ROIEstimatorModel(BaseModel): +class ROIEstimatorModel(LiteLLMBaseModel): model_name: str provider_models: tuple[str, ...] -class ROISettingsResponse(BaseModel): +class ROISettingsResponse(LiteLLMBaseModel): report_mode: Literal["legacy", "observed"] = "legacy" source_provider: Literal["github", "gitlab"] = "github" gitlab_api_url: str = "https://gitlab.com/api/v4" @@ -171,19 +173,19 @@ class ROISettingsResponse(BaseModel): ready: bool -class ROIRepository(BaseModel): +class ROIRepository(LiteLLMBaseModel): name: str visibility: str archived: bool -class ROIRepositoriesResponse(BaseModel): +class ROIRepositoriesResponse(LiteLLMBaseModel): repositories: tuple[ROIRepository, ...] page: int has_more: bool -class ROISyncStatus(BaseModel): +class ROISyncStatus(LiteLLMBaseModel): running: bool phase: Literal["idle", "spend", "repositories", "estimates", "complete", "cancelled", "error"] stage: str @@ -240,14 +242,14 @@ class ROIPullRecord(TypedDict): cache_key: ReadOnly[str | None] -class ROIBranchSpend(BaseModel): +class ROIBranchSpend(LiteLLMBaseModel): repo: str branch: str spend: float requests: int -class ROIBranchAttribution(BaseModel): +class ROIBranchAttribution(LiteLLMBaseModel): repo: str branch: str spend: float | None = None @@ -255,7 +257,7 @@ class ROIBranchAttribution(BaseModel): status: Literal["matched", "unattributed", "ambiguous", "unavailable"] = "unattributed" -class ROIBranchMetrics(BaseModel): +class ROIBranchMetrics(LiteLLMBaseModel): spend: float = 0 hours: float = 0 cost_per_hour: float | None = None @@ -410,7 +412,7 @@ class ROISummary(TypedDict): trend: ReadOnly[tuple[ROITrendDay, ...]] -class ROIMetricsResponse(BaseModel): +class ROIMetricsResponse(LiteLLMBaseModel): matched_spend: float output_hours: float total_spend: float @@ -426,7 +428,7 @@ class ROIMetricsResponse(BaseModel): pending_prs: int -class ROIPersonResponse(BaseModel): +class ROIPersonResponse(LiteLLMBaseModel): id: str email: str logins: tuple[str, ...] @@ -440,7 +442,7 @@ class ROIPersonResponse(BaseModel): cost_per_hour: float | None -class ROIEstimateResponse(BaseModel): +class ROIEstimateResponse(LiteLLMBaseModel): status: Literal["estimated", "needs_review", "error"] hours: float | None reasoning: str @@ -450,7 +452,7 @@ class ROIEstimateResponse(BaseModel): cached: bool = False -class ROIPullResponse(BaseModel): +class ROIPullResponse(LiteLLMBaseModel): source_repo: str = "" source_branch: str = "" branch_cost: ROIBranchAttribution = Field(default_factory=lambda: ROIBranchAttribution(repo="", branch="")) @@ -475,14 +477,14 @@ class ROIPullResponse(BaseModel): matched: bool -class ROITrendResponse(BaseModel): +class ROITrendResponse(LiteLLMBaseModel): date: str spend: float hours: float prs: int -class ROISummaryResponse(BaseModel): +class ROISummaryResponse(LiteLLMBaseModel): source_provider: Literal["github", "gitlab"] = "github" branch_metrics: ROIBranchMetrics = Field(default_factory=ROIBranchMetrics) unlinked_branches: tuple[ROIBranchSpend, ...] = () @@ -502,11 +504,11 @@ class ROISummaryResponse(BaseModel): trend: tuple[ROITrendResponse, ...] -class ROIReportResponse(BaseModel): +class ROIReportResponse(LiteLLMBaseModel): report: ROISummaryResponse | None -class ROIIdentityMapUpdate(BaseModel): +class ROIIdentityMapUpdate(LiteLLMBaseModel): github_login: str email: str | None @@ -516,26 +518,26 @@ class ROIIdentityMapUpdate(BaseModel): return value.strip().casefold() -class ROIIdentityMapResponse(BaseModel): +class ROIIdentityMapResponse(LiteLLMBaseModel): report: ROISummaryResponse | None identity_map: Mapping[str, str] -class ROIEstimatorChanges(BaseModel): +class ROIEstimatorChanges(LiteLLMBaseModel): additions: int deletions: int files: int commits: int -class ROIEstimatorFile(BaseModel): +class ROIEstimatorFile(LiteLLMBaseModel): filename: str | None status: str | None additions: int | None deletions: int | None -class ROIEstimatorCommit(BaseModel): +class ROIEstimatorCommit(LiteLLMBaseModel): sha: str message: str additions: int | None = None @@ -543,7 +545,7 @@ class ROIEstimatorCommit(BaseModel): changed_files: int | None = None -class ROIEstimatorEvidence(BaseModel): +class ROIEstimatorEvidence(LiteLLMBaseModel): repo: str number: int title: str @@ -566,7 +568,7 @@ class ROIResponseFormat(TypedDict): type: ReadOnly[Literal["json_object"]] -class ROICompletionRequest(BaseModel): +class ROICompletionRequest(LiteLLMBaseModel): model: str temperature: Literal[0] messages: tuple[ROICompletionMessage, ...] @@ -576,26 +578,26 @@ class ROICompletionRequest(BaseModel): reasoning_effort: Literal["none"] | None = None -class _ROICompletionMessageResponse(BaseModel): +class _ROICompletionMessageResponse(LiteLLMBaseModel): model_config = ConfigDict(from_attributes=True) content: str | None = None -class _ROICompletionChoice(BaseModel): +class _ROICompletionChoice(LiteLLMBaseModel): model_config = ConfigDict(from_attributes=True) finish_reason: str | None = None message: _ROICompletionMessageResponse -class ROICompletionResponse(BaseModel): +class ROICompletionResponse(LiteLLMBaseModel): model_config = ConfigDict(from_attributes=True) choices: tuple[_ROICompletionChoice, ...] -class ROIEstimatorResult(BaseModel): +class ROIEstimatorResult(LiteLLMBaseModel): model_config = ConfigDict(strict=True, extra="forbid") hours: StrictInt | StrictFloat diff --git a/litellm/types/roi_observed.py b/litellm/types/roi_observed.py index b617175788b..eee85d831a2 100644 --- a/litellm/types/roi_observed.py +++ b/litellm/types/roi_observed.py @@ -2,12 +2,13 @@ from collections.abc import Mapping from datetime import date, datetime from typing import Literal -from pydantic import BaseModel, ConfigDict, Field +from pydantic import ConfigDict, Field +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.roi_calculator import ROIBranchAttribution, ROIBranchSpend, ROISpendRecord -class ObservedModel(BaseModel): +class ObservedModel(LiteLLMBaseModel): model_config = ConfigDict(frozen=True) @@ -151,7 +152,7 @@ class ObservedReportResponse(ObservedModel): report: ObservedReport | None -class ObservedIdentityUpdate(BaseModel): +class ObservedIdentityUpdate(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid") email: str @@ -186,7 +187,7 @@ class ObservedSettings(ObservedConnection): connections: tuple[ObservedConnection, ...] = () -class ObservedSettingsUpdate(BaseModel): +class ObservedSettingsUpdate(LiteLLMBaseModel): model_config = ConfigDict(extra="forbid") connection_id: str | None = Field(default=None, max_length=100) diff --git a/litellm/types/router.py b/litellm/types/router.py index 6c52120c3ae..8fd53079156 100644 --- a/litellm/types/router.py +++ b/litellm/types/router.py @@ -21,13 +21,14 @@ from typing import ( from zoneinfo import ZoneInfo, ZoneInfoNotFoundError import httpx -from pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator +from pydantic import ConfigDict, Field, field_validator, model_validator from typing_extensions import Protocol, ReadOnly, Required, TypedDict, runtime_checkable from litellm._logging import verbose_logger from litellm._uuid import uuid from litellm.litellm_core_utils.core_helpers import normalize_drop_params from litellm.litellm_core_utils.provider_affinity import validate_provider_affinity_header_name +from litellm.types.llms.base import LiteLLMBaseModel from litellm.types.router_weights import RouterWeights if TYPE_CHECKING: @@ -60,7 +61,7 @@ class ConfigurableClientsideParamsCustomAuth(TypedDict): CONFIGURABLE_CLIENTSIDE_AUTH_PARAMS = list[str | ConfigurableClientsideParamsCustomAuth] | None -class ModelConfig(BaseModel): +class ModelConfig(LiteLLMBaseModel): model_name: str litellm_params: CompletionRequest | EmbeddingRequest tpm: int @@ -69,7 +70,7 @@ class ModelConfig(BaseModel): model_config = ConfigDict(protected_namespaces=()) -class RoutingGroup(BaseModel): +class RoutingGroup(LiteLLMBaseModel): """ A group of models that share a routing strategy. """ @@ -101,7 +102,7 @@ class RoutingGroup(BaseModel): model_config = ConfigDict(protected_namespaces=()) -class RouterConfig(BaseModel): +class RouterConfig(LiteLLMBaseModel): model_list: list[ModelConfig] redis_url: str | None = None @@ -110,17 +111,17 @@ class RouterConfig(BaseModel): redis_password: str | None = None cache_responses: bool | None = False - cache_kwargs: dict | None = {} + cache_kwargs: dict | None = Field(default={}) caching_groups: list[tuple[str, list[str]]] | None = None client_ttl: int | None = 3600 num_retries: int | None = 0 timeout: float | None = None - default_litellm_params: dict[str, str] | None = {} + default_litellm_params: dict[str, str] | None = Field(default={}) set_verbose: bool | None = False - fallbacks: list | None = [] + fallbacks: list | None = Field(default=[]) allowed_fails: int | None = None - context_window_fallbacks: list | None = [] - model_group_alias: dict[str, list[str]] | None = {} + context_window_fallbacks: list | None = Field(default=[]) + model_group_alias: dict[str, list[str]] | None = Field(default={}) retry_after: int | None = 0 routing_strategy: RoutingStrategyName = "simple-shuffle" routing_groups: list[RoutingGroup] | None = None @@ -128,7 +129,7 @@ class RouterConfig(BaseModel): model_config = ConfigDict(protected_namespaces=()) -class RetryPolicy(BaseModel): +class RetryPolicy(LiteLLMBaseModel): """ Use this to set a custom number of retries per exception type If RateLimitErrorRetries = 3, then 3 retries will be made for RateLimitError @@ -161,7 +162,7 @@ OptionalPreCallChecks = list[ ] -class UpdateRouterConfig(BaseModel): +class UpdateRouterConfig(LiteLLMBaseModel): """ Set of params that you can modify via `router.update_settings()`. """ @@ -180,7 +181,7 @@ class UpdateRouterConfig(BaseModel): retry_after: float | None = None fallbacks: list[dict] | None = None context_window_fallbacks: list[dict] | None = None - model_group_alias: dict[str, str | dict] | None = {} + model_group_alias: dict[str, str | dict] | None = Field(default={}) enable_tag_filtering: bool | None = None weights: RouterWeights | None = None tag_routing_prefix: str | None = None @@ -197,7 +198,7 @@ def _as_utc(value: datetime.datetime | None) -> datetime.datetime | None: return value.astimezone(datetime.timezone.utc) -class ModelAccessWindow(BaseModel): +class ModelAccessWindow(LiteLLMBaseModel): model_config = ConfigDict(frozen=True, extra="forbid") start: datetime.time @@ -336,7 +337,7 @@ class ModelInfo(MirroredPricingParams): setattr(self, key, value) -class CredentialLiteLLMParams(BaseModel): +class CredentialLiteLLMParams(LiteLLMBaseModel): api_key: str | None = None api_base: str | None = None api_version: str | None = None @@ -630,7 +631,7 @@ class updateLiteLLMParams(GenericLiteLLMParams): model: str | None = None -class updateDeployment(BaseModel): +class updateDeployment(LiteLLMBaseModel): model_name: str | None = None litellm_params: updateLiteLLMParams | None = None model_info: ModelInfo | None = None @@ -724,7 +725,7 @@ class DeploymentTypedDict(TypedDict, total=False): SPECIAL_MODEL_INFO_PARAMS = tuple(MirroredPricingParams.model_fields) -class Deployment(BaseModel): +class Deployment(LiteLLMBaseModel): model_name: str litellm_params: LiteLLM_Params model_info: ModelInfo @@ -824,7 +825,7 @@ class RouterErrors(enum.Enum): ) -class AllowedFailsPolicy(BaseModel): +class AllowedFailsPolicy(LiteLLMBaseModel): """ Use this to set a custom number of allowed fails/minute before cooling down a deployment If `AuthenticationErrorAllowedFails = 1000`, then 1000 AuthenticationError will be allowed before cooling down a deployment @@ -844,7 +845,7 @@ class AllowedFailsPolicy(BaseModel): NotFoundErrorAllowedFails: int | None = None -class AlertingConfig(BaseModel): +class AlertingConfig(LiteLLMBaseModel): """ Use this configure alerting for the router. Receive alerts on the following events - LLM API Exceptions @@ -865,7 +866,7 @@ def _resolved_annotations(model_class: type[object]) -> Mapping[str, object]: return get_type_hints(model_class) -class ModelGroupInfo(BaseModel): +class ModelGroupInfo(LiteLLMBaseModel): model_group: str providers: list[str] max_input_tokens: float | None = None @@ -966,7 +967,7 @@ class GuardrailTypedDict(TypedDict, total=False): id: str | None # Unique identifier for the guardrail deployment -class FineTuningConfig(BaseModel): +class FineTuningConfig(LiteLLMBaseModel): custom_llm_provider: Literal["azure", "openai"] @@ -1018,7 +1019,7 @@ class CustomRoutingStrategyBase: """ -class RouterGeneralSettings(BaseModel): +class RouterGeneralSettings(LiteLLMBaseModel): async_only_mode: bool = Field(default=False) # this will only initialize async clients. Good for memory utils pass_through_all_models: bool = Field( default=False @@ -1109,7 +1110,7 @@ class RouterCacheEnum(enum.Enum): OTPM = "global_router:{id}:{model}:otpm:{current_minute}" -class GenericBudgetWindowDetails(BaseModel): +class GenericBudgetWindowDetails(LiteLLMBaseModel): """Details about a provider's budget window""" budget_start: float @@ -1184,11 +1185,11 @@ class MockRouterTestingParams: ) -class ModelGroupSettings(BaseModel): +class ModelGroupSettings(LiteLLMBaseModel): forward_client_headers_to_llm_api: list[str] | None = None -class PreRoutingHookResponse(BaseModel): +class PreRoutingHookResponse(LiteLLMBaseModel): """ Response object from the pre-routing hook. @@ -1244,7 +1245,7 @@ class PreRoutingStrategy(Protocol): ) -> "PreRoutingHookResponse | None": ... -class RoutingContext(BaseModel): +class RoutingContext(LiteLLMBaseModel): """ Passed through a Router's `plugins` pipeline before the routing decision is made. @@ -1301,7 +1302,7 @@ class RequestType(str, enum.Enum): GENERAL = "general" -class AdaptiveRouterWeights(BaseModel): +class AdaptiveRouterWeights(LiteLLMBaseModel): quality: float = Field(default=0.7, ge=0.0, le=1.0) cost: float = Field(default=0.3, ge=0.0, le=1.0) @@ -1314,12 +1315,12 @@ class AdaptiveRouterWeights(BaseModel): return v -class AdaptiveRouterConfig(BaseModel): +class AdaptiveRouterConfig(LiteLLMBaseModel): available_models: list[str] weights: AdaptiveRouterWeights = Field(default_factory=AdaptiveRouterWeights) -class AdaptiveRouterPreferences(BaseModel): +class AdaptiveRouterPreferences(LiteLLMBaseModel): """model_info.adaptive_router_preferences — declared by each model.""" model_config = ConfigDict(use_enum_values=False) diff --git a/litellm/types/services.py b/litellm/types/services.py index 8a74be06da6..e86044c9303 100644 --- a/litellm/types/services.py +++ b/litellm/types/services.py @@ -1,9 +1,11 @@ import enum from typing import Final -from pydantic import BaseModel, Field +from pydantic import Field from typing_extensions import TypedDict +from litellm.types.llms.base import LiteLLMBaseModel + class ServiceMetrics(enum.Enum): COUNTER = "counter" @@ -95,7 +97,7 @@ class ServiceEventMetadata(TypedDict, total=False): gauge_value: float | None -class ServiceLoggerPayload(BaseModel): +class ServiceLoggerPayload(LiteLLMBaseModel): """ The payload logged during service success/failure """ diff --git a/litellm/types/tag_management.py b/litellm/types/tag_management.py index f121f5bc562..e59b02af71a 100644 --- a/litellm/types/tag_management.py +++ b/litellm/types/tag_management.py @@ -1,7 +1,7 @@ -from pydantic import BaseModel +from litellm.types.llms.base import LiteLLMBaseModel -class TagBase(BaseModel): +class TagBase(LiteLLMBaseModel): name: str description: str | None = None models: list[str] | None = None @@ -38,9 +38,9 @@ class TagUpdateRequest(TagBase): budget_duration: str | None = None -class TagDeleteRequest(BaseModel): +class TagDeleteRequest(LiteLLMBaseModel): name: str -class TagInfoRequest(BaseModel): +class TagInfoRequest(LiteLLMBaseModel): names: list[str] diff --git a/litellm/types/tool_management.py b/litellm/types/tool_management.py index 13553dbecc6..5ea500fc0f2 100644 --- a/litellm/types/tool_management.py +++ b/litellm/types/tool_management.py @@ -5,7 +5,9 @@ Pydantic models for Tool Policy management endpoints. from datetime import datetime from typing import Literal -from pydantic import BaseModel, Field +from pydantic import Field + +from litellm.types.llms.base import LiteLLMBaseModel ToolCallPolicy = Literal["trusted", "untrusted", "dual_llm", "blocked"] @@ -13,13 +15,13 @@ ToolInputPolicy = Literal["trusted", "untrusted", "blocked"] ToolOutputPolicy = Literal["trusted", "untrusted"] -class ToolDiscoveryUser(BaseModel): +class ToolDiscoveryUser(LiteLLMBaseModel): user_id: str user_email: str | None = None user_alias: str | None = None -class LiteLLM_ToolTableRow(BaseModel): +class LiteLLM_ToolTableRow(LiteLLMBaseModel): tool_id: str tool_name: str origin: str | None = None @@ -39,12 +41,12 @@ class LiteLLM_ToolTableRow(BaseModel): updated_by: str | None = None -class ToolListResponse(BaseModel): +class ToolListResponse(LiteLLMBaseModel): tools: list[LiteLLM_ToolTableRow] total: int -class ToolPolicyUpdateRequest(BaseModel): +class ToolPolicyUpdateRequest(LiteLLMBaseModel): tool_name: str input_policy: ToolInputPolicy | None = None output_policy: ToolOutputPolicy | None = None @@ -53,7 +55,7 @@ class ToolPolicyUpdateRequest(BaseModel): key_alias: str | None = None -class ToolPolicyUpdateResponse(BaseModel): +class ToolPolicyUpdateResponse(LiteLLMBaseModel): tool_name: str input_policy: ToolInputPolicy | None = None output_policy: ToolOutputPolicy | None = None @@ -62,7 +64,7 @@ class ToolPolicyUpdateResponse(BaseModel): key_hash: str | None = None -class ToolPolicyOverrideRow(BaseModel): +class ToolPolicyOverrideRow(LiteLLMBaseModel): override_id: str tool_name: str team_id: str | None = None @@ -73,23 +75,23 @@ class ToolPolicyOverrideRow(BaseModel): updated_at: datetime | None = None -class ToolPolicyOption(BaseModel): +class ToolPolicyOption(LiteLLMBaseModel): value: str label: str description: str -class ToolPolicyOptionsResponse(BaseModel): +class ToolPolicyOptionsResponse(LiteLLMBaseModel): input_policies: list[ToolPolicyOption] output_policies: list[ToolPolicyOption] -class ToolDetailResponse(BaseModel): +class ToolDetailResponse(LiteLLMBaseModel): tool: LiteLLM_ToolTableRow overrides: list[ToolPolicyOverrideRow] = Field(default_factory=list) -class ToolUsageLogEntry(BaseModel): +class ToolUsageLogEntry(LiteLLMBaseModel): """One spend log row for a tool call (for UI "recent logs" table).""" id: str # request_id @@ -100,14 +102,14 @@ class ToolUsageLogEntry(BaseModel): input_snippet: str | None = None -class ToolUsageLogsResponse(BaseModel): +class ToolUsageLogsResponse(LiteLLMBaseModel): logs: list[ToolUsageLogEntry] total: int page: int page_size: int -class ToolSpendEntry(BaseModel): +class ToolSpendEntry(LiteLLMBaseModel): """Total spend attributed to one tool over the requested window.""" tool_name: str @@ -119,7 +121,7 @@ class ToolSpendEntry(BaseModel): total_tokens: int = 0 -class ToolSpendDailyEntry(BaseModel): +class ToolSpendDailyEntry(LiteLLMBaseModel): """Spend attributed to one tool on one UTC day.""" date: str @@ -128,7 +130,7 @@ class ToolSpendDailyEntry(BaseModel): call_count: int = 0 -class ToolSpendResponse(BaseModel): +class ToolSpendResponse(LiteLLMBaseModel): by_tool: list[ToolSpendEntry] = Field(default_factory=list) daily: list[ToolSpendDailyEntry] = Field(default_factory=list) start_date: str | None = None diff --git a/litellm/types/utils.py b/litellm/types/utils.py index 2c4dff592e5..d3fe65037e2 100644 --- a/litellm/types/utils.py +++ b/litellm/types/utils.py @@ -52,6 +52,7 @@ from litellm.constants import INTERNAL_KWARG_PREFIX from litellm.types.llms.base import ( BaseLiteLLMOpenAIResponseObject, CachedTokensDetails, + LiteLLMBaseModel, LiteLLMPydanticObjectBase, ) from litellm.types.mcp import MCPServerCostInfo @@ -1740,7 +1741,7 @@ class CompletionTokensDetailsWrapper(CompletionTokensDetails): # wrapper for ol """Video tokens generated by the model.""" -class CacheCreationTokenDetails(BaseModel): +class CacheCreationTokenDetails(LiteLLMBaseModel): ephemeral_5m_input_tokens: int | None = None ephemeral_1h_input_tokens: int | None = None @@ -1843,7 +1844,7 @@ class PromptTokensDetailsWrapper( del self.cached_tokens_details -class ServerToolUse(BaseModel): +class ServerToolUse(LiteLLMBaseModel): web_search_requests: int | None = None tool_search_requests: int | None = None browser_open_requests: int | None = None @@ -2723,17 +2724,17 @@ class ImageResponse(OpenAIImageResponse, BaseLiteLLMOpenAIResponseObject): return self.dict() -class TranscriptionUsageDurationObject(BaseModel): +class TranscriptionUsageDurationObject(LiteLLMBaseModel): type: Literal["duration"] seconds: float -class TranscriptionUsageInputTokenDetailsObject(BaseModel): +class TranscriptionUsageInputTokenDetailsObject(LiteLLMBaseModel): audio_tokens: int text_tokens: int -class TranscriptionUsageTokensObject(BaseModel): +class TranscriptionUsageTokensObject(LiteLLMBaseModel): type: Literal["tokens"] input_tokens: int output_tokens: int @@ -3708,7 +3709,7 @@ class StandardCallbackDynamicParams(TypedDict, total=False): litellm_disabled_callbacks: list[str] | None -class MirroredPricingParams(BaseModel): +class MirroredPricingParams(LiteLLMBaseModel): """Pricing overrides that ``Deployment.__init__`` mirrors from ``litellm_params`` onto ``model_info``, so both blobs hold the same rate. @@ -3997,7 +3998,7 @@ class StandardKeyGenerationConfig(TypedDict, total=False): personal_key_generation: PersonalUIKeyGenerationConfig -class BudgetConfig(BaseModel): +class BudgetConfig(LiteLLMBaseModel): max_budget: float | None = None budget_duration: str | None = None tpm_limit: int | None = None @@ -4516,7 +4517,7 @@ class PriorityReservationDict(TypedDict, total=False): value: float -class PriorityReservationSettings(BaseModel): +class PriorityReservationSettings(LiteLLMBaseModel): """ Settings for priority-based rate limiting reservation. diff --git a/litellm/types/vector_stores.py b/litellm/types/vector_stores.py index 34c14e6b042..5e7d517ece2 100644 --- a/litellm/types/vector_stores.py +++ b/litellm/types/vector_stores.py @@ -4,9 +4,10 @@ from datetime import datetime from enum import Enum from typing import Any, Literal -from pydantic import BaseModel from typing_extensions import ReadOnly, TypedDict +from litellm.types.llms.base import LiteLLMBaseModel + class SupportedVectorStoreIntegrations(str, Enum): """Supported vector store integrations.""" @@ -57,7 +58,7 @@ class LiteLLM_ManagedVectorStoreListResponse(TypedDict, total=False): total_pages: int | None -class VectorStoreUpdateRequest(BaseModel): +class VectorStoreUpdateRequest(LiteLLMBaseModel): vector_store_id: str custom_llm_provider: str | None = None vector_store_name: str | None = None @@ -65,11 +66,11 @@ class VectorStoreUpdateRequest(BaseModel): vector_store_metadata: dict | None = None -class VectorStoreDeleteRequest(BaseModel): +class VectorStoreDeleteRequest(LiteLLMBaseModel): vector_store_id: str -class VectorStoreInfoRequest(BaseModel): +class VectorStoreInfoRequest(LiteLLMBaseModel): vector_store_id: str @@ -262,12 +263,12 @@ class VectorStoreCreateResponse(TypedDict, total=False): metadata: dict[str, str] | None # Metadata associated with the vector store -class IndexCreateLiteLLMParams(BaseModel): +class IndexCreateLiteLLMParams(LiteLLMBaseModel): vector_store_index: str vector_store_name: str -class IndexCreateRequest(BaseModel): +class IndexCreateRequest(LiteLLMBaseModel): index_name: str litellm_params: IndexCreateLiteLLMParams index_info: dict[str, object] | None = None @@ -278,7 +279,7 @@ class BaseVectorStoreAuthCredentials(TypedDict, total=False): query_params: dict -class LiteLLM_ManagedVectorStoreIndex(BaseModel): +class LiteLLM_ManagedVectorStoreIndex(LiteLLMBaseModel): """LiteLLM managed vector store index object - this is is the object stored in the database""" id: str @@ -291,7 +292,7 @@ class LiteLLM_ManagedVectorStoreIndex(BaseModel): updated_by: str | None = None -class IndexListResponse(BaseModel): +class IndexListResponse(LiteLLMBaseModel): object: Literal["list"] = "list" data: tuple[LiteLLM_ManagedVectorStoreIndex, ...] diff --git a/litellm/types/videos/main.py b/litellm/types/videos/main.py index f4369fd95af..7c22fe18745 100644 --- a/litellm/types/videos/main.py +++ b/litellm/types/videos/main.py @@ -2,11 +2,13 @@ import builtins from typing import Any, Literal from openai.types.audio.transcription_create_params import FileTypes -from pydantic import BaseModel +from pydantic import Field, PrivateAttr from typing_extensions import ReadOnly, TypedDict +from litellm.types.llms.base import LiteLLMBaseModel -class VideoObject(BaseModel): + +class VideoObject(LiteLLMBaseModel): """Represents a generated video object.""" id: str @@ -22,7 +24,7 @@ class VideoObject(BaseModel): size: str | None = None model: str | None = None usage: dict[str, Any] | None = None - _hidden_params: dict[str, builtins.object] = {} + _hidden_params: dict[str, builtins.object] = PrivateAttr(default={}) def __contains__(self, key) -> bool: # Define custom behavior for the 'in' operator @@ -44,11 +46,11 @@ class VideoObject(BaseModel): return self.dict() -class VideoResponse(BaseModel): +class VideoResponse(LiteLLMBaseModel): """Response object for video generation requests.""" data: list[VideoObject] - hidden_params: dict[str, object] = {} + hidden_params: dict[str, object] = Field(default={}) def __contains__(self, key) -> bool: return hasattr(self, key) @@ -104,14 +106,14 @@ class DecodedVideoId(TypedDict, total=False): video_id: str -class CharacterObject(BaseModel): +class CharacterObject(LiteLLMBaseModel): """Represents a character created from a video.""" id: str object: Literal["character"] = "character" created_at: int name: str - _hidden_params: dict[str, builtins.object] = {} + _hidden_params: dict[str, builtins.object] = PrivateAttr(default={}) def __contains__(self, key) -> bool: return hasattr(self, key) diff --git a/scripts/generate_trace_types.py b/scripts/generate_trace_types.py index a8f4054a646..4ba462ae731 100644 --- a/scripts/generate_trace_types.py +++ b/scripts/generate_trace_types.py @@ -99,6 +99,8 @@ def generate( else ( "--output-model-type", "pydantic_v2.BaseModel", + "--base-class", + "litellm.types.llms.base.LiteLLMBaseModel", "--enable-faux-immutability", "--additional-imports", "collections.abc.Mapping,typing.TypeAlias,pydantic.JsonValue", diff --git a/tests/unit/types/llms/test_types_llms_base.py b/tests/unit/types/llms/test_types_llms_base.py new file mode 100644 index 00000000000..32f22e68397 --- /dev/null +++ b/tests/unit/types/llms/test_types_llms_base.py @@ -0,0 +1,73 @@ +import os +import subprocess +import sys +from typing import Final + +import pytest + +_PROBE: Final = """ +from litellm.types.llms.base import LiteLLMBaseModel + + +class Probe(LiteLLMBaseModel): + value: int + + +print(Probe.__pydantic_complete__, Probe(value=1).value, Probe.__pydantic_complete__) +""" + + +def _run_probe(probe: str, defer_pydantic_build: str | None) -> str: + env: Final = {key: value for key, value in os.environ.items() if key != "DEFER_PYDANTIC_BUILD"} + overrides: Final = {} if defer_pydantic_build is None else {"DEFER_PYDANTIC_BUILD": defer_pydantic_build} + result: Final = subprocess.run( + (sys.executable, "-I", "-c", probe), + env={**env, **overrides}, + capture_output=True, + text=True, + check=True, + timeout=120, + ) + return result.stdout.strip().splitlines()[-1] + + +def _probe_with(defer_pydantic_build: str | None) -> str: + return _run_probe(_PROBE, defer_pydantic_build) + + +@pytest.mark.parametrize("defer_pydantic_build", [None, "true", "1", "on"]) +def test_litellm_models_defer_schema_build_until_first_use(defer_pydantic_build: str | None) -> None: + assert _probe_with(defer_pydantic_build) == "False 1 True" + + +@pytest.mark.parametrize("defer_pydantic_build", ["false", "0", "off"]) +def test_litellm_models_build_schema_at_class_creation_when_defer_is_disabled(defer_pydantic_build: str) -> None: + assert _probe_with(defer_pydantic_build) == "True 1 True" + + +_NESTED_PROBE: Final = """ +from pydantic import BaseModel + +from litellm.types.llms.base import LiteLLMBaseModel + + +class Inner(LiteLLMBaseModel): + value: int + + +class Parent(LiteLLMBaseModel): + inner: Inner + + +class Holder(BaseModel): + item: object + + +validated = Parent(inner={"value": 1}).inner +constructed = Inner.model_construct(value=2) +print(Holder(item=validated).model_dump_json(serialize_as_any=True), Holder(item=constructed).model_dump_json()) +""" + + +def test_deferred_instances_created_without_their_own_init_still_serialize_as_any() -> None: + assert _run_probe(_NESTED_PROBE, None) == '{"item":{"value":1}} {"item":{"value":2}}'