Skip to content

Commit a7d5536

Browse files
authored
(fix) passthrough - allow internal users to access /anthropic (#6843)
* fix /anthropic/ * test llm_passthrough_router * fix test_gemini_pass_through_endpoint
1 parent 50d2510 commit a7d5536

File tree

5 files changed

+22
-8
lines changed

5 files changed

+22
-8
lines changed

litellm/proxy/auth/route_checks.py

+4
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ def is_llm_api_route(route: str) -> bool:
192192
return True
193193
if "/langfuse/" in route:
194194
return True
195+
if "/anthropic/" in route:
196+
return True
197+
if "/azure/" in route:
198+
return True
195199
return False
196200

197201
@staticmethod

litellm/proxy/vertex_ai_endpoints/google_ai_studio_endpoints.py renamed to litellm/proxy/pass_through_endpoints/llm_passthrough_endpoints.py

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
What is this?
33
44
Provider-specific Pass-Through Endpoints
5-
"""
65
7-
"""
8-
1. Create pass-through endpoints for any LITELLM_BASE_URL/gemini/<endpoint> map to https://generativelanguage.googleapis.com/<endpoint>
6+
Use litellm with Anthropic SDK, Vertex AI SDK, Cohere SDK, etc.
97
"""
108

119
import ast

litellm/proxy/proxy_server.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,9 @@ def generate_feedback_box():
203203
router as openai_files_router,
204204
)
205205
from litellm.proxy.openai_files_endpoints.files_endpoints import set_files_config
206+
from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
207+
router as llm_passthrough_router,
208+
)
206209
from litellm.proxy.pass_through_endpoints.pass_through_endpoints import (
207210
initialize_pass_through_endpoints,
208211
)
@@ -233,9 +236,6 @@ def generate_feedback_box():
233236
reset_budget,
234237
update_spend,
235238
)
236-
from litellm.proxy.vertex_ai_endpoints.google_ai_studio_endpoints import (
237-
router as gemini_router,
238-
)
239239
from litellm.proxy.vertex_ai_endpoints.langfuse_endpoints import (
240240
router as langfuse_router,
241241
)
@@ -9128,7 +9128,7 @@ def cleanup_router_config_variables():
91289128
app.include_router(rerank_router)
91299129
app.include_router(fine_tuning_router)
91309130
app.include_router(vertex_router)
9131-
app.include_router(gemini_router)
9131+
app.include_router(llm_passthrough_router)
91329132
app.include_router(langfuse_router)
91339133
app.include_router(pass_through_router)
91349134
app.include_router(health_router)

tests/proxy_admin_ui_tests/test_route_check_unit_tests.py

+12
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
import pytest
2828
from litellm.proxy.auth.route_checks import RouteChecks
2929
from litellm.proxy._types import LiteLLM_UserTable, LitellmUserRoles, UserAPIKeyAuth
30+
from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
31+
router as llm_passthrough_router,
32+
)
3033

3134
# Replace the actual hash_token function with our mock
3235
import litellm.proxy.auth.route_checks
@@ -56,12 +59,21 @@ def test_is_llm_api_route():
5659
assert RouteChecks.is_llm_api_route("/vertex-ai/text") is True
5760
assert RouteChecks.is_llm_api_route("/gemini/generate") is True
5861
assert RouteChecks.is_llm_api_route("/cohere/generate") is True
62+
assert RouteChecks.is_llm_api_route("/anthropic/messages") is True
63+
assert RouteChecks.is_llm_api_route("/anthropic/v1/messages") is True
64+
assert RouteChecks.is_llm_api_route("/azure/endpoint") is True
5965

6066
# check non-matching routes
6167
assert RouteChecks.is_llm_api_route("/some/random/route") is False
6268
assert RouteChecks.is_llm_api_route("/key/regenerate/82akk800000000jjsk") is False
6369
assert RouteChecks.is_llm_api_route("/key/82akk800000000jjsk/delete") is False
6470

71+
# check all routes in llm_passthrough_router, ensure they are considered llm api routes
72+
for route in llm_passthrough_router.routes:
73+
route_path = str(route.path)
74+
print("route_path", route_path)
75+
assert RouteChecks.is_llm_api_route(route_path) is True
76+
6577

6678
# Test _route_matches_pattern
6779
def test_route_matches_pattern():

tests/proxy_unit_tests/test_proxy_server.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1794,7 +1794,7 @@ async def test_add_callback_via_key_litellm_pre_call_utils_langsmith(
17941794
async def test_gemini_pass_through_endpoint():
17951795
from starlette.datastructures import URL
17961796

1797-
from litellm.proxy.vertex_ai_endpoints.google_ai_studio_endpoints import (
1797+
from litellm.proxy.pass_through_endpoints.llm_passthrough_endpoints import (
17981798
Request,
17991799
Response,
18001800
gemini_proxy_route,

0 commit comments

Comments
 (0)