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
feat: add opt-out flag for Vertex batch output transformation
mateo-berri439217511af7
diff --git a/litellm/__init__.py b/litellm/__init__.pyindex d02d39cae15..28112f5c12a 100644--- a/litellm/__init__.py+++ b/litellm/__init__.py@@ -288,6 +288,7 @@ disable_token_counter: bool = Falsedisable_add_transform_inline_image_block: bool = Falsedisable_add_user_agent_to_request_tags: bool = Falsedisable_anthropic_gemini_context_caching_transform: bool = False+disable_vertex_batch_output_transformation: bool = Falseextra_spend_tag_headers: Optional[List[str]] = Nonein_memory_llm_clients_cache: "LLMClientCache"safe_memory_mode: bool = Falsediff --git a/litellm/llms/vertex_ai/files/transformation.py b/litellm/llms/vertex_ai/files/transformation.pyindex 02ef2ab6575..7df16723870 100644--- a/litellm/llms/vertex_ai/files/transformation.py+++ b/litellm/llms/vertex_ai/files/transformation.py@@ -9,6 +9,7 @@ import httpxfrom httpx import Headers, Responsefrom openai.types.file_deleted import FileDeleted+import litellmfrom litellm._uuid import uuidfrom litellm.files.utils import FilesAPIUtilsfrom litellm.litellm_core_utils.litellm_logging import Logging@@ -573,6 +574,11 @@ class VertexAIFilesConfig(VertexBase, BaseFilesConfig):is returned as-is to maintain backward compatibility."""try:+ # Allow users to opt out of automatic Vertex batch output -> OpenAI+ # transformation, e.g. if they consume raw `predictions.jsonl` directly.+ if getattr(litellm, "disable_vertex_batch_output_transformation", False):+ return HttpxBinaryResponseContent(response=raw_response)+# Try to transform batch output if it's a JSONL filecontent = raw_response.contentif content:diff --git 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.pyindex 6537fb6a946..4adad53a98f 100644--- 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@@ -210,6 +210,47 @@ class TestTransformFileContent:assert logging_obj.optional_params == original_optional_paramsassert result.response is not raw_response+ def test_should_skip_batch_output_transformation_when_opt_out_flag_set(+ self, config, monkeypatch+ ):+ """When `litellm.disable_vertex_batch_output_transformation` is True the+ Vertex predictions.jsonl content must be returned untouched, so callers+ that parse raw `candidates`/`modelVersion` keep working."""+ import litellm++ raw_jsonl = json.dumps(+ {+ "status": "",+ "processed_time": "2024-11-01T18:13:16.826+00:00",+ "request": {"labels": {"litellm_custom_id": "request-1"}},+ "response": {+ "candidates": [+ {"content": {"parts": [{"text": "ok"}], "role": "model"}}+ ],+ "modelVersion": "gemini-2.0-flash-001@default",+ },+ }+ ).encode("utf-8")+ raw_response = httpx.Response(+ status_code=200,+ content=raw_jsonl,+ headers={"content-type": "application/octet-stream"},+ request=httpx.Request("GET", "https://example.com"),+ )++ monkeypatch.setattr(+ litellm, "disable_vertex_batch_output_transformation", True, raising=False+ )++ result = config.transform_file_content_response(+ raw_response=raw_response,+ logging_obj=MagicMock(),+ litellm_params={},+ )++ assert isinstance(result, HttpxBinaryResponseContent)+ assert result.response.content == raw_jsonl+class TestTransformDeleteFile:def test_should_build_correct_gcs_delete_url(self, config):