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): stop /{provider}/v1/files from capturing /openai_passthrough

Devin AI5a5bb8c9d844
diff --git a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py
index 38da00a3bb9..baa74c19182 100644
--- a/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py
+++ b/litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py
@@ -60,6 +60,7 @@ from .passthrough_endpoint_router import PassthroughEndpointRouter
vertex_llm_base: Final = VertexBase()
router: Final = APIRouter()
+openai_passthrough_router: Final = APIRouter()
default_vertex_config: Final = None
passthrough_endpoint_router: Final = PassthroughEndpointRouter()
@@ -1875,7 +1876,7 @@ async def vertex_proxy_route(
)
+@openai_passthrough_router.api_route(
"/openai_passthrough/{endpoint:path}",
methods=["GET", "POST", "PUT", "DELETE", "PATCH"],
tags=["OpenAI Pass-through", "pass-through"],
diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py
index fb9c4e67aad..e75277e7f0a 100644
--- a/litellm/proxy/proxy_server.py
+++ b/litellm/proxy/proxy_server.py
@@ -522,6 +522,7 @@ from litellm.proxy.openai_files_endpoints.files_endpoints import (
set_files_config,
)
from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
+ openai_passthrough_router,
passthrough_endpoint_router,
vertex_ai_live_websocket_passthrough,
)
@@ -16433,6 +16434,7 @@ app.include_router(search_router)
app.include_router(image_router)
app.include_router(fine_tuning_router)
app.include_router(credential_router)
+app.include_router(openai_passthrough_router)
app.include_router(batches_router)
app.include_router(openai_files_router)
app.include_router(llm_passthrough_router)
diff --git a/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py b/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py
index 181846fe289..27d6e4c8585 100644
--- a/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py
+++ b/tests/test_litellm/proxy/pass_through_endpoints/test_llm_pass_through_endpoints.py
@@ -2814,6 +2814,63 @@ class TestOpenAIPassthroughRoute:
assert result == {"id": "asst_123", "object": "assistant"}
+def _resolve_route_name(method: str, path: str) -> str | None:
+ from starlette.routing import Match
+
+ from litellm.proxy.proxy_server import app
+
+ scope = {
+ "type": "http",
+ "method": method,
+ "path": path,
+ "headers": [],
+ "query_string": b"",
+ "root_path": "",
+ }
+ for route in app.router.routes:
+ if route.matches(scope)[0] == Match.FULL:
+ return getattr(route, "name", None)
+ return None
+
+
+ "method, path",
+ [
+ ("POST", "/openai_passthrough/v1/files"),
+ ("GET", "/openai_passthrough/v1/files"),
+ ("GET", "/openai_passthrough/v1/files/file-abc123"),
+ ("DELETE", "/openai_passthrough/v1/files/file-abc123"),
+ ("GET", "/openai_passthrough/v1/files/file-abc123/content"),
+ ("POST", "/openai_passthrough/v1/batches"),
+ ("GET", "/openai_passthrough/v1/batches"),
+ ("GET", "/openai_passthrough/v1/batches/batch_abc123"),
+ ("POST", "/openai_passthrough/v1/batches/batch_abc123/cancel"),
+ ("POST", "/openai_passthrough/v1/responses"),
+ ],
+)
+def test_openai_passthrough_prefix_wins_over_native_provider_routes(method, path):
+ """
+ /openai_passthrough exists to guarantee passthrough, so the native
+ /{provider}/v1/files and /{provider}/v1/batches routes must never capture it
+ with provider="openai_passthrough" (which 500s on the LlmProviders lookup).
+ """
+ assert _resolve_route_name(method, path) == "openai_proxy_route"
+
+
+ "method, path, expected_name",
+ [
+ ("POST", "/openai/v1/files", "create_file"),
+ ("GET", "/azure/v1/files", "list_files"),
+ ("POST", "/v1/files", "create_file"),
+ ("POST", "/v1/batches", "create_batch"),
+ ("POST", "/openai/v1/chat/completions", "openai_proxy_route"),
+ ],
+)
+def test_native_provider_routes_are_unchanged(method, path, expected_name):
+ assert _resolve_route_name(method, path) == expected_name
+
+
class TestCursorProxyRoute:
"""Tests for the Cursor Cloud Agents pass-through route."""