The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
refactor(types): import proxy-only types under TYPE_CHECKING in SDK modules (#44740)
devin-ai-integration[bot]0b633aa9c8e4
diff --git a/litellm/llms/base_llm/files/transformation.py b/litellm/llms/base_llm/files/transformation.pyindex 5ecf033fb2c..ec0b28a63ad 100644--- a/litellm/llms/base_llm/files/transformation.py+++ b/litellm/llms/base_llm/files/transformation.py@@ -6,7 +6,6 @@ import httpxfrom openai.types.file_deleted import FileDeletedfrom litellm.files.types import FileContentStreamingResult-from litellm.proxy._types import UserAPIKeyAuthfrom litellm.types.files import TwoStepFileUploadConfigfrom litellm.types.llms.openai import (AllMessageValues,@@ -23,16 +22,19 @@ from ..chat.transformation import BaseConfigif TYPE_CHECKING:from litellm.litellm_core_utils.litellm_logging import Logging as _LiteLLMLoggingObjfrom litellm.litellm_core_utils.tokenizer import Encoding as Tokenizer+ from litellm.proxy._types import UserAPIKeyAuth as _UserAPIKeyAuthfrom litellm.router import Router as _Routerfrom litellm.types.llms.openai import HttpxBinaryResponseContentLiteLLMLoggingObj = _LiteLLMLoggingObjSpan = AnyRouter = _Router+ UserAPIKeyAuth = _UserAPIKeyAuthelse:LiteLLMLoggingObj = AnySpan = AnyRouter = Any+ UserAPIKeyAuth = Anyclass BaseFileUploadStream(ABC):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.pyindex 03ec559b83d..0fa2bfff218 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@@ -1,6 +1,6 @@from collections.abc import Mappingfrom datetime import datetime-from typing import Final+from typing import TYPE_CHECKING, Finalimport httpxfrom pydantic import BaseModel, TypeAdapter, ValidationError@@ -11,9 +11,11 @@ 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.proxy._types import PassThroughEndpointLoggingTypedDictfrom litellm.types.utils import ModelResponse, StandardPassThroughResponseObject, Usage+if TYPE_CHECKING:+ from litellm.proxy._types import PassThroughEndpointLoggingTypedDict+class _TypeSafeUsage(BaseModel):input_tokens: int = 0@@ -68,7 +70,7 @@ class TypeSafePassthroughLoggingHandler:request_body: Mapping[str, object],custom_llm_provider: str,**kwargs: object,- ) -> PassThroughEndpointLoggingTypedDict:+ ) -> "PassThroughEndpointLoggingTypedDict":response: Final = _parse_typesafe_response(response_body)request_model_value: Final = request_body.get("model")request_model: Final = request_model_value if isinstance(request_model_value, str) else Nonediff --git a/litellm/responses/litellm_completion_transformation/session_handler.py b/litellm/responses/litellm_completion_transformation/session_handler.pyindex 1d6a47d6365..e6f4b364815 100644--- a/litellm/responses/litellm_completion_transformation/session_handler.py+++ b/litellm/responses/litellm_completion_transformation/session_handler.py@@ -5,7 +5,6 @@ from typing import TYPE_CHECKING, Any, Final, castimport litellmfrom litellm._logging import verbose_proxy_loggerfrom litellm.constants import REDACTED_BY_LITELLM, REDACTED_TOOL_CALL_ARGUMENTS_PLACEHOLDER-from litellm.proxy._types import SpendLogsMetadata, SpendLogsPayloadfrom litellm.proxy.spend_tracking.cold_storage_handler import ColdStorageHandlerfrom litellm.responses.utils import ResponsesAPIRequestUtilsfrom litellm.types.llms.openai import (@@ -17,6 +16,7 @@ from litellm.types.llms.openai import (from litellm.types.utils import ChatCompletionMessageToolCall, Message, ModelResponseif TYPE_CHECKING:+ from litellm.proxy._types import SpendLogsMetadata, SpendLogsPayloadfrom litellm.responses.litellm_completion_transformation.transformation import (ChatCompletionSession,)@@ -89,7 +89,7 @@ class ResponsesSessionHandler:@staticmethodasync def extend_chat_completion_message_with_spend_log_payload(- spend_log: SpendLogsPayload,+ spend_log: "SpendLogsPayload",chat_completion_message_history: list[AllMessageValues| GenericChatCompletionMessage@@ -161,7 +161,7 @@ class ResponsesSessionHandler:@staticmethodasync def get_proxy_server_request_from_spend_log(- spend_log: SpendLogsPayload,+ spend_log: "SpendLogsPayload",) -> dict | None:"""Get the parsed proxy server request from the spend log@@ -194,7 +194,7 @@ class ResponsesSessionHandler:@staticmethoddef _get_cold_storage_object_key_from_spend_log(- spend_log: SpendLogsPayload,+ spend_log: "SpendLogsPayload",) -> str | None:"""Extract the cold storage object key from spend log metadata.@@ -265,7 +265,7 @@ class ResponsesSessionHandler:@staticmethodasync def get_all_spend_logs_for_previous_response_id(previous_response_id: str,- ) -> list[SpendLogsPayload]:+ ) -> "list[SpendLogsPayload]":"""Get all spend logs for a previous response id