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(gemini-embeddings): convert task_type to camelCase taskType for Gemini API (#24191)

Christopher Baer589c6cdad00d
diff --git a/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_transformation.py b/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_transformation.py
index 0f6d85525d9..08831a8215f 100644
--- a/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_transformation.py
+++ b/litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_transformation.py
@@ -152,6 +152,8 @@ def transform_openai_input_gemini_content(
gemini_params = optional_params.copy()
if "dimensions" in gemini_params:
gemini_params["outputDimensionality"] = gemini_params.pop("dimensions")
+ if "task_type" in gemini_params:
+ gemini_params["taskType"] = gemini_params.pop("task_type")
requests: List[EmbedContentRequest] = []
if isinstance(input, str):
@@ -196,6 +198,8 @@ def transform_openai_input_gemini_embed_content(
gemini_params = optional_params.copy()
if "dimensions" in gemini_params:
gemini_params["outputDimensionality"] = gemini_params.pop("dimensions")
+ if "task_type" in gemini_params:
+ gemini_params["taskType"] = gemini_params.pop("task_type")
input_list = [input] if isinstance(input, str) else input
parts: List[PartType] = []
diff --git a/tests/litellm/llms/vertex_ai/test_gemini_batch_embeddings.py b/tests/litellm/llms/vertex_ai/test_gemini_batch_embeddings.py
index 1ed1de01b5f..a8e427d3bc1 100644
--- a/tests/litellm/llms/vertex_ai/test_gemini_batch_embeddings.py
+++ b/tests/litellm/llms/vertex_ai/test_gemini_batch_embeddings.py
@@ -22,6 +22,7 @@ from litellm.llms.vertex_ai.gemini_embeddings.batch_embed_content_transformation
_is_multimodal_input,
_parse_data_url,
process_embed_content_response,
+ transform_openai_input_gemini_content,
transform_openai_input_gemini_embed_content,
)
from litellm.types.utils import EmbeddingResponse
@@ -396,6 +397,44 @@ def test_transform_with_optional_params():
assert result["taskType"] == "SEMANTIC_SIMILARITY"
+def test_task_type_mapped_to_camel_case_batch():
+ """Test that snake_case task_type is converted to camelCase taskType for batchEmbedContents."""
+ result = transform_openai_input_gemini_content(
+ input="test text",
+ model="text-embedding-004",
+ optional_params={"task_type": "RETRIEVAL_DOCUMENT"},
+ )
+ for request in result["requests"]:
+ assert "taskType" in request
+ assert request["taskType"] == "RETRIEVAL_DOCUMENT"
+ assert "task_type" not in request
+
+
+def test_task_type_mapped_to_camel_case_embed_content():
+ """Test that snake_case task_type is converted to camelCase taskType for embedContent."""
+ result = transform_openai_input_gemini_embed_content(
+ input=["test text"],
+ model="gemini-embedding-2-preview",
+ optional_params={"task_type": "RETRIEVAL_DOCUMENT"},
+ resolved_files=None,
+ )
+ assert "taskType" in result
+ assert result["taskType"] == "RETRIEVAL_DOCUMENT"
+ assert "task_type" not in result
+
+
+def test_task_type_camel_case_passthrough():
+ """Test that camelCase taskType passed directly is preserved."""
+ result = transform_openai_input_gemini_embed_content(
+ input=["test text"],
+ model="gemini-embedding-2-preview",
+ optional_params={"taskType": "SEMANTIC_SIMILARITY"},
+ resolved_files=None,
+ )
+ assert result["taskType"] == "SEMANTIC_SIMILARITY"
+ assert "task_type" not in result
+
+
def test_dimensions_mapped_to_output_dimensionality():
"""Test that OpenAI 'dimensions' param is mapped to Gemini 'outputDimensionality'."""
input_data = ["test text"]