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: document gemini file URI handling

userdc3e0739fbaf
diff --git a/litellm/litellm_core_utils/url_utils.py b/litellm/litellm_core_utils/url_utils.py
index fca157fce6d..a8720282afd 100644
--- a/litellm/litellm_core_utils/url_utils.py
+++ b/litellm/litellm_core_utils/url_utils.py
@@ -67,7 +67,11 @@ def encode_url_path_segment(value: Any, *, field_name: str = "path parameter") -
def encode_url_path_segments(value: Any, *, field_name: str = "path") -> str:
- """Percent-encode a user-controlled URL path made of multiple segments."""
+ """Percent-encode a user-controlled URL path made of multiple segments.
+
+ Empty segments are rejected, so leading, trailing, or consecutive slashes
+ fail closed instead of being normalized by the HTTP client.
+ """
if value is None:
raise ValueError(f"{field_name} is required")
diff --git a/tests/test_litellm/llms/gemini/files/test_gemini_files_transformation.py b/tests/test_litellm/llms/gemini/files/test_gemini_files_transformation.py
index d262b3b96d8..a2f95724688 100644
--- a/tests/test_litellm/llms/gemini/files/test_gemini_files_transformation.py
+++ b/tests/test_litellm/llms/gemini/files/test_gemini_files_transformation.py
@@ -320,9 +320,7 @@ class TestGoogleAIStudioFilesTransformation:
litellm_params=litellm_params,
)
- # Verify URL extraction
- assert "files/test123" in url
- assert "generativelanguage.googleapis.com" in url
+ assert url == "https://generativelanguage.googleapis.com/v1beta/files/test123"
# Params should be empty (API key goes in header via validate_environment)
assert params == {}