refactor(types): import proxy-only types under TYPE_CHECKING in SDK modules (#44740)

Co-authored-by: nate <nate@berri.ai>
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
devin-ai-integration[bot] 2026-10-05 21:52:59 -07:00 • committed by GitHub
parent b72c737fc8
commit 0b633aa9c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 9 deletions

View file

@ -6,7 +6,6 @@ import httpx
from openai.types.file_deleted import FileDeleted
from litellm.files.types import FileContentStreamingResult
from litellm.proxy._types import UserAPIKeyAuth
from litellm.types.files import TwoStepFileUploadConfig
from litellm.types.llms.openai import (
AllMessageValues,
@ -23,16 +22,19 @@ from ..chat.transformation import BaseConfig
if TYPE_CHECKING:
from litellm.litellm_core_utils.litellm_logging import Logging as _LiteLLMLoggingObj
from litellm.litellm_core_utils.tokenizer import Encoding as Tokenizer
from litellm.proxy._types import UserAPIKeyAuth as _UserAPIKeyAuth
from litellm.router import Router as _Router
from litellm.types.llms.openai import HttpxBinaryResponseContent
LiteLLMLoggingObj = _LiteLLMLoggingObj
Span = Any
Router = _Router
UserAPIKeyAuth = _UserAPIKeyAuth
else:
LiteLLMLoggingObj = Any
Span = Any
Router = Any
UserAPIKeyAuth = Any
class BaseFileUploadStream(ABC):

View file

@ -1,6 +1,6 @@
from collections.abc import Mapping
from datetime import datetime
from typing import Final
from typing import TYPE_CHECKING, Final
import httpx
from 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 PassThroughEndpointLoggingTypedDict
from 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 None

View file

@ -5,7 +5,6 @@ from typing import TYPE_CHECKING, Any, Final, cast
import litellm
from litellm._logging import verbose_proxy_logger
from litellm.constants import REDACTED_BY_LITELLM, REDACTED_TOOL_CALL_ARGUMENTS_PLACEHOLDER
from litellm.proxy._types import SpendLogsMetadata, SpendLogsPayload
from litellm.proxy.spend_tracking.cold_storage_handler import ColdStorageHandler
from litellm.responses.utils import ResponsesAPIRequestUtils
from litellm.types.llms.openai import (
@ -17,6 +16,7 @@ from litellm.types.llms.openai import (
from litellm.types.utils import ChatCompletionMessageToolCall, Message, ModelResponse
if TYPE_CHECKING:
from litellm.proxy._types import SpendLogsMetadata, SpendLogsPayload
from litellm.responses.litellm_completion_transformation.transformation import (
ChatCompletionSession,
)
@ -89,7 +89,7 @@ class ResponsesSessionHandler:
@staticmethod
async 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:
@staticmethod
async 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:
@staticmethod
def _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:
@staticmethod
async 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