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
fix(gemini): ignore non-string response_format when deciding on word timestamps
mateo-berrif2e64d981832
diff --git a/litellm/llms/gemini/audio_transcription/transformation.py b/litellm/llms/gemini/audio_transcription/transformation.pyindex 85335371b2b..c8dd7a9a5ff 100644--- a/litellm/llms/gemini/audio_transcription/transformation.py+++ b/litellm/llms/gemini/audio_transcription/transformation.py@@ -223,7 +223,7 @@ def _language_config(language: object) -> GeminiTranscriptionConfig:def _timestamp_config(timestamp_granularities: object, response_format: object) -> GeminiTranscriptionConfig:wants_word_timestamps: Final = (isinstance(timestamp_granularities, list) and "word" in timestamp_granularities- ) or response_format in SUBTITLE_RESPONSE_FORMATS+ ) or (isinstance(response_format, str) and response_format in SUBTITLE_RESPONSE_FORMATS)return _WORD_TIMESTAMP_CONFIG if wants_word_timestamps else _EMPTY_TRANSCRIPTION_CONFIGdiff --git a/tests/test_litellm/llms/gemini/audio_transcription/test_gemini_audio_transcription_transformation.py b/tests/test_litellm/llms/gemini/audio_transcription/test_gemini_audio_transcription_transformation.pyindex 0a06fb968c4..8b48ac0b467 100644--- a/tests/test_litellm/llms/gemini/audio_transcription/test_gemini_audio_transcription_transformation.py+++ b/tests/test_litellm/llms/gemini/audio_transcription/test_gemini_audio_transcription_transformation.py@@ -196,6 +196,15 @@ class TestTransformRequest:)assert "generation_config" not in request_data.data+ def test_non_string_response_format_sends_no_mode(self, config):+ request_data = config.transform_audio_transcription_request(+ model="gemini-3.5-transcribe",+ audio_file=("sample.wav", AUDIO_BYTES, "audio/wav"),+ optional_params={"response_format": {"type": "json_object"}},+ litellm_params={},+ )+ assert "generation_config" not in request_data.data+def test_segment_granularity_sends_no_mode(self, config):request_data = config.transform_audio_transcription_request(model="gemini-3.5-transcribe",diff --git a/tests/test_litellm/llms/soniox/audio_transcription/test_soniox_audio_transcription_transformation.py b/tests/test_litellm/llms/soniox/audio_transcription/test_soniox_audio_transcription_transformation.pyindex 7ee816d5d9e..261efcb7b24 100644--- a/tests/test_litellm/llms/soniox/audio_transcription/test_soniox_audio_transcription_transformation.py+++ b/tests/test_litellm/llms/soniox/audio_transcription/test_soniox_audio_transcription_transformation.py@@ -477,12 +477,12 @@ class TestBuildResponseWithResponseFormat:}}# SRT requested but tokens have no start_ms/end_ms -> empty SRT- # falls back gracefully since _group_tokens_into_cues skips them+ # falls back gracefully since group_subtitle_tokens_into_cues skips themresp = cfg._build_response_from_payload(payload, response_format="srt")# With no timestamp data, SRT rendering produces empty string,# but we still get output because the code checks `tokens` truthiness# before choosing SRT path. Actually the tokens list is truthy but- # _group_tokens_into_cues will produce no cues -> empty SRT string.+ # group_subtitle_tokens_into_cues will produce no cues -> empty SRT string.# Let's verify it doesn't crash.assert isinstance(resp.text, str)