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]

test fixes for mapped tests

Ishaan Jaffered5c9f1c693b
diff --git a/tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py b/tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py
index 069896e9fb4..662064a1afc 100644
--- a/tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py
+++ b/tests/test_litellm/proxy/spend_tracking/test_spend_management_endpoints.py
@@ -32,6 +32,7 @@ ignored_keys = [
"metadata.model_map_information",
"metadata.usage_object",
"metadata.cold_storage_object_key",
+ "metadata.additional_usage_values.prompt_tokens_details.cache_creation_tokens",
]
MODEL_LIST = [
diff --git a/tests/test_litellm/proxy/spend_tracking/test_spend_tracking_utils.py b/tests/test_litellm/proxy/spend_tracking/test_spend_tracking_utils.py
index eac631bdb0d..10d13ca3ee8 100644
--- a/tests/test_litellm/proxy/spend_tracking/test_spend_tracking_utils.py
+++ b/tests/test_litellm/proxy/spend_tracking/test_spend_tracking_utils.py
@@ -32,10 +32,28 @@ def test_sanitize_request_body_for_spend_logs_payload_basic():
def test_sanitize_request_body_for_spend_logs_payload_long_string():
- long_string = "a" * 2000 # Create a string longer than MAX_STRING_LENGTH
+ from litellm.constants import MAX_STRING_LENGTH_PROMPT_IN_DB
+
+ # Create a string longer than MAX_STRING_LENGTH_PROMPT_IN_DB (2048)
+ long_string = "a" * 3000 # Create a string longer than MAX_STRING_LENGTH_PROMPT_IN_DB
request_body = {"text": long_string, "normal_text": "short text"}
sanitized = _sanitize_request_body_for_spend_logs_payload(request_body)
- assert len(sanitized["text"]) == 1000 + len(f"... ({LITELLM_TRUNCATED_PAYLOAD_FIELD} 1000 chars)")
+
+ # Calculate expected lengths: 35% start + 65% end + truncation message
+ start_chars = int(MAX_STRING_LENGTH_PROMPT_IN_DB * 0.35)
+ end_chars = int(MAX_STRING_LENGTH_PROMPT_IN_DB * 0.65)
+ total_keep = start_chars + end_chars
+ if total_keep > MAX_STRING_LENGTH_PROMPT_IN_DB:
+ end_chars = MAX_STRING_LENGTH_PROMPT_IN_DB - start_chars
+
+ skipped_chars = len(long_string) - (start_chars + end_chars)
+ expected_truncation_message = f"... ({LITELLM_TRUNCATED_PAYLOAD_FIELD} skipped {skipped_chars} chars) ..."
+ expected_length = start_chars + len(expected_truncation_message) + end_chars
+
+ assert len(sanitized["text"]) == expected_length
+ assert sanitized["text"].startswith("a" * start_chars)
+ assert sanitized["text"].endswith("a" * end_chars)
+ assert expected_truncation_message in sanitized["text"]
assert sanitized["normal_text"] == "short text"