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]

fix(proxy): enforce require_managed_files on every raw provider id route

mateo-berri5f7a663005bf
diff --git a/litellm/proxy/batches_endpoints/endpoints.py b/litellm/proxy/batches_endpoints/endpoints.py
index f7c332f2849..c9f66c5a48b 100644
--- a/litellm/proxy/batches_endpoints/endpoints.py
+++ b/litellm/proxy/batches_endpoints/endpoints.py
@@ -36,6 +36,7 @@ from litellm.proxy.openai_files_endpoints.common_utils import (
get_original_file_id,
prepare_data_with_credentials,
update_batch_in_database,
+ validate_managed_id_requirement,
)
from litellm.proxy.utils import handle_exception_on_proxy, is_known_model
from litellm.repositories.table_repositories import ManagedFileRepository
@@ -176,6 +177,7 @@ async def create_batch(
}
input_file_id: Final = _create_batch_data.get("input_file_id", None)
+ validate_managed_id_requirement(resource_id=input_file_id, resource_kind="file")
unified_file_id: str | Literal[False] = False
model_from_file_id = None
@@ -392,6 +394,7 @@ async def retrieve_batch(
data: dict = {}
try:
+ validate_managed_id_requirement(resource_id=batch_id, resource_kind="batch")
model_from_id: Final = decode_model_from_file_id(batch_id)
_retrieve_batch_request: Final = RetrieveBatchRequest(
batch_id=batch_id,
@@ -840,6 +843,8 @@ async def cancel_batch(
data: dict = {}
try:
+ validate_managed_id_requirement(resource_id=batch_id, resource_kind="batch")
+
# Check for encoded batch ID with model info
model_from_id: Final = decode_model_from_file_id(batch_id)
diff --git a/litellm/proxy/fine_tuning_endpoints/endpoints.py b/litellm/proxy/fine_tuning_endpoints/endpoints.py
index f8ffb77edb8..87e9895eed0 100644
--- a/litellm/proxy/fine_tuning_endpoints/endpoints.py
+++ b/litellm/proxy/fine_tuning_endpoints/endpoints.py
@@ -17,6 +17,7 @@ from litellm.proxy.auth.user_api_key_auth import user_api_key_auth
from litellm.proxy.common_request_processing import ProxyBaseLLMRequestProcessing
from litellm.proxy.openai_files_endpoints.common_utils import (
_is_base64_encoded_unified_file_id,
+ validate_managed_id_requirement,
)
from litellm.proxy.utils import handle_exception_on_proxy
from litellm.types.utils import LiteLLMFineTuningJob
@@ -134,6 +135,11 @@ async def create_fine_tuning_job(
## CHECK IF MANAGED FILE ID
unified_file_id: str | Literal[False] = False
training_file: Final = fine_tuning_request.training_file
+ validate_managed_id_requirement(resource_id=training_file, resource_kind="file")
+ validate_managed_id_requirement(
+ resource_id=fine_tuning_request.validation_file,
+ resource_kind="file",
+ )
response: LiteLLMFineTuningJob | None = None
if training_file:
unified_file_id = _is_base64_encoded_unified_file_id(training_file)
@@ -246,6 +252,7 @@ async def retrieve_fine_tuning_job(
try:
if premium_user is not True:
raise ValueError(f"Only premium users can use this endpoint + {CommonProxyErrors.not_premium_user.value}")
+ validate_managed_id_requirement(resource_id=fine_tuning_job_id, resource_kind="fine-tuning job")
# Include original request and headers in the data
base_llm_response_processor: Final = ProxyBaseLLMRequestProcessing(data=data)
(
@@ -513,6 +520,7 @@ async def cancel_fine_tuning_job(
try:
if premium_user is not True:
raise ValueError(f"Only premium users can use this endpoint + {CommonProxyErrors.not_premium_user.value}")
+ validate_managed_id_requirement(resource_id=fine_tuning_job_id, resource_kind="fine-tuning job")
# Include original request and headers in the data
base_llm_response_processor: Final = ProxyBaseLLMRequestProcessing(data=data)
(
diff --git a/litellm/proxy/openai_files_endpoints/common_utils.py b/litellm/proxy/openai_files_endpoints/common_utils.py
index b26010c5597..143bd5bc6b5 100644
--- a/litellm/proxy/openai_files_endpoints/common_utils.py
+++ b/litellm/proxy/openai_files_endpoints/common_utils.py
@@ -881,17 +881,20 @@ def validate_managed_files_requirement(
)
-def validate_managed_file_id_requirement(file_id: str) -> None:
+def validate_managed_id_requirement(
+ resource_id: str | None,
+ resource_kind: Literal["file", "batch", "fine-tuning job"],
+) -> None:
"""
- Enforce proxy-level managed files on the file read/delete routes when
- ``litellm.require_managed_files`` is enabled.
+ Enforce proxy-level managed resources on every route that accepts a provider-issued id
+ 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.
+ Ownership is only recorded for LiteLLM managed ids, so a raw provider id is forwarded to the
+ provider under shared credentials without any tenant check; knowing another tenant's provider
+ id would be enough to read, reuse, or destroy the object behind it.
Raises:
- HTTPException: 400 if ``file_id`` is not a LiteLLM managed file id.
+ HTTPException: 400 if ``resource_id`` is set and is not a LiteLLM managed id.
"""
from fastapi import HTTPException
@@ -900,14 +903,18 @@ def validate_managed_file_id_requirement(file_id: str) -> None:
if litellm.require_managed_files is not True:
return
- if _is_base64_encoded_unified_file_id(file_id):
+ if not resource_id:
+ return
+
+ if _is_base64_encoded_unified_file_id(resource_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."
+ f"Raw provider {resource_kind} ids cannot be used when require_managed_files is enabled in "
+ f"litellm_settings. Use the LiteLLM managed {resource_kind} id returned when the "
+ f"{resource_kind} was created."
),
)
diff --git a/litellm/proxy/openai_files_endpoints/files_endpoints.py b/litellm/proxy/openai_files_endpoints/files_endpoints.py
index 5c1a4441d0d..b5950c4f852 100644
--- a/litellm/proxy/openai_files_endpoints/files_endpoints.py
+++ b/litellm/proxy/openai_files_endpoints/files_endpoints.py
@@ -49,8 +49,8 @@ from litellm.proxy.openai_files_endpoints.common_utils import (
get_credentials_for_model,
handle_model_based_routing,
prepare_data_with_credentials,
- validate_managed_file_id_requirement,
validate_managed_files_requirement,
+ validate_managed_id_requirement,
)
from litellm.proxy.utils import ProxyLogging, is_known_model
from litellm.repositories.table_repositories import ManagedFileRepository
@@ -613,7 +613,7 @@ async def get_file_content(
data: dict = {"file_id": file_id}
try:
- validate_managed_file_id_requirement(file_id=file_id)
+ validate_managed_id_requirement(resource_id=file_id, resource_kind="file")
# Include original request and headers in the data
base_llm_response_processor: Final = ProxyBaseLLMRequestProcessing(data=data)
@@ -911,7 +911,7 @@ async def get_file(
data: dict = {"file_id": file_id}
try:
- validate_managed_file_id_requirement(file_id=file_id)
+ validate_managed_id_requirement(resource_id=file_id, resource_kind="file")
custom_llm_provider: Final = (
provider
@@ -1103,7 +1103,7 @@ async def delete_file(
data: dict = {"file_id": file_id}
try:
- validate_managed_file_id_requirement(file_id=file_id)
+ validate_managed_id_requirement(resource_id=file_id, resource_kind="file")
custom_llm_provider: Final = (
provider
diff --git a/litellm/proxy/vector_store_files_endpoints/endpoints.py b/litellm/proxy/vector_store_files_endpoints/endpoints.py
index 896b7ca33d7..f8fdf607292 100644
--- a/litellm/proxy/vector_store_files_endpoints/endpoints.py
+++ b/litellm/proxy/vector_store_files_endpoints/endpoints.py
@@ -65,6 +65,11 @@ def _update_request_data_with_managed_file_id(
is_base64_encoded_unified_id,
parse_unified_id,
)
+ from litellm.proxy.openai_files_endpoints.common_utils import (
+ validate_managed_id_requirement,
+ )
+
+ validate_managed_id_requirement(resource_id=file_id, resource_kind="file")
# First, check if this is a unified managed file ID (base64 encoded)
decoded_id: Final = is_base64_encoded_unified_id(file_id)
diff --git a/tests/test_litellm/proxy/batches_endpoints/test_endpoints.py b/tests/test_litellm/proxy/batches_endpoints/test_endpoints.py
index e758aa5ca7f..18ca604f88d 100644
--- a/tests/test_litellm/proxy/batches_endpoints/test_endpoints.py
+++ b/tests/test_litellm/proxy/batches_endpoints/test_endpoints.py
@@ -2253,3 +2253,120 @@ async def test_cancel__provider_only_resolves_named_vertex_credentials(cancel_ha
"vertex_location": "us-central1",
"vertex_credentials": "/creds/customer-sa.json",
}
+
+
+# =========================================================================== #
+# require_managed_files - raw provider ids must not reach the provider. #
+# #
+# Ownership rows only exist for LiteLLM managed ids. A raw provider id sent to #
+# these routes is forwarded under the shared provider credentials with no #
+# tenant check, so any caller who learns another tenant's id can read its #
+# batch, reuse its file as batch input, or cancel its job. These lock the #
+# guard on every batches route that accepts a caller-supplied id. #
+# =========================================================================== #
+
+
+def _unified_batch_id(model_id: str = "azure/gpt-4o", batch_id: str = "batch-provider-id") -> str:
+ import base64
+
+ from litellm.types.utils import SpecialEnums
+
+ unified = SpecialEnums.LITELLM_MANAGED_BATCH_COMPLETE_STR.value.format(model_id, batch_id)
+ return base64.urlsafe_b64encode(unified.encode()).decode().rstrip("=")
+
+
+async def test_create__raw_input_file_id_rejected_when_managed_files_required(harness):
+ set_body(
+ harness,
+ {
+ "input_file_id": "file-victim-abc123",
+ "endpoint": "/v1/chat/completions",
+ "completion_window": "24h",
+ },
+ )
+
+ with patch.object(litellm, "require_managed_files", True):
+ with pytest.raises(ProxyException) as exc:
+ await call_create(harness)
+
+ assert exc.value.code == "400"
+ harness.litellm_acreate.assert_not_called()
+ harness.router_acreate.assert_not_called()
+
+
+async def test_create__model_encoded_input_file_id_rejected_when_managed_files_required(harness):
+ """A model-encoded id is client-forgeable and has no ownership row, so it is
+ not a managed file id and must be rejected like any other raw id."""
+ set_body(
+ harness,
+ {
+ "input_file_id": AZURE_FILE_ID,
+ "endpoint": "/v1/chat/completions",
+ "completion_window": "24h",
+ },
+ )
+
+ with patch.object(litellm, "require_managed_files", True):
+ with pytest.raises(ProxyException) as exc:
+ await call_create(harness)
+
+ assert exc.value.code == "400"
+ harness.litellm_acreate.assert_not_called()
+ harness.router_acreate.assert_not_called()
+
+
+async def test_create__raw_input_file_id_allowed_when_managed_files_not_required(harness):
+ set_body(
+ harness,
+ {
+ "input_file_id": "file-victim-abc123",
+ "endpoint": "/v1/chat/completions",
+ "completion_window": "24h",
+ },
+ )
+
+ with patch.object(litellm, "require_managed_files", False):
+ await call_create(harness)
+
+ assert harness.acreate_kwargs()["input_file_id"] == "file-victim-abc123"
+
+
+async def test_retrieve__raw_batch_id_rejected_when_managed_files_required(retrieve_harness):
+ with patch.object(litellm, "require_managed_files", True):
+ with pytest.raises(ProxyException) as exc:
+ await call_retrieve(retrieve_harness, "batch-victim-abc123")
+
+ assert exc.value.code == "400"
+ retrieve_harness.litellm_aretrieve.assert_not_called()
+ retrieve_harness.router_aretrieve.assert_not_called()
+
+
+async def test_retrieve__unified_batch_id_allowed_when_managed_files_required(retrieve_harness):
+ with patch.object(litellm, "require_managed_files", True):
+ await call_retrieve(retrieve_harness, _unified_batch_id())
+
+ assert retrieve_harness.router_aretrieve.call_count == 1
+
+
+async def test_cancel__raw_batch_id_rejected_when_managed_files_required(cancel_harness):
+ with patch.object(litellm, "require_managed_files", True):
+ with pytest.raises(ProxyException) as exc:
+ await call_cancel(cancel_harness, "batch-victim-abc123")
+
+ assert exc.value.code == "400"
+ cancel_harness.litellm_acancel.assert_not_called()
+ cancel_harness.router_acancel.assert_not_called()
+
+
+async def test_cancel__unified_batch_id_allowed_when_managed_files_required(cancel_harness):
+ with patch.object(litellm, "require_managed_files", True):
+ await call_cancel(cancel_harness, _unified_batch_id())
+
+ assert cancel_harness.router_acancel.call_count == 1
diff --git a/tests/test_litellm/proxy/fine_tuning_endpoints/__init__.py b/tests/test_litellm/proxy/fine_tuning_endpoints/__init__.py
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/tests/test_litellm/proxy/fine_tuning_endpoints/test_endpoints.py b/tests/test_litellm/proxy/fine_tuning_endpoints/test_endpoints.py
new file mode 100644
index 00000000000..35c202057e7
--- /dev/null
+++ b/tests/test_litellm/proxy/fine_tuning_endpoints/test_endpoints.py
@@ -0,0 +1,236 @@
+"""
+require_managed_files enforcement for litellm/proxy/fine_tuning_endpoints/endpoints.py
+
+Ownership rows only exist for LiteLLM managed ids. A raw provider id sent to these
+routes is forwarded to the provider under the shared proxy credentials with no tenant
+check, so any caller who learns another tenant's file id can train on it, and any
+caller who learns another tenant's job id can read or cancel it.
+
+Each test asserts BOTH that the request is rejected AND that every downstream provider
+seam stayed untouched, so a guard that raises after the provider call would still fail.
+"""
+
+import base64
+import os
+import sys
+from contextlib import ExitStack
+from unittest.mock import AsyncMock, MagicMock, patch
+
+import pytest
+
+sys.path.insert(0, os.path.abspath("../../../.."))
+
+from fastapi import Response
+
+import litellm
+import litellm.proxy.fine_tuning_endpoints.endpoints as endpoints
+import litellm.proxy.proxy_server as proxy_server
+from litellm.proxy._types import ProxyException, UserAPIKeyAuth
+from litellm.proxy.common_request_processing import ProxyBaseLLMRequestProcessing
+from litellm.proxy.utils import ProxyLogging
+from litellm.router import Router
+from litellm.types.llms.openai import LiteLLMFineTuningJobCreate
+from litellm.types.utils import LiteLLMFineTuningJob, SpecialEnums
+
+RAW_FILE_ID = "file-victim-abc123"
+RAW_JOB_ID = "ftjob-victim-abc123"
+
+
+def _unified_file_id() -> str:
+ unified = SpecialEnums.LITELLM_MANAGED_FILE_COMPLETE_STR.value.format(
+ "application/json", "victim-unified-id", "gpt-4o-mini", RAW_FILE_ID, "gpt-4o-mini-id"
+ )
+ return base64.urlsafe_b64encode(unified.encode()).decode().rstrip("=")
+
+
+def _unified_job_id() -> str:
+ unified = SpecialEnums.LITELLM_MANAGED_GENERIC_RESPONSE_COMPLETE_STR.value.format("gpt-4o-mini-id", RAW_JOB_ID)
+ return base64.urlsafe_b64encode(unified.encode()).decode().rstrip("=")
+
+
+def _job() -> LiteLLMFineTuningJob:
+ job = LiteLLMFineTuningJob(
+ id=RAW_JOB_ID,
+ created_at=1234567890,
+ fine_tuned_model=None,
+ finished_at=None,
+ hyperparameters={"n_epochs": 1},
+ model="gpt-4o-mini",
+ object="fine_tuning.job",
+ organization_id="org-test",
+ result_files=[],
+ seed=0,
+ status="running",
+ trained_tokens=None,
+ training_file=RAW_FILE_ID,
+ validation_file=None,
+ )
+ job._hidden_params = {}
+ return job
+
+
+class FakeRequest:
+ def __init__(self):
+ self.headers = {}
+ self.query_params = {}
+
+ async def json(self):
+ return {}
+
+
+class Seams:
+ def __init__(self, router: MagicMock, litellm_calls: dict[str, AsyncMock]):
+ self.router = router
+ self.litellm_calls = litellm_calls
+
+ def assert_no_provider_call(self) -> None:
+ for name, mock in self.litellm_calls.items():
+ assert mock.call_count == 0, f"litellm.{name} was called"
+ for name in ("acreate_fine_tuning_job", "aretrieve_fine_tuning_job", "acancel_fine_tuning_job"):
+ assert getattr(self.router, name).call_count == 0, f"router.{name} was called"
+
+
+def seams():
+ logging = MagicMock(spec=ProxyLogging)
+ logging.post_call_success_hook = AsyncMock(side_effect=lambda **kw: kw["response"])
+ logging.post_call_failure_hook = AsyncMock()
+ logging.update_request_status = AsyncMock()
+ logging.get_proxy_hook = MagicMock(return_value=None)
+
+ router = MagicMock(spec=Router)
+ router.acreate_fine_tuning_job = AsyncMock(return_value=_job())
+ router.aretrieve_fine_tuning_job = AsyncMock(return_value=_job())
+ router.acancel_fine_tuning_job = AsyncMock(return_value=_job())
+
+ litellm_calls = {
+ name: AsyncMock(return_value=_job())
+ for name in ("acreate_fine_tuning_job", "aretrieve_fine_tuning_job", "acancel_fine_tuning_job")
+ }
+
+ with ExitStack() as stack:
+ stack.enter_context(
+ patch.object(
+ ProxyBaseLLMRequestProcessing,
+ "common_processing_pre_call_logic",
+ AsyncMock(side_effect=lambda self=None, **kw: (self.data if self else {}, MagicMock())),
+ )
+ )
+ stack.enter_context(patch.object(ProxyBaseLLMRequestProcessing, "get_custom_headers", MagicMock(return_value={})))
+ for name, mock in litellm_calls.items():
+ stack.enter_context(patch.object(litellm, name, mock))
+ stack.enter_context(patch.object(proxy_server, "llm_router", router))
+ stack.enter_context(patch.object(proxy_server, "proxy_logging_obj", logging))
+ stack.enter_context(patch.object(proxy_server, "premium_user", True))
+ stack.enter_context(patch.object(proxy_server, "general_settings", {}))
+ stack.enter_context(patch.object(proxy_server, "proxy_config", MagicMock()))
+ stack.enter_context(patch.object(proxy_server, "version", "test-version"))
+ stack.enter_context(patch.object(endpoints, "fine_tuning_config", [{"custom_llm_provider": "openai"}]))
+ yield Seams(router=router, litellm_calls=litellm_calls)
+
+
+async def _create(training_file: str, validation_file: str | None = None):
+ return await endpoints.create_fine_tuning_job(
+ request=FakeRequest(),
+ fastapi_response=Response(),
+ fine_tuning_request=LiteLLMFineTuningJobCreate(
+ model="gpt-4o-mini",
+ training_file=training_file,
+ validation_file=validation_file,
+ custom_llm_provider="openai",
+ ),
+ user_api_key_dict=UserAPIKeyAuth(api_key="sk-test"),
+ )
+
+
+async def _retrieve(job_id: str):
+ return await endpoints.retrieve_fine_tuning_job(
+ request=FakeRequest(),
+ fastapi_response=Response(),
+ fine_tuning_job_id=job_id,
+ custom_llm_provider="openai",
+ user_api_key_dict=UserAPIKeyAuth(api_key="sk-test"),
+ )
+
+
+async def _cancel(job_id: str):
+ return await endpoints.cancel_fine_tuning_job(
+ request=FakeRequest(),
+ fastapi_response=Response(),
+ fine_tuning_job_id=job_id,
+ user_api_key_dict=UserAPIKeyAuth(api_key="sk-test"),
+ )
+
+
+async def test_create__raw_training_file_rejected_when_managed_files_required(seams):
+ with patch.object(litellm, "require_managed_files", True):
+ with pytest.raises(ProxyException) as exc:
+ await _create(RAW_FILE_ID)
+
+ assert exc.value.code == "400"
+ seams.assert_no_provider_call()
+
+
+async def test_create__raw_validation_file_rejected_when_managed_files_required(seams):
+ """The validation file is uploaded and readable exactly like the training file,
+ so a managed training_file must not smuggle a raw validation_file past the guard."""
+ with patch.object(litellm, "require_managed_files", True):
+ with pytest.raises(ProxyException) as exc:
+ await _create(_unified_file_id(), validation_file=RAW_FILE_ID)
+
+ assert exc.value.code == "400"
+ seams.assert_no_provider_call()
+
+
+async def test_create__unified_training_file_allowed_when_managed_files_required(seams):
+ with patch.object(litellm, "require_managed_files", True):
+ await _create(_unified_file_id())
+
+ assert seams.router.acreate_fine_tuning_job.call_count == 1
+
+
+async def test_create__raw_training_file_allowed_when_managed_files_not_required(seams):
+ with patch.object(litellm, "require_managed_files", False):
+ await _create(RAW_FILE_ID)
+
+ assert seams.litellm_calls["acreate_fine_tuning_job"].call_count == 1
+
+
+async def test_retrieve__raw_job_id_rejected_when_managed_files_required(seams):
+ with patch.object(litellm, "require_managed_files", True):
+ with pytest.raises(ProxyException) as exc:
+ await _retrieve(RAW_JOB_ID)
+
+ assert exc.value.code == "400"
+ seams.assert_no_provider_call()
+
+
+async def test_retrieve__unified_job_id_allowed_when_managed_files_required(seams):
+ with patch.object(litellm, "require_managed_files", True):
+ await _retrieve(_unified_job_id())
+
+ assert seams.router.aretrieve_fine_tuning_job.call_count == 1
+
+
+async def test_cancel__raw_job_id_rejected_when_managed_files_required(seams):
+ with patch.object(litellm, "require_managed_files", True):
+ with pytest.raises(ProxyException) as exc:
+ await _cancel(RAW_JOB_ID)
+
+ assert exc.value.code == "400"
+ seams.assert_no_provider_call()
+
+
+async def test_cancel__unified_job_id_allowed_when_managed_files_required(seams):
+ with patch.object(litellm, "require_managed_files", True):
+ await _cancel(_unified_job_id())
+
+ assert seams.router.acancel_fine_tuning_job.call_count == 1
diff --git a/tests/test_litellm/proxy/openai_files_endpoint/test_files_endpoint.py b/tests/test_litellm/proxy/openai_files_endpoint/test_files_endpoint.py
index 24b814bae1f..2e15da7590a 100644
--- a/tests/test_litellm/proxy/openai_files_endpoint/test_files_endpoint.py
+++ b/tests/test_litellm/proxy/openai_files_endpoint/test_files_endpoint.py
@@ -3109,22 +3109,22 @@ def _unified_managed_file_id() -> str:
def test_require_managed_files_allows_unified_managed_file_id(monkeypatch):
from litellm.proxy.openai_files_endpoints.common_utils import (
- validate_managed_file_id_requirement,
+ validate_managed_id_requirement,
)
monkeypatch.setattr("litellm.require_managed_files", True)
- validate_managed_file_id_requirement(file_id=_unified_managed_file_id())
+ validate_managed_id_requirement(resource_id=_unified_managed_file_id(), resource_kind="file")
def test_managed_file_id_requirement_is_opt_in(monkeypatch):
from litellm.proxy.openai_files_endpoints.common_utils import (
- validate_managed_file_id_requirement,
+ validate_managed_id_requirement,
)
monkeypatch.setattr("litellm.require_managed_files", False)
- validate_managed_file_id_requirement(file_id="file-victim-abc123")
+ validate_managed_id_requirement(resource_id="file-victim-abc123", resource_kind="file")
def test_raw_provider_file_id_retrieve_allowed_when_managed_files_not_required(
diff --git a/tests/test_litellm/proxy/vector_store_files_endpoints/__init__.py b/tests/test_litellm/proxy/vector_store_files_endpoints/__init__.py
new file mode 100644
index 00000000000..e69de29bb2d
diff --git a/tests/test_litellm/proxy/vector_store_files_endpoints/test_endpoints.py b/tests/test_litellm/proxy/vector_store_files_endpoints/test_endpoints.py
new file mode 100644
index 00000000000..c2bdb1d80f2
--- /dev/null
+++ b/tests/test_litellm/proxy/vector_store_files_endpoints/test_endpoints.py
@@ -0,0 +1,83 @@
+"""
+require_managed_files enforcement for litellm/proxy/vector_store_files_endpoints/endpoints.py
+
+Every vector-store file route (create, retrieve, content, update, delete) resolves its
+caller-supplied file id through _update_request_data_with_managed_file_id before the
+provider call, so the guard lives there once and covers all five.
+
+A raw provider file id has no ownership row, so without the guard it is attached to a
+vector store or read back under the shared provider credentials with no tenant check.
+"""
+
+import base64
+import os
+import sys
+from unittest.mock import MagicMock, patch
+
+import pytest
+
+sys.path.insert(0, os.path.abspath("../../../.."))
+
+from fastapi import HTTPException
+
+import litellm
+from litellm.proxy.vector_store_files_endpoints.endpoints import (
+ _update_request_data_with_managed_file_id,
+)
+from litellm.types.utils import SpecialEnums
+
+RAW_FILE_ID = "file-victim-abc123"
+
+
+def _unified_file_id() -> str:
+ unified = SpecialEnums.LITELLM_MANAGED_FILE_COMPLETE_STR.value.format(
+ "application/json", "victim-unified-id", "gpt-4o-mini", RAW_FILE_ID, "gpt-4o-mini-id"
+ )
+ return base64.urlsafe_b64encode(unified.encode()).decode().rstrip("=")
+
+
+def _resolve(file_id: str):
+ return _update_request_data_with_managed_file_id(
+ data={"vector_store_id": "vs-test", "file_id": file_id},
+ file_id=file_id,
+ request=MagicMock(headers={}, query_params={}),
+ llm_router=None,
+ )
+
+
+def test_raw_file_id_rejected_when_managed_files_required():
+ with patch.object(litellm, "require_managed_files", True):
+ with pytest.raises(HTTPException) as exc:
+ _resolve(RAW_FILE_ID)
+
+ assert exc.value.status_code == 400
+
+
+def test_model_encoded_file_id_rejected_when_managed_files_required():
+ """encode_file_id_with_model output is client-forgeable and carries no ownership
+ row, so it is not a managed file id."""
+ from litellm.proxy.openai_files_endpoints.common_utils import encode_file_id_with_model
+
+ encoded = encode_file_id_with_model(RAW_FILE_ID, "gpt-4o-mini", id_type="file")
+
+ with patch.object(litellm, "require_managed_files", True):
+ with pytest.raises(HTTPException) as exc:
+ _resolve(encoded)
+
+ assert exc.value.status_code == 400
+
+
+def test_unified_file_id_allowed_when_managed_files_required():
+ with patch.object(litellm, "require_managed_files", True):
+ data, original = _resolve(_unified_file_id())
+
+ assert original == _unified_file_id()
+ assert data["file_id"] == RAW_FILE_ID
+
+
+def test_raw_file_id_allowed_when_managed_files_not_required():
+ with patch.object(litellm, "require_managed_files", False):
+ data, original = _resolve(RAW_FILE_ID)
+
+ assert original is None
+ assert data["file_id"] == RAW_FILE_ID