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: Add /v1/messages/count_tokens to Anthropic routes for non-admin user access (#15034)

Copilotf22fd4cddd77
diff --git a/litellm/proxy/_types.py b/litellm/proxy/_types.py
index c5b4ee0753e..c5370eb7d70 100644
--- a/litellm/proxy/_types.py
+++ b/litellm/proxy/_types.py
@@ -330,6 +330,7 @@ class LiteLLMRoutes(enum.Enum):
anthropic_routes = [
"/v1/messages",
+ "/v1/messages/count_tokens",
]
mcp_routes = [
diff --git a/tests/test_litellm/proxy/auth/test_route_checks.py b/tests/test_litellm/proxy/auth/test_route_checks.py
index ac09917e4cd..539ee4a9ba8 100644
--- a/tests/test_litellm/proxy/auth/test_route_checks.py
+++ b/tests/test_litellm/proxy/auth/test_route_checks.py
@@ -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