What
When task_type is passed to litellm.embedding() for Gemini models, the parameter name is not converted to match the Gemini API's documented format.
- Gemini REST API documents the field as camelCase
taskType (ref)
- LiteLLM sends it as snake_case
task_type
- LiteLLM's own TypedDicts (
GeminiEmbedContentRequestBody) define it as camelCase taskType
There is an existing conversion for dimensions → outputDimensionality in the same code path. The parallel conversion for task_type → taskType is missing.
Context
gemini-embedding-2-preview supports task-type hints (RETRIEVAL_DOCUMENT, RETRIEVAL_QUERY, SEMANTIC_SIMILARITY, etc.) — docs.
Where
litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_transformation.py
transform_openai_input_gemini_content — has dimensions conversion, missing task_type
transform_openai_input_gemini_embed_content — has dimensions conversion, missing task_type
Reproduction
No API keys needed:
import litellm, json
from unittest.mock import MagicMock, patch
from litellm.llms.custom_httpx.http_handler import HTTPHandler
client = HTTPHandler()
with patch.object(client, "post") as mock_post, \
patch("litellm.llms.vertex_ai.gemini_embeddings.batch_embed_content_handler.GoogleBatchEmbeddings._ensure_access_token", return_value=(None, "p")), \
patch("litellm.llms.vertex_ai.gemini_embeddings.batch_embed_content_handler.GoogleBatchEmbeddings._get_token_and_url", return_value=({"x-goog-api-key": "k"}, "https://example.com")):
mock_post.return_value = MagicMock(status_code=200, json=lambda: {"embeddings": [{"values": [0.1]}]})
litellm.embedding(model="gemini/text-embedding-004", input=["test"], task_type="RETRIEVAL_DOCUMENT", api_key="k", client=client)
body = json.loads(mock_post.call_args.kwargs["data"])
print(json.dumps(body, indent=2))
# Request body contains "task_type" (snake_case)
# Gemini API documents "taskType" (camelCase)
Suggested fix
Add to both functions, alongside the existing dimensions conversion:
if "task_type" in gemini_params:
gemini_params["taskType"] = gemini_params.pop("task_type")
Happy to open a PR with tests if this looks right.
What
When
task_typeis passed tolitellm.embedding()for Gemini models, the parameter name is not converted to match the Gemini API's documented format.taskType(ref)task_typeGeminiEmbedContentRequestBody) define it as camelCasetaskTypeThere is an existing conversion for
dimensions→outputDimensionalityin the same code path. The parallel conversion fortask_type→taskTypeis missing.Context
gemini-embedding-2-previewsupports task-type hints (RETRIEVAL_DOCUMENT,RETRIEVAL_QUERY,SEMANTIC_SIMILARITY, etc.) — docs.Where
litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_transformation.pytransform_openai_input_gemini_content— hasdimensionsconversion, missingtask_typetransform_openai_input_gemini_embed_content— hasdimensionsconversion, missingtask_typeReproduction
No API keys needed:
Suggested fix
Add to both functions, alongside the existing
dimensionsconversion:Happy to open a PR with tests if this looks right.