litellm/tests/unit
Jeremy Schoemaker 39372b3922
fix(gemini/vertex realtime): declare the real input audio sample rate
Fixes #40563.

Both GeminiRealtimeConfig and VertexAIRealtimeConfig hardcoded the pcm16 input
MIME type to audio/pcm;rate=24000. 24kHz is the Live API's *output* rate. Its
documented native *input* rate is 16kHz, and the MIME rate is the only channel
the caller has for telling the server what it is actually sending:

  "Audio output always uses a sample rate of 24kHz. Input audio is natively
   16kHz ... To convey the sample rate of input audio, set the MIME type of each
   audio-containing Blob to a value like audio/pcm;rate=16000."
  https://ai.google.dev/gemini-api/docs/live-api/capabilities

Because the server resamples against whatever the MIME type claims, a client
streaming correct 16kHz PCM16 had it relabeled as 24kHz, which corrupts it
server-side and degrades transcription with no error anywhere.

Three changes:

1. The rate now comes from what the client declared. session.update carries it
   in the GA shape at audio.input.format.rate, so that value is recorded and
   used for every subsequent blob. The rate-less beta shape (input_audio_format
   is a bare codec name), a missing or malformed rate, and a bool (an int
   subclass, so excluded explicitly) all leave the default alone.
2. That default is now 16000, the documented native input rate, instead of the
   output rate.
3. VertexAIRealtimeConfig's byte-identical copy of get_audio_mime_type is
   deleted so it inherits the parent. The duplicate is why patching the parent
   alone had no effect on the Vertex path, which is the trap the report calls
   out; a test now asserts the override stays gone.

The billed audio duration reads the same rate, so the label and the duration
estimate cannot disagree. PCM16_INPUT_AUDIO_BYTES_PER_SECOND (48000, that is
24kHz x 2 bytes) is replaced by the declared rate x PCM16_BYTES_PER_SAMPLE.
This does move the estimate for a transcribe-live caller who declares no rate:
the same byte count is now billed as 1.5x the duration, because 16kHz audio
takes 1.5x as long to send as the 24kHz the old constant assumed. The two
existing estimate tests are updated for that, and a new test covers a caller
that declares 24kHz and still bills at the old numbers.

14 tests added or updated, each verified to fail against unpatched sources.
tests/test_litellm/llms/{gemini,vertex_ai}/realtime: 97 passed.
2026-09-23 15:25:06 -05:00
..
a2a_protocol test(a2a): sort imports in merged bedrock agentcore test 2026-09-21 16:10:40 +00:00
anthropic_interface test: add __init__.py to migrated tests/unit packages 2026-09-20 11:53:49 +00:00
batches fix(cost): bill batch prompts above 272K at OpenAI's long-context batch tier (#39861) 2026-09-22 10:22:41 -07:00
chat_completions feat(rust-bridge): add cache and secret migration foundations (#42328) 2026-09-22 03:41:04 +00:00
completion_extras test: add sync and async custom_llm_provider bridge propagation tests 2026-09-20 13:46:52 +00:00
compression test: add __init__.py to migrated tests/unit packages 2026-09-20 11:53:49 +00:00
endpoints test: add __init__.py to migrated tests/unit packages 2026-09-20 11:53:49 +00:00
enterprise test(unit): make bedrock collector and secret scan timing tests deterministic (#42405) 2026-09-22 09:30:28 -07:00
integrations chore: merge main into litellm_migrate_tests_p1 2026-09-20 12:54:53 +00:00
litellm_core_utils test(response_metadata): make the detailed-timing receive-anchor test timezone independent (#42429) 2026-09-22 10:49:37 -07:00
llms fix(gemini/vertex realtime): declare the real input audio sample rate 2026-09-23 15:25:06 -05:00
messages feat(rust-bridge): add cache and secret migration foundations (#42328) 2026-09-22 03:41:04 +00:00
models feat(auth): breached password detection, self-service change-password and forced password reset 2026-09-21 18:48:35 +00:00
ocr feat(rust-bridge): add cache and secret migration foundations (#42328) 2026-09-22 03:41:04 +00:00
passthrough test: migrate phase 15 legacy tests to tests/unit 2026-09-20 11:55:43 +00:00
rag test: add __init__.py to intermediate tests/unit packages 2026-09-20 12:55:27 +00:00
realtime_api test: add __init__.py to new tests/unit packages 2026-09-20 12:36:13 +00:00
repositories test: point CircleCI-only suites at models still in the cost map (#42617) 2026-09-22 17:28:34 -07:00
router_strategy fix(auto-router): skip JEV for encrypted delegated tasks 2026-09-21 18:29:21 +00:00
router_utils Merge pull request #42080 from BerriAI/litellm_prompt_caching_affinity_lookback 2026-09-21 12:44:34 -07:00
rust_bridge Merge remote-tracking branch 'origin/main' into litellm_migrate_tests_p15 2026-09-20 13:44:24 +00:00
sandbox test: add __init__.py to every tests/unit directory phase 16 touches 2026-09-20 11:52:38 +00:00
skills test: add __init__.py to every tests/unit directory phase 16 touches 2026-09-20 11:52:38 +00:00
test_router test: add __init__.py to every tests/unit directory phase 16 touches 2026-09-20 11:52:38 +00:00
types test: add __init__.py to every tests/unit directory phase 16 touches 2026-09-20 11:52:38 +00:00
videos test: migrate phase 16 legacy tests to tests/unit 2026-09-20 10:59:02 +00:00
__init__.py test(unit): add package markers to migrated unit test directories 2026-09-20 11:53:14 +00:00
AGENTS.md docs(tests): define the tier contract for unit, integration and e2e 2026-09-20 06:24:06 +00:00
conftest.py test: use main's local_model_cost_map fixture in tests/unit/conftest.py 2026-09-20 13:44:30 +00:00
test_package_layout.py test(unit): make every tests/unit directory a package so pytest collection is unique 2026-09-20 11:50:59 +00:00
test_socket_policy.py test(unit): block external sockets at import time and add a socket policy regression test 2026-09-20 08:07:50 +00:00