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
fix: use chat format in tools test, include tools/system in local fallback
Chesarsabc381cfe2ad
diff --git a/litellm/main.py b/litellm/main.pyindex e70055a90a3..8be923685ab 100644--- a/litellm/main.py+++ b/litellm/main.py@@ -7617,9 +7617,13 @@ async def acount_tokens()# Fallback to local tiktoken-based token counting+ fallback_messages = messages or []+ if system and fallback_messages:+ fallback_messages = [{"role": "system", "content": system}] + fallback_messageslocal_count = litellm.token_counter(model=model,- messages=messages or [],+ messages=fallback_messages,+ tools=tools,)return TokenCountResponse(diff --git a/tests/test_litellm/test_count_tokens_public_api.py b/tests/test_litellm/test_count_tokens_public_api.pyindex 59a1092455c..81ba244796d 100644--- a/tests/test_litellm/test_count_tokens_public_api.py+++ b/tests/test_litellm/test_count_tokens_public_api.py@@ -71,9 +71,11 @@ def test_acount_tokens_with_tools():tools = [{"type": "function",- "name": "get_weather",- "description": "Get weather info",- "parameters": {"type": "object", "properties": {"city": {"type": "string"}}},+ "function": {+ "name": "get_weather",+ "description": "Get weather info",+ "parameters": {"type": "object", "properties": {"city": {"type": "string"}}},+ },}]