litellm/tests/test_litellm/llms/vertex_ai/gemini_embeddings
Mateo Wang 6e3540856c
fix(vertex): preserve Gemini Embedding 2 usageMetadata for cost tracking (#31354)
* fix(vertex): preserve Gemini Embedding 2 usageMetadata for cost tracking

* style(vertex): apply ruff format to batch_embed_content_transformation

* fix(vertex): bill files/ image refs in Gemini embedContent at per-image rate

Resolved files/... references whose mime type is an image were not detected
by _is_image_element, so image_count stayed 0 and generic_cost_per_token fell
back to the text token rate instead of input_cost_per_image. Thread the
resolved_files mapping into the usage builder so resolved image references are
counted and billed per image. Also modernize the _flatten_input return
annotation to satisfy the ruff UP006 strict gate.

* fix(vertex): bill Gemini embedding audio per-second and stop video+audio double-billing

Audio-only embedContent responses set audio_tokens, but generic_cost_per_token only
charges audio via input_cost_per_audio_token. gemini-embedding-2 prices audio via
input_cost_per_audio_per_second, so spend stayed at $0. Plumb a new
audio_length_seconds field through PromptTokensDetailsWrapper, parse it in
_parse_prompt_tokens_details, and bill it from _calculate_input_cost. The vertex
embedding transformation derives audio_length_seconds from audio_tokens using
the documented 32 tokens/sec Gemini rate.

The 1-token text floor that protects video billing only fired when no other
modality was billable, but audio presence flipped that flag, leaving text_tokens
at zero for video+audio responses. generic_cost_per_token then rewrote
text_tokens to prompt_tokens minus audio_tokens (the video token count),
charging video tokens as text on top of the per-second video cost. The rewrite
trigger is text_tokens == 0 and image_count == 0; align the floor with that
trigger and ignore audio_tokens.

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
2026-06-25 19:53:16 -07:00
..
__init__.py fix(gemini): return separate embeddings for multimodal batch inputs (#24209) 2026-03-21 23:06:24 -03:00
test_batch_embed_content_transformation.py fix(vertex): preserve Gemini Embedding 2 usageMetadata for cost tracking (#31354) 2026-06-25 19:53:16 -07:00