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]

Merge remote-tracking branch 'origin/litellm_internal_staging' into codex/cloud-storage-file-guard

user7c94149aeb13
diff --cc litellm/llms/vertex_ai/files/handler.py
index 1a92d521065,bd4b2ac8bbc..c31bfde69e7
--- a/litellm/llms/vertex_ai/files/handler.py
+++ b/litellm/llms/vertex_ai/files/handler.py
@@@ -1,5 -1,6 +1,6 @@@
import asyncio
+ import time
-import urllib.parse
+from urllib.parse import unquote
from typing import Any, Coroutine, Optional, Tuple, Union
import httpx
@@@ -198,11 -189,31 +200,30 @@@ class VertexAIFilesHandler(GCSBucketBas
mock_response = httpx.Response(
status_code=200,
content=file_content,
- headers={"content-type": "application/octet-stream"},
+ headers={
+ "content-type": "application/octet-stream",
+ "content-length": str(len(file_content)),
+ },
- request=httpx.Request(method="GET", url=decoded_path),
+ request=httpx.Request(method="GET", url=decoded_file_id),
)
- return HttpxBinaryResponseContent(response=mock_response)
+ # Apply transformation to convert Vertex AI batch outputs to OpenAI format
+ config = VertexAIFilesConfig()
+
+ # Create a logging object for transformation
+ logging_obj = Logging(
+ model="",
+ messages=[],
+ stream=False,
+ call_type="afile_content",
+ start_time=time.time(),
+ litellm_call_id="",
+ function_id="",
+ )
+
+ return config.transform_file_content_response(
+ raw_response=mock_response, logging_obj=logging_obj, litellm_params={}
+ )
def file_content(
self,
diff --cc litellm/llms/vertex_ai/files/transformation.py
index 85663bd551c,01b2125d030..f30518bc7ca
--- a/litellm/llms/vertex_ai/files/transformation.py
+++ b/litellm/llms/vertex_ai/files/transformation.py
@@@ -5,17 -9,10 +9,19 @@@ import http
from httpx import Headers, Response
from openai.types.file_deleted import FileDeleted
+ import litellm
from litellm._uuid import uuid
from litellm.files.utils import FilesAPIUtils
+from litellm.litellm_core_utils.cloud_storage_security import (
+ VERTEX_AI_MANAGED_GCS_PREFIX,
+ build_managed_cloud_object_name,
+ encode_gcs_object_name_for_url,
+ sanitize_cloud_object_path,
+ should_allow_legacy_cloud_file_ids,
+ split_configured_cloud_bucket_name,
+ validate_managed_cloud_file_id,
+)
+ from litellm.litellm_core_utils.litellm_logging import Logging
from litellm.litellm_core_utils.prompt_templates.common_utils import extract_file_data
from litellm.llms.base_llm.chat.transformation import BaseLLMException
from litellm.llms.base_llm.files.transformation import (
diff --cc tests/test_litellm/llms/vertex_ai/files/test_vertex_ai_files_transformation.py
index a41fafa0e87,b8482ce6aae..7c063c72607
--- a/tests/test_litellm/llms/vertex_ai/files/test_vertex_ai_files_transformation.py
+++ b/tests/test_litellm/llms/vertex_ai/files/test_vertex_ai_files_transformation.py
@@@ -1,10 -1,10 +1,12 @@@
"""
Tests for VertexAIFilesConfig transformation methods (Issues 5-7).
+ Includes tests for Vertex AI batch output transformation to OpenAI format.
"""
+ import json
import urllib.parse
+from types import MappingProxyType
+from urllib.parse import parse_qs, urlparse
import httpx
import pytest