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 ttl tests

Otavio Britob2a734c1f867
diff --git a/docs/my-website/docs/providers/vertex.md b/docs/my-website/docs/providers/vertex.md
index e4a9c1b6b80..3d8e7818ff3 100644
--- a/docs/my-website/docs/providers/vertex.md
+++ b/docs/my-website/docs/providers/vertex.md
@@ -933,7 +933,7 @@ curl -X POST 'http://0.0.0.0:4000/chat/completions' \
"content": [
{
"type": "text",
- "text": "Long cache message (must be >= 1025 tokens)",
+ "text": "Long cache message (must be >= 1024 tokens)",
"cache_control": {
"type": "ephemeral",
"ttl": "7200s"
diff --git a/tests/test_litellm/llms/vertex_ai/context_caching/test_context_caching_ttl.py b/tests/test_litellm/llms/vertex_ai/context_caching/test_context_caching_ttl.py
index cce6055ab3f..f230d814ae6 100644
--- a/tests/test_litellm/llms/vertex_ai/context_caching/test_context_caching_ttl.py
+++ b/tests/test_litellm/llms/vertex_ai/context_caching/test_context_caching_ttl.py
@@ -191,7 +191,8 @@ class TestTTLExtraction:
class TestTransformationWithTTL:
"""Test the complete transformation with TTL support"""
- def test_transform_with_valid_ttl(self):
+ @pytest.mark.parametrize("custom_llm_provider", ["gemini", "vertex_ai", "vertex_ai_beta"])
+ def test_transform_with_valid_ttl(self, custom_llm_provider):
"""Test transformation includes TTL when provided"""
messages = [
{
@@ -205,19 +206,32 @@ class TestTransformationWithTTL:
]
}
]
+
+ vertex_location="test_location"
+ vertex_project="test_project"
result = transform_openai_messages_to_gemini_context_caching(
model="gemini-1.5-pro",
messages=messages,
- cache_key="test-cache-key"
+ cache_key="test-cache-key",
+ custom_llm_provider=custom_llm_provider,
+ vertex_location="test_location",
+ vertex_project="test_project"
)
assert "ttl" in result
assert result["ttl"] == "3600s"
- assert result["model"] == "models/gemini-1.5-pro"
+
+ if custom_llm_provider == "gemini":
+ assert result["model"] == "models/gemini-1.5-pro"
+ else:
+ assert result["model"] == f"projects/{vertex_project}/locations/{vertex_location}/publishers/google/models/gemini-1.5-pro"
+
+
assert result["displayName"] == "test-cache-key"
- def test_transform_without_ttl(self):
+ @pytest.mark.parametrize("custom_llm_provider", ["gemini", "vertex_ai", "vertex_ai_beta"])
+ def test_transform_without_ttl(self, custom_llm_provider):
"""Test transformation without TTL"""
messages = [
{
@@ -231,18 +245,30 @@ class TestTransformationWithTTL:
]
}
]
+
+ vertex_location="test_location"
+ vertex_project="test_project"
result = transform_openai_messages_to_gemini_context_caching(
model="gemini-1.5-pro",
messages=messages,
- cache_key="test-cache-key"
+ cache_key="test-cache-key",
+ custom_llm_provider=custom_llm_provider,
+ vertex_location=vertex_location,
+ vertex_project=vertex_project
)
assert "ttl" not in result
- assert result["model"] == "models/gemini-1.5-pro"
+
+ if custom_llm_provider == "gemini":
+ assert result["model"] == "models/gemini-1.5-pro"
+ else:
+ assert result["model"] == f"projects/{vertex_project}/locations/{vertex_location}/publishers/google/models/gemini-1.5-pro"
+
assert result["displayName"] == "test-cache-key"
- def test_transform_with_invalid_ttl(self):
+ @pytest.mark.parametrize("custom_llm_provider", ["gemini", "vertex_ai", "vertex_ai_beta"])
+ def test_transform_with_invalid_ttl(self, custom_llm_provider):
"""Test transformation with invalid TTL (should be ignored)"""
messages = [
{
@@ -256,18 +282,29 @@ class TestTransformationWithTTL:
]
}
]
+ vertex_location="test_location"
+ vertex_project="test_project"
result = transform_openai_messages_to_gemini_context_caching(
model="gemini-1.5-pro",
messages=messages,
- cache_key="test-cache-key"
+ cache_key="test-cache-key",
+ custom_llm_provider=custom_llm_provider,
+ vertex_location=vertex_location,
+ vertex_project=vertex_project
)
assert "ttl" not in result
- assert result["model"] == "models/gemini-1.5-pro"
+
+ if custom_llm_provider == "gemini":
+ assert result["model"] == "models/gemini-1.5-pro"
+ else:
+ assert result["model"] == f"projects/{vertex_project}/locations/{vertex_location}/publishers/google/models/gemini-1.5-pro"
+
assert result["displayName"] == "test-cache-key"
- def test_transform_with_system_message_and_ttl(self):
+ @pytest.mark.parametrize("custom_llm_provider", ["gemini", "vertex_ai", "vertex_ai_beta"])
+ def test_transform_with_system_message_and_ttl(self, custom_llm_provider):
"""Test transformation with system message and TTL"""
messages = [
{
@@ -290,17 +327,28 @@ class TestTransformationWithTTL:
]
}
]
+
+ vertex_location="test_location"
+ vertex_project="test_project"
result = transform_openai_messages_to_gemini_context_caching(
model="gemini-1.5-pro",
messages=messages,
- cache_key="test-cache-key"
+ cache_key="test-cache-key",
+ custom_llm_provider=custom_llm_provider,
+ vertex_location=vertex_location,
+ vertex_project=vertex_project
)
assert "ttl" in result
assert result["ttl"] == "7200s"
assert "system_instruction" in result
- assert result["model"] == "models/gemini-1.5-pro"
+
+ if custom_llm_provider == "gemini":
+ assert result["model"] == "models/gemini-1.5-pro"
+ else:
+ assert result["model"] == f"projects/{vertex_project}/locations/{vertex_location}/publishers/google/models/gemini-1.5-pro"
+
assert result["displayName"] == "test-cache-key"