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]

fixes: expose flag to disable token counter (#11344)

Ishaan Jaffa73cf185ac1b
diff --git a/litellm/__init__.py b/litellm/__init__.py
index 1cdeb0d6ab4..38f332b41e7 100644
--- a/litellm/__init__.py
+++ b/litellm/__init__.py
@@ -217,6 +217,7 @@ use_client: bool = False
ssl_verify: Union[str, bool] = True
ssl_certificate: Optional[str] = None
disable_streaming_logging: bool = False
+disable_token_counter: bool = False
disable_add_transform_inline_image_block: bool = False
in_memory_llm_clients_cache: LLMClientCache = LLMClientCache()
safe_memory_mode: bool = False
diff --git a/litellm/litellm_core_utils/token_counter.py b/litellm/litellm_core_utils/token_counter.py
index e72700efac9..737784bed8e 100644
--- a/litellm/litellm_core_utils/token_counter.py
+++ b/litellm/litellm_core_utils/token_counter.py
@@ -362,6 +362,15 @@ def token_counter(
"""
from litellm.utils import convert_list_message_to_dict
+ #########################################################
+ # Flag to disable token counter
+ # We've gotten reports of this consuming CPU cycles,
+ # exposing this flag to allow users to disable
+ # it to confirm if this is indeed the issue
+ #########################################################
+ if litellm.disable_token_counter is True:
+ return 0
+
verbose_logger.debug(
f"messages in token_counter: {messages}, text in token_counter: {text}"
)
diff --git a/litellm/proxy/proxy_config.yaml b/litellm/proxy/proxy_config.yaml
index 25e31f108fd..42d7297218f 100644
--- a/litellm/proxy/proxy_config.yaml
+++ b/litellm/proxy/proxy_config.yaml
@@ -4,6 +4,5 @@ model_list:
model: openai/*
-
-
-
+litellm_settings:
+ disable_token_counter: True
diff --git a/litellm/utils.py b/litellm/utils.py
index 63a01f3ad59..d80be1900fb 100644
--- a/litellm/utils.py
+++ b/litellm/utils.py
@@ -1697,6 +1697,16 @@ def token_counter(
Kept for backwards compatibility.
"""
+
+ #########################################################
+ # Flag to disable token counter
+ # We've gotten reports of this consuming CPU cycles,
+ # exposing this flag to allow users to disable
+ # it to confirm if this is indeed the issue
+ #########################################################
+ if litellm.disable_token_counter is True:
+ return 0
+
return token_counter_new(
model,
custom_tokenizer,