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]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fixes: expose flag to disable token counter (#11344)
Ishaan Jaffa73cf185ac1b
diff --git a/litellm/__init__.py b/litellm/__init__.pyindex 1cdeb0d6ab4..38f332b41e7 100644--- a/litellm/__init__.py+++ b/litellm/__init__.py@@ -217,6 +217,7 @@ use_client: bool = Falsessl_verify: Union[str, bool] = Truessl_certificate: Optional[str] = Nonedisable_streaming_logging: bool = False+disable_token_counter: bool = Falsedisable_add_transform_inline_image_block: bool = Falsein_memory_llm_clients_cache: LLMClientCache = LLMClientCache()safe_memory_mode: bool = Falsediff --git a/litellm/litellm_core_utils/token_counter.py b/litellm/litellm_core_utils/token_counter.pyindex 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.yamlindex 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: Truediff --git a/litellm/utils.py b/litellm/utils.pyindex 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,