Skip to content

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]

Merge branch 'litellm_internal_staging' into devin_ai_require_managed_files_read_paths_35530

mateo-berri10209a8f919c
diff --cc litellm/proxy/openai_files_endpoints/common_utils.py
index 3eef3868c94,9f3c9d9db45..b26010c5597
--- a/litellm/proxy/openai_files_endpoints/common_utils.py
+++ b/litellm/proxy/openai_files_endpoints/common_utils.py
@@@ -866,36 -881,6 +881,37 @@@ def validate_managed_files_requirement
)
+def validate_managed_file_id_requirement(file_id: str) -> None:
+ """
+ Enforce proxy-level managed files on the file read/delete routes when
+ ``litellm.require_managed_files`` is enabled.
+
+ Ownership is only recorded for LiteLLM managed files, so a raw provider file id sent to
+ retrieve/content/delete is forwarded to the provider under shared credentials without any
+ tenant check; knowing another tenant's provider file id would be enough to read or delete it.
+
+ Raises:
+ HTTPException: 400 if ``file_id`` is not a LiteLLM managed file id.
+ """
- import litellm
+ from fastapi import HTTPException
+
++ import litellm
++
+ if litellm.require_managed_files is not True:
+ return
+
+ if _is_base64_encoded_unified_file_id(file_id):
+ return
+
+ raise HTTPException(
+ status_code=400,
+ detail=(
+ "Raw provider file ids cannot be used when require_managed_files is enabled in "
+ "litellm_settings. Use the LiteLLM managed file id returned when the file was created."
+ ),
+ )
+
+
def _extract_model_param(request: "Request", request_body: dict) -> str | None:
"""
Extract model parameter from request.
diff --cc litellm/proxy/openai_files_endpoints/files_endpoints.py
index 37f1ced6996,bf7aa96121a..5c1a4441d0d
--- a/litellm/proxy/openai_files_endpoints/files_endpoints.py
+++ b/litellm/proxy/openai_files_endpoints/files_endpoints.py
@@@ -613,10 -612,8 +613,10 @@@ async def get_file_content
data: dict = {"file_id": file_id}
try:
+ validate_managed_file_id_requirement(file_id=file_id)
+
# Include original request and headers in the data
- base_llm_response_processor = ProxyBaseLLMRequestProcessing(data=data)
+ base_llm_response_processor: Final = ProxyBaseLLMRequestProcessing(data=data)
(
data,
litellm_logging_obj,
@@@ -911,9 -908,7 +911,9 @@@ async def get_file
data: dict = {"file_id": file_id}
try:
+ validate_managed_file_id_requirement(file_id=file_id)
+
- custom_llm_provider = (
+ custom_llm_provider: Final = (
provider
or get_custom_llm_provider_from_request_headers(request=request)
or get_custom_llm_provider_from_request_query(request=request)
@@@ -1103,9 -1098,7 +1103,9 @@@ async def delete_file
data: dict = {"file_id": file_id}
try:
+ validate_managed_file_id_requirement(file_id=file_id)
+
- custom_llm_provider = (
+ custom_llm_provider: Final = (
provider
or get_custom_llm_provider_from_request_headers(request=request)
or get_custom_llm_provider_from_request_query(request=request)