fix(proxy): stop /{provider}/v1/files from capturing /anthropic passthrough

The native files and batches routers mount before the passthrough router, so
/anthropic/v1/files matched /{provider}/v1/files with provider="anthropic" and
422'd on the OpenAI-only `purpose` field instead of forwarding to Anthropic's
Files API. Give /anthropic its own router mounted ahead of batches and files,
mirroring the fix already applied to /openai_passthrough in #36092.
This commit is contained in:
chelsealong 2026-08-19 02:00:45 +00:00
parent 41de13aa0c
commit 75fbc4b481
3 changed files with 24 additions and 1 deletions

View file

@ -63,6 +63,7 @@ from .passthrough_endpoint_router import PassthroughEndpointRouter
vertex_llm_base: Final = VertexBase()
router: Final = APIRouter()
openai_passthrough_router: Final = APIRouter()
anthropic_passthrough_router: Final = APIRouter()
default_vertex_config: Final = None
passthrough_endpoint_router: Final = PassthroughEndpointRouter()
@ -563,7 +564,7 @@ async def is_streaming_request_fn(request: Request) -> bool:
return False
@router.api_route(
@anthropic_passthrough_router.api_route(
"/anthropic/{endpoint:path}",
methods=["GET", "POST", "PUT", "DELETE", "PATCH"],
tags=["Anthropic Pass-through", "pass-through"],

View file

@ -560,6 +560,7 @@ from litellm.proxy.openai_files_endpoints.files_endpoints import (
set_files_config,
)
from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
anthropic_passthrough_router,
openai_passthrough_router,
passthrough_endpoint_router,
vertex_ai_live_websocket_passthrough,
@ -17280,6 +17281,7 @@ 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(anthropic_passthrough_router)
app.include_router(batches_router)
app.include_router(openai_files_router)
app.include_router(llm_passthrough_router)

View file

@ -2990,6 +2990,26 @@ def test_native_provider_routes_are_unchanged(method, path, expected_name):
assert _resolve_route_name(method, path) == expected_name
@pytest.mark.parametrize(
"method, path",
[
("POST", "/anthropic/v1/files"),
("GET", "/anthropic/v1/files"),
("GET", "/anthropic/v1/files/file-abc123"),
("DELETE", "/anthropic/v1/files/file-abc123"),
("POST", "/anthropic/v1/batches"),
("POST", "/anthropic/v1/messages"),
],
)
def test_anthropic_passthrough_prefix_wins_over_native_provider_routes(method, path):
"""
Anthropic's Files API has no `purpose` field and no `files_settings` config,
so the native /{provider}/v1/files and /{provider}/v1/batches routes must never
capture /anthropic/... with provider="anthropic".
"""
assert _resolve_route_name(method, path) == "anthropic_proxy_route"
class TestCursorProxyRoute:
"""Tests for the Cursor Cloud Agents pass-through route."""