refactor: define pass-through custom body state key in types module

Avoid module-level cyclic import between llm_passthrough_endpoints and
pass_through_endpoints; CodeQL and partial init order no longer risk
undefined LITELLM_PASS_THROUGH_CUSTOM_BODY_STATE_KEY.

Made-with: Cursor
This commit is contained in:
shivam 2026-04-11 15:26:44 -07:00
parent 574eb207c8
commit 3742b0cee1
No known key found for this signature in database
3 changed files with 8 additions and 6 deletions

View file

@ -37,11 +37,13 @@ from litellm.proxy.common_utils.http_parsing_utils import (
from litellm.proxy.pass_through_endpoints.common_utils import get_litellm_virtual_key
from litellm.proxy.pass_through_endpoints.pass_through_endpoints import (
HttpPassThroughEndpointHelpers,
LITELLM_PASS_THROUGH_CUSTOM_BODY_STATE_KEY,
create_pass_through_route,
create_websocket_passthrough_route,
websocket_passthrough_request,
)
from litellm.types.passthrough_endpoints.pass_through_endpoints import (
LITELLM_PASS_THROUGH_CUSTOM_BODY_STATE_KEY,
)
from litellm.proxy.utils import is_known_model
from litellm.proxy.vector_store_endpoints.utils import (
is_allowed_to_call_vector_store_endpoint,

View file

@ -61,6 +61,7 @@ from litellm.secret_managers.main import get_secret_str
from litellm.types.llms.custom_http import httpxSpecialProvider
from litellm.types.passthrough_endpoints.pass_through_endpoints import (
EndpointType,
LITELLM_PASS_THROUGH_CUSTOM_BODY_STATE_KEY,
PassthroughStandardLoggingPayload,
)
@ -76,11 +77,6 @@ _registered_pass_through_routes: Dict[
str, Dict[str, Union[str, List[str], Dict[str, Any]]]
] = {}
# Programmatic pass-through callers (e.g. Bedrock proxy) attach JSON here. Must not use a
# `custom_body: dict` route parameter — FastAPI would treat it as the HTTP body and reject
# multipart/form-data before the handler runs.
LITELLM_PASS_THROUGH_CUSTOM_BODY_STATE_KEY = "litellm_pass_through_custom_body"
def get_response_body(response: httpx.Response) -> Optional[dict]:
try:

View file

@ -3,6 +3,10 @@ from typing import Optional
from typing_extensions import TypedDict
# Request.state key for programmatic pass-through callers (e.g. Bedrock proxy) that attach
# JSON without a FastAPI `custom_body` parameter (which would consume the HTTP body).
LITELLM_PASS_THROUGH_CUSTOM_BODY_STATE_KEY = "litellm_pass_through_custom_body"
class EndpointType(str, Enum):
VERTEX_AI = "vertex-ai"