Skip to content

fix(gemini-embeddings): convert task_type to camelCase taskType for Gemini API#24191

Merged
RheagalFire merged 1 commit intoBerriAI:litellm_oss_staging_03_19_2026from
christopherbaer:fix/gemini-embedding-task-type-camelcase
Mar 20, 2026
Merged

fix(gemini-embeddings): convert task_type to camelCase taskType for Gemini API#24191
RheagalFire merged 1 commit intoBerriAI:litellm_oss_staging_03_19_2026from
christopherbaer:fix/gemini-embedding-task-type-camelcase

Conversation

@christopherbaer
Copy link
Copy Markdown
Contributor

Fixes #24190

What

  • 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

The existing code converts dimensionsoutputDimensionality but misses the parallel task_typetaskType conversion.

Fix

Adds task_typetaskType conversion to both transformation functions in batch_embed_content_transformation.py, following the existing dimensions pattern:

if "task_type" in gemini_params:
    gemini_params["taskType"] = gemini_params.pop("task_type")

Tests added

  • test_task_type_mapped_to_camel_case_batch — snake_case conversion for batchEmbedContents path
  • test_task_type_mapped_to_camel_case_embed_content — snake_case conversion for embedContent path
  • test_task_type_camel_case_passthrough — camelCase taskType passed directly is preserved

All 23 tests in test_gemini_batch_embeddings.py pass.

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 20, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Mar 20, 2026 6:17am

Request Review

@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 20, 2026

CLA assistant check
All committers have signed the CLA.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Mar 20, 2026

Greptile Summary

This PR fixes a long-standing silent bug where LiteLLM was sending task_type (snake_case) to the Gemini embeddings API instead of the correct taskType (camelCase). The API was silently ignoring the field, meaning task type had no effect. The fix adds the missing task_typetaskType key conversion to both transform_openai_input_gemini_content (batchEmbedContents path) and transform_openai_input_gemini_embed_content (embedContent path), mirroring the already-present dimensionsoutputDimensionality pattern.

Changes:

  • batch_embed_content_transformation.py: Adds task_typetaskType renaming in both transformation functions (4 lines, following existing idiom)
  • test_gemini_batch_embeddings.py: Three new mock-only unit tests covering snake_case conversion for each path and camelCase passthrough preservation

Notes:

  • The fix is minimal, correct, and consistent with the existing dimensions mapping pattern
  • All new tests use mocks (no real network calls), satisfying CI/CD requirements
  • Minor coverage gap: there is no camelCase taskType passthrough test for the batch (transform_openai_input_gemini_content) path — only for transform_openai_input_gemini_embed_content — though this is low risk given the code path is identical

Confidence Score: 5/5

  • This PR is safe to merge — it is a minimal, targeted bug fix with proper test coverage and no backward-compatibility concerns.
  • The change is 4 lines in the source file, follows an established pattern already in the codebase, correctly fixes an API contract mismatch, and is covered by new mock-based tests. No custom rules are violated, no real network calls are added to the test suite, and the existing 23 tests continue to pass.
  • No files require special attention.

Important Files Changed

Filename Overview
litellm/llms/vertex_ai/gemini_embeddings/batch_embed_content_transformation.py Adds task_typetaskType key conversion in both transformation functions, correctly following the existing dimensionsoutputDimensionality pattern. Change is minimal, correct, and complete.
tests/litellm/llms/vertex_ai/test_gemini_batch_embeddings.py Adds three new mock-based unit tests that verify snake_case→camelCase conversion for both API paths and camelCase passthrough. All tests are properly mocked (no real network calls). Minor: camelCase passthrough is only tested for the embed_content path, not the batch path.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[User calls litellm.embedding with task_type param] --> B{Which path?}
    B -->|text-only, non-multimodal| C[transform_openai_input_gemini_content\nbatchEmbedContents path]
    B -->|multimodal / gemini-embedding-2-preview| D[transform_openai_input_gemini_embed_content\nembedContent path]

    C --> E{task_type in gemini_params?}
    E -->|Yes - BEFORE fix| F1["❌ Sends task_type\n(silently ignored by API)"]
    E -->|Yes - AFTER fix| G1["✅ Renames to taskType\n(accepted by API)"]
    E -->|No| H1[Pass through unchanged]

    D --> I{task_type in gemini_params?}
    I -->|Yes - BEFORE fix| F2["❌ Sends task_type\n(silently ignored by API)"]
    I -->|Yes - AFTER fix| G2["✅ Renames to taskType\n(accepted by API)"]
    I -->|No| H2[Pass through unchanged]

    G1 --> J1[EmbedContentRequest with taskType field]
    H1 --> J1
    G2 --> J2[embedContent request body with taskType field]
    H2 --> J2
Loading

Last reviewed commit: "fix(gemini-embedding..."

@codspeed-hq
Copy link
Copy Markdown
Contributor

codspeed-hq bot commented Mar 20, 2026

Merging this PR will not alter performance

✅ 16 untouched benchmarks


Comparing christopherbaer:fix/gemini-embedding-task-type-camelcase (ed764f7) with main (30589b0)

Open in CodSpeed

…emini API

The Gemini REST API documents the embedding task type parameter as
camelCase `taskType`. The existing transformation functions convert
`dimensions` to `outputDimensionality` but miss the parallel
`task_type` to `taskType` conversion. This adds that conversion to
both `transform_openai_input_gemini_content` (batchEmbedContents path)
and `transform_openai_input_gemini_embed_content` (embedContent path).

Fixes BerriAI#24190
@RheagalFire RheagalFire changed the base branch from main to litellm_oss_staging_03_19_2026 March 20, 2026 17:01
@RheagalFire RheagalFire merged commit 589c6cd into BerriAI:litellm_oss_staging_03_19_2026 Mar 20, 2026
39 checks passed
@christopherbaer christopherbaer deleted the fix/gemini-embedding-task-type-camelcase branch March 26, 2026 02:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

task_type not converted to camelCase taskType for Gemini embeddings

3 participants