mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-11 22:51:28 +00:00
Fix: Add /v1/messages/count_tokens to Anthropic routes for non-admin user access (#15034)
* Initial plan * Fix: Add /v1/messages/count_tokens to Anthropic routes for user access Co-authored-by: ishaan-jaff <29436595+ishaan-jaff@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: ishaan-jaff <29436595+ishaan-jaff@users.noreply.github.com>
This commit is contained in:
parent
ebf72f5eb9
commit
f22fd4cddd
2 changed files with 20 additions and 0 deletions
|
|
@ -330,6 +330,7 @@ class LiteLLMRoutes(enum.Enum):
|
|||
|
||||
anthropic_routes = [
|
||||
"/v1/messages",
|
||||
"/v1/messages/count_tokens",
|
||||
]
|
||||
|
||||
mcp_routes = [
|
||||
|
|
|
|||
|
|
@ -228,3 +228,22 @@ def test_virtual_key_allowed_routes_with_no_member_names_only_explicit():
|
|||
)
|
||||
|
||||
assert "Virtual key is not allowed to call this route" in str(exc_info.value)
|
||||
|
||||
|
||||
def test_anthropic_count_tokens_route_is_llm_api_route():
|
||||
"""Test that /v1/messages/count_tokens is recognized as an LLM API route for Anthropic"""
|
||||
|
||||
# Test the core anthropic routes
|
||||
assert RouteChecks.is_llm_api_route("/v1/messages") is True
|
||||
assert RouteChecks.is_llm_api_route("/v1/messages/count_tokens") is True
|
||||
|
||||
|
||||
def test_anthropic_count_tokens_route_accessible_to_internal_users():
|
||||
"""Test that internal users can access the Anthropic count_tokens route"""
|
||||
|
||||
# Test that the route is recognized as an LLM API route (which means it's accessible to internal users)
|
||||
# This is the core check that was failing in the original issue
|
||||
assert RouteChecks.is_llm_api_route("/v1/messages/count_tokens") is True
|
||||
|
||||
# Also test that the regular messages route still works
|
||||
assert RouteChecks.is_llm_api_route("/v1/messages") is True
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue