Skip to content

fix(gemini): return raw pcm16 when Gemini TTS answers WAV audio - #51145

Merged
mateo-berri merged 14 commits into
BerriAI:mainfrom
mika-lt:litellm_gemini_tts_wav_to_pcm16
Nov 24, 2026
Merged

mateo-berri merged 14 commits into
BerriAI:mainfrom
mika-lt:litellm_gemini_tts_wav_to_pcm16

Conversation

@mika-lt

@mika-lt mika-lt commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Gemini 3.8 Flash TTS sends back a WAV file where older voices sent raw audio, so chat pcm16 audio came back as WAV and /v1/audio/speech played a click before the voice. This strips that WAV wrapper, while Lyria music and WAV a caller asked for by name come back as before

Details

TLDR

Problem this solves:

  • Gemini 3.8 TTS models answer audio/wav, older ones raw PCM
  • Chat audio with format: pcm16 comes back as WAV bytes
  • /v1/audio/speech puts a second WAV header around that WAV

How it solves it:

  • Unwrap inline audio/wav holding 24 kHz mono 16-bit samples to raw PCM
  • Older models' raw PCM and other WAV shapes pass through as before
  • A request that names an audio mime type, and native or pass-through routes, keep Google's audio

User Flow

Before

  1. Send POST https://litellm-domain/v1/chat/completions with "model": "gemini-3.8-flash-tts", "modalities": ["audio"], and "audio": {"voice": "Kore", "format": "pcm16"}
  2. Get HTTP 200, but the audio starts with a RIFF WAV header
  3. POST https://litellm-domain/v1/audio/speech with "response_format": "wav" returns a WAV with a second RIFF header inside, and "pcm" returns WAV bytes

After

  1. The same chat call returns raw 16-bit PCM with no RIFF header
  2. The same speech calls return one WAV header, and "pcm" returns raw PCM

Relevant issues

Fixes #44541

Supersedes #44545 and #44548, which fix only /v1/audio/speech

Decisions
  • Unwrap on the declared type audio/wav, or its aliases audio/x-wav, audio/wave and audio/vnd.wave, in an inlineData part or a data:audio/...;base64, text part
  • Only a WAV holding 16-bit mono 24 kHz audio, the shape pcm16 names, is unwrapped
    • Any other WAV keeps its header, since raw bytes cannot carry its rate or channels. Lyria music asked for as WAV is 48 kHz stereo, so it comes back as before
    • Alternative: unwrap only for Gemini TTS model names, which needs the model passed into the response parser and would still strip a TTS WAV of another shape
    • The header is read from the first 4096 base64 characters, so a large WAV of another shape is never decoded in full. A header that does not fit there falls back to decoding the whole payload
  • Audio labeled audio/wav that is not strict base64, does not parse as a WAV of that shape, or holds no samples passes through unchanged
    • Alternative: decode leniently, which skips characters outside the base64 alphabet and can turn URL-safe base64 into noise
    • Alternative: fail the request, which would turn a mislabel into an outage
  • A caller who names an audio mime type in the body sent to Gemini gets Gemini's audio as is
    • Naming a container there is an explicit choice, so an AUDIO_WAV request still returns WAV
    • The check reads responseFormat or response_format, under generationConfig or the snake_case generation_config Gemini also takes, with mimeType or mime_type
    • A name like AUDIO_WAV or a nonzero enum number, integer or float, counts. 0 is Gemini's unspecified value, so it counts as no ask
    • A null generationConfig counts as absent, so its snake_case twin is read. Gemini answers that body with the WAV it names
    • Vertex batch output reads the same field from each row's own request
    • Alternative: unwrap anyway, which would turn that explicit WAV request into raw PCM
  • The response cache key includes top-level responseFormat, generationConfig and generation_config for every provider. Main keys extra_body since fix(caching): key the response cache on extra_body by default #53898
    • The audio container now depends on them, so a cached answer must not cross between a WAV ask and no ask
    • Alternative: key them only for Gemini models, which misses a router or fallback that changes the model name
  • Native generateContent and the Gemini and Vertex pass-through routes log Google's audio as is
    • Those routes hand the caller Google's bytes unchanged, so the logged copy matches what the caller got
    • Alternative: unwrap in the logged copy too, which would log raw PCM while the caller holds a WAV
  • The proxy does not ask Gemini for AUDIO_L16 to get raw PCM at the source
    • Alternative: send responseFormat.audio.mimeType: AUDIO_L16 on every call. 3.8 answers it with audio/l16, but 2.5 rejects it, so this needs a per-model list
  • /v1/audio/speech returns chat audio that is already a WAV as is, and wraps only raw PCM
    • Alternative: wrap every payload, which puts a second header around a WAV the unwrap keeps, such as 48 kHz stereo
  • A 3.8 chat call that leaves out audio.format, or drops it under drop_params, also gets raw PCM
  • Google's trailing provenance chunk (C2PA) is dropped on both routes
    • Raw pcm16 has no container to hold it, and the speech route builds its WAV from the chat audio
    • Before this PR, speech wav already hid the chunk inside its own data chunk, where a C2PA reader does not look. Only the routes that broke the pcm16 contract handed it back
    • Alternative: return Google's own WAV from /v1/audio/speech, which needs the speech route to see the provider's container and makes its output differ per model
  • Streaming chunks go through the same unwrap
    • Gemini streams 3.8 audio as raw PCM today, so streaming output does not change

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Each leg is a 2-worker proxy with its own Postgres, calling the real Gemini API and Vertex. Cache cases run two such proxies on one Redis

Last updated: d875f7d. QA ran on d875f7d, with the before leg on the merge base 25b010e

Proxy config
model_list:
  - model_name: gemini-3.8-flash-tts
    litellm_params:
      model: gemini/gemini-3.8-flash-tts
      api_key: os.environ/GEMINI_API_KEY
  - model_name: gemini-3.8-flash-lite-tts
    litellm_params:
      model: gemini/gemini-3.8-flash-lite-tts
      api_key: os.environ/GEMINI_API_KEY
  - model_name: gemini-2.5-flash-preview-tts
    litellm_params:
      model: gemini/gemini-2.5-flash-preview-tts
      api_key: os.environ/GEMINI_API_KEY
  - model_name: vertex-gemini-3.8-flash-tts
    litellm_params:
      model: vertex_ai/gemini-3.8-flash-tts
      vertex_project: os.environ/VERTEXAI_PROJECT
      vertex_location: global
  - model_name: lyria-3.5
    litellm_params:
      model: gemini/lyria-3.5
      api_key: os.environ/GEMINI_API_KEY
general_settings:
  store_prompts_in_spend_logs: true
  master_key: os.environ/LITELLM_MASTER_KEY

Each proxy started from its own tree, with DATABASE_URL naming its own Postgres database

cd <tree> && DATABASE_URL=<its own database> .venv/bin/python litellm/proxy/proxy_cli.py --config proxy_config.yaml --port <random free port> --num_workers 2

The cache proxies add the litellm_settings block under Cache and float cases, all on one Redis at 127.0.0.1:28061

Case Before After
Chat, 3.8 flash WAV PCM
Streaming, 3.8 flash PCM PCM
Vertex chat WAV PCM
Vertex streaming PCM PCM
Speech wav, 3.8 flash 2 headers 1 header
Speech pcm, 3.8 flash WAV PCM
Vertex speech wav 2 headers 1 header
Chat, 3.8 flash lite WAV PCM
Chat, 2.5 flash PCM PCM
Speech wav, 2.5 flash 1 header 1 header
Lyria 3.5 music WAV WAV
SDK speech, 3.8 flash 2 headers 1 header
responseFormat WAV WAV WAV
mime_type key WAV WAV WAV
extra_body WAV WAV WAV
Top-level generationConfig WAV PCM
response_format WAV WAV WAV
WAV by enum number 4 WAV WAV
Enum 0, unspecified WAV PCM
generation_config WAV WAV WAV
Native generateContent WAV WAV
Gemini pass-through WAV WAV
Logged audio WAV WAV
Cache, no ask then WAV ask WAV, WAV PCM, WAV
Cache, WAV ask then no ask WAV, WAV WAV, PCM
Cache, no ask then top-level WAV ask WAV, WAV PCM, WAV
WAV as float 4.0 WAV WAV

Before (25b010e)

Chat audio pcm16, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore","format":"pcm16"},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o chat-38.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' chat-38.json | base64 -d > chat-38.pcm; wc -c < chat-38.pcm; xxd -l 32 chat-38.pcm; grep -c RIFF chat-38.pcm; grep -ao C2PA chat-38.pcm | wc -l
157468
00000000: 5249 4646 1467 0200 5741 5645 666d 7420  RIFF.g..WAVEfmt 
00000010: 1000 0000 0100 0100 c05d 0000 80bb 0000  .........]......
1
12

After (d875f7d)

Chat audio pcm16, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore","format":"pcm16"},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o chat-38.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' chat-38.json | base64 -d > chat-38.pcm; wc -c < chat-38.pcm; xxd -l 32 chat-38.pcm; grep -c RIFF chat-38.pcm; grep -ao C2PA chat-38.pcm | wc -l
147840
00000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000010: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0
0
Other cases

Before, Streaming chat audio pcm16, gemini-3.8-flash-tts

$ curl -sN localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","stream":true,"modalities":["audio"],"audio":{"voice":"Kore","format":"pcm16"},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' > stream-38.sse; grep -c '^data: {' stream-38.sse
47

$ sed -n 's/^data: //p' stream-38.sse | grep -v DONE | jq -r '.choices[0].delta.audio.data // empty' | while read -r c; do print -rn -- $c | base64 -d; done > stream-38.pcm; wc -c < stream-38.pcm; xxd -l 32 stream-38.pcm; grep -c RIFF stream-38.pcm; grep -ao C2PA stream-38.pcm | wc -l
161280
00000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000010: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0
0

After, Streaming chat audio pcm16, gemini-3.8-flash-tts

$ curl -sN localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","stream":true,"modalities":["audio"],"audio":{"voice":"Kore","format":"pcm16"},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' > stream-38.sse; grep -c '^data: {' stream-38.sse
46

$ sed -n 's/^data: //p' stream-38.sse | grep -v DONE | jq -r '.choices[0].delta.audio.data // empty' | while read -r c; do print -rn -- $c | base64 -d; done > stream-38.pcm; wc -c < stream-38.pcm; xxd -l 32 stream-38.pcm; grep -c RIFF stream-38.pcm; grep -ao C2PA stream-38.pcm | wc -l
149760
00000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000010: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0
0

Before, Chat audio pcm16, vertex-gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"vertex-gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore","format":"pcm16"},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o vertex-chat-38.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' vertex-chat-38.json | base64 -d > vertex-chat-38.pcm; wc -c < vertex-chat-38.pcm; xxd -l 32 vertex-chat-38.pcm; grep -c RIFF vertex-chat-38.pcm; grep -ao C2PA vertex-chat-38.pcm | wc -l
145948
00000000: 5249 4646 143a 0200 5741 5645 666d 7420  RIFF.:..WAVEfmt 
00000010: 1000 0000 0100 0100 c05d 0000 80bb 0000  .........]......
1
12

After, Chat audio pcm16, vertex-gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"vertex-gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore","format":"pcm16"},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o vertex-chat-38.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' vertex-chat-38.json | base64 -d > vertex-chat-38.pcm; wc -c < vertex-chat-38.pcm; xxd -l 32 vertex-chat-38.pcm; grep -c RIFF vertex-chat-38.pcm; grep -ao C2PA vertex-chat-38.pcm | wc -l
163200
00000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000010: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0
0

Before, Streaming chat audio pcm16, vertex-gemini-3.8-flash-tts

$ curl -sN localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"vertex-gemini-3.8-flash-tts","stream":true,"modalities":["audio"],"audio":{"voice":"Kore","format":"pcm16"},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' > vertex-stream-38.sse; grep -c '^data: {' vertex-stream-38.sse
55

$ sed -n 's/^data: //p' vertex-stream-38.sse | grep -v DONE | jq -r '.choices[0].delta.audio.data // empty' | while read -r c; do print -rn -- $c | base64 -d; done > vertex-stream-38.pcm; wc -c < vertex-stream-38.pcm; xxd -l 32 vertex-stream-38.pcm; grep -c RIFF vertex-stream-38.pcm; grep -ao C2PA vertex-stream-38.pcm | wc -l
167040
00000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000010: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0
0

After, Streaming chat audio pcm16, vertex-gemini-3.8-flash-tts

$ curl -sN localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"vertex-gemini-3.8-flash-tts","stream":true,"modalities":["audio"],"audio":{"voice":"Kore","format":"pcm16"},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' > vertex-stream-38.sse; grep -c '^data: {' vertex-stream-38.sse
48

$ sed -n 's/^data: //p' vertex-stream-38.sse | grep -v DONE | jq -r '.choices[0].delta.audio.data // empty' | while read -r c; do print -rn -- $c | base64 -d; done > vertex-stream-38.pcm; wc -c < vertex-stream-38.pcm; xxd -l 32 vertex-stream-38.pcm; grep -c RIFF vertex-stream-38.pcm; grep -ao C2PA vertex-stream-38.pcm | wc -l
163200
00000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000010: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0
0

Before, Speech wav, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/audio/speech -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","input":"Say cheerfully: Have a wonderful day!","voice":"Kore","response_format":"wav"}' -o speech-38.wav -D speech-38.hdr -w 'HTTP %{http_code}\n'; grep -i '^content-type' speech-38.hdr
HTTP 200
content-type: audio/wav

$ wc -c < speech-38.wav; xxd -l 16 speech-38.wav; xxd -s 44 -l 16 speech-38.wav; grep -c RIFF speech-38.wav; grep -ao C2PA speech-38.wav | wc -l
161352
00000000: 5249 4646 4076 0200 5741 5645 666d 7420  RIFF@v..WAVEfmt 
0000002c: 5249 4646 1476 0200 5741 5645 666d 7420  RIFF.v..WAVEfmt 
2
12

After, Speech wav, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/audio/speech -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","input":"Say cheerfully: Have a wonderful day!","voice":"Kore","response_format":"wav"}' -o speech-38.wav -D speech-38.hdr -w 'HTTP %{http_code}\n'; grep -i '^content-type' speech-38.hdr
HTTP 200
content-type: audio/wav

$ wc -c < speech-38.wav; xxd -l 16 speech-38.wav; xxd -s 44 -l 16 speech-38.wav; grep -c RIFF speech-38.wav; grep -ao C2PA speech-38.wav | wc -l
159404
00000000: 5249 4646 a46e 0200 5741 5645 666d 7420  RIFF.n..WAVEfmt 
0000002c: 0000 0000 0000 0000 0000 0000 0000 0000  ................
1
0

Before, Speech pcm, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/audio/speech -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","input":"Say cheerfully: Have a wonderful day!","voice":"Kore","response_format":"pcm"}' -o speech-38.pcm -D speech-38.hdr -w 'HTTP %{http_code}\n'; grep -i '^content-type' speech-38.hdr
HTTP 200
content-type: audio/pcm

$ wc -c < speech-38.pcm; xxd -l 16 speech-38.pcm; xxd -s 44 -l 16 speech-38.pcm; grep -c RIFF speech-38.pcm; grep -ao C2PA speech-38.pcm | wc -l
161308
00000000: 5249 4646 1476 0200 5741 5645 666d 7420  RIFF.v..WAVEfmt 
0000002c: 0000 0000 0000 0000 0000 0000 0000 0000  ................
1
12

After, Speech pcm, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/audio/speech -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","input":"Say cheerfully: Have a wonderful day!","voice":"Kore","response_format":"pcm"}' -o speech-38.pcm -D speech-38.hdr -w 'HTTP %{http_code}\n'; grep -i '^content-type' speech-38.hdr
HTTP 200
content-type: audio/pcm

$ wc -c < speech-38.pcm; xxd -l 16 speech-38.pcm; xxd -s 44 -l 16 speech-38.pcm; grep -c RIFF speech-38.pcm; grep -ao C2PA speech-38.pcm | wc -l
144000
00000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0000002c: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0
0

Before, Speech wav, vertex-gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/audio/speech -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"vertex-gemini-3.8-flash-tts","input":"Say cheerfully: Have a wonderful day!","voice":"Kore","response_format":"wav"}' -o vertex-speech-38.wav -D vertex-speech-38.hdr -w 'HTTP %{http_code}\n'; grep -i '^content-type' vertex-speech-38.hdr
HTTP 200
content-type: audio/wav

$ wc -c < vertex-speech-38.wav; xxd -l 16 vertex-speech-38.wav; xxd -s 44 -l 16 vertex-speech-38.wav; grep -c RIFF vertex-speech-38.wav; grep -ao C2PA vertex-speech-38.wav | wc -l
159432
00000000: 5249 4646 c06e 0200 5741 5645 666d 7420  RIFF.n..WAVEfmt 
0000002c: 5249 4646 946e 0200 5741 5645 666d 7420  RIFF.n..WAVEfmt 
2
12

After, Speech wav, vertex-gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/audio/speech -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"vertex-gemini-3.8-flash-tts","input":"Say cheerfully: Have a wonderful day!","voice":"Kore","response_format":"wav"}' -o vertex-speech-38.wav -D vertex-speech-38.hdr -w 'HTTP %{http_code}\n'; grep -i '^content-type' vertex-speech-38.hdr
HTTP 200
content-type: audio/wav

$ wc -c < vertex-speech-38.wav; xxd -l 16 vertex-speech-38.wav; xxd -s 44 -l 16 vertex-speech-38.wav; grep -c RIFF vertex-speech-38.wav; grep -ao C2PA vertex-speech-38.wav | wc -l
142124
00000000: 5249 4646 242b 0200 5741 5645 666d 7420  RIFF$+..WAVEfmt 
0000002c: 0000 0000 0000 0000 0000 0000 0000 0000  ................
1
0

Before, Chat audio pcm16, gemini-3.8-flash-lite-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-lite-tts","modalities":["audio"],"audio":{"voice":"Kore","format":"pcm16"},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o chat-38lite.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' chat-38lite.json | base64 -d > chat-38lite.pcm; wc -c < chat-38lite.pcm; xxd -l 32 chat-38lite.pcm; grep -c RIFF chat-38lite.pcm; grep -ao C2PA chat-38lite.pcm | wc -l
161308
00000000: 5249 4646 1476 0200 5741 5645 666d 7420  RIFF.v..WAVEfmt 
00000010: 1000 0000 0100 0100 c05d 0000 80bb 0000  .........]......
1
12

After, Chat audio pcm16, gemini-3.8-flash-lite-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-lite-tts","modalities":["audio"],"audio":{"voice":"Kore","format":"pcm16"},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o chat-38lite.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' chat-38lite.json | base64 -d > chat-38lite.pcm; wc -c < chat-38lite.pcm; xxd -l 32 chat-38lite.pcm; grep -c RIFF chat-38lite.pcm; grep -ao C2PA chat-38lite.pcm | wc -l
147840
00000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000010: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0
0

Before, Chat audio pcm16, gemini-2.5-flash-preview-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-2.5-flash-preview-tts","modalities":["audio"],"audio":{"voice":"Kore","format":"pcm16"},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o chat-25.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' chat-25.json | base64 -d > chat-25.pcm; wc -c < chat-25.pcm; xxd -l 32 chat-25.pcm; grep -c RIFF chat-25.pcm; grep -ao C2PA chat-25.pcm | wc -l
98446
00000000: fdff feff 0000 fcff 0100 0200 0000 0000  ................
00000010: ffff fdff feff ffff 0100 0000 ffff ffff  ................
0
0

After, Chat audio pcm16, gemini-2.5-flash-preview-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-2.5-flash-preview-tts","modalities":["audio"],"audio":{"voice":"Kore","format":"pcm16"},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o chat-25.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' chat-25.json | base64 -d > chat-25.pcm; wc -c < chat-25.pcm; xxd -l 32 chat-25.pcm; grep -c RIFF chat-25.pcm; grep -ao C2PA chat-25.pcm | wc -l
88846
00000000: 1900 1900 1e00 1b00 2000 2100 1f00 1d00  ........ .!.....
00000010: 1c00 1c00 1d00 1d00 2000 2000 1f00 1f00  ........ . .....
0
0

Before, Speech wav, gemini-2.5-flash-preview-tts

$ curl -s localhost:$PORT/v1/audio/speech -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-2.5-flash-preview-tts","input":"Say cheerfully: Have a wonderful day!","voice":"Kore","response_format":"wav"}' -o speech-25.wav -D speech-25.hdr -w 'HTTP %{http_code}\n'; grep -i '^content-type' speech-25.hdr
HTTP 200
content-type: audio/wav

$ wc -c < speech-25.wav; xxd -l 16 speech-25.wav; xxd -s 44 -l 16 speech-25.wav; grep -c RIFF speech-25.wav; grep -ao C2PA speech-25.wav | wc -l
94650
00000000: 5249 4646 b271 0100 5741 5645 666d 7420  RIFF.q..WAVEfmt 
0000002c: f5ff f4ff faff f4ff fcff feff f7ff f7ff  ................
1
0

After, Speech wav, gemini-2.5-flash-preview-tts

$ curl -s localhost:$PORT/v1/audio/speech -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-2.5-flash-preview-tts","input":"Say cheerfully: Have a wonderful day!","voice":"Kore","response_format":"wav"}' -o speech-25.wav -D speech-25.hdr -w 'HTTP %{http_code}\n'; grep -i '^content-type' speech-25.hdr
HTTP 200
content-type: audio/wav

$ wc -c < speech-25.wav; xxd -l 16 speech-25.wav; xxd -s 44 -l 16 speech-25.wav; grep -c RIFF speech-25.wav; grep -ao C2PA speech-25.wav | wc -l
94650
00000000: 5249 4646 b271 0100 5741 5645 666d 7420  RIFF.q..WAVEfmt 
0000002c: f5ff fbff ffff fcff 0000 ffff feff 0000  ................
1
0

Before, Chat music WAV, lyria-3.5

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"lyria-3.5","modalities":["audio","text"],"responseFormat":{"audio":{"mimeType":"AUDIO_WAV"}},"messages":[{"role":"user","content":"A calm five second piano loop"}]}' -o music.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' music.json | base64 -d > music.wav; wc -c < music.wav; xxd -l 48 music.wav; grep -c RIFF music.wav; grep -ao C2PA music.wav | wc -l
11470364
00000000: 5249 4646 1406 af00 5741 5645 666d 7420  RIFF....WAVEfmt 
00000010: 1000 0000 0100 0200 80bb 0000 00ee 0200  ................
00000020: 0400 1000 6461 7461 00e8 ae00 0000 0000  ....data........
1
12

After, Chat music WAV, lyria-3.5

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"lyria-3.5","modalities":["audio","text"],"responseFormat":{"audio":{"mimeType":"AUDIO_WAV"}},"messages":[{"role":"user","content":"A calm five second piano loop"}]}' -o music.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' music.json | base64 -d > music.wav; wc -c < music.wav; xxd -l 48 music.wav; grep -c RIFF music.wav; grep -ao C2PA music.wav | wc -l
11576860
00000000: 5249 4646 14a6 b000 5741 5645 666d 7420  RIFF....WAVEfmt 
00000010: 1000 0000 0100 0200 80bb 0000 00ee 0200  ................
00000020: 0400 1000 6461 7461 0088 b000 0000 0000  ....data........
1
12

Before, SDK litellm.speech, gemini-3.8-flash-tts, no response_format

$ PYTHON_DOTENV_DISABLED=1 $TREE/.venv/bin/python - <<'PY'
import litellm
litellm.speech(model="gemini/gemini-3.8-flash-tts", input="Hello.", voice="Kore").stream_to_file("sdk-speech.wav")
PY
<stdin>:2: DeprecationWarning: Due to a bug, this method doesn't actually stream the response content, `.with_streaming_response.method()` should be used instead

$ wc -c < sdk-speech.wav; xxd -l 16 sdk-speech.wav; xxd -s 44 -l 16 sdk-speech.wav; grep -c RIFF sdk-speech.wav; grep -ao C2PA sdk-speech.wav | wc -l
63432
00000000: 5249 4646 c0f7 0000 5741 5645 666d 7420  RIFF....WAVEfmt 
0000002c: 5249 4646 94f7 0000 5741 5645 666d 7420  RIFF....WAVEfmt 
2
12

After, SDK litellm.speech, gemini-3.8-flash-tts, no response_format

$ PYTHON_DOTENV_DISABLED=1 $TREE/.venv/bin/python - <<'PY'
import litellm
litellm.speech(model="gemini/gemini-3.8-flash-tts", input="Hello.", voice="Kore").stream_to_file("sdk-speech.wav")
PY
<stdin>:2: DeprecationWarning: Due to a bug, this method doesn't actually stream the response content, `.with_streaming_response.method()` should be used instead

$ wc -c < sdk-speech.wav; xxd -l 16 sdk-speech.wav; xxd -s 44 -l 16 sdk-speech.wav; grep -c RIFF sdk-speech.wav; grep -ao C2PA sdk-speech.wav | wc -l
40364
00000000: 5249 4646 a49d 0000 5741 5645 666d 7420  RIFF....WAVEfmt 
0000002c: 0000 0000 0000 0000 0000 0000 0000 0000  ................
1
0

Before, Chat audio with responseFormat AUDIO_WAV, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"responseFormat":{"audio":{"mimeType":"AUDIO_WAV"}},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o explicit-wav.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' explicit-wav.json | base64 -d > explicit-wav.wav; wc -c < explicit-wav.wav; xxd -l 32 explicit-wav.wav; grep -c RIFF explicit-wav.wav; grep -ao C2PA explicit-wav.wav | wc -l
180508
00000000: 5249 4646 14c1 0200 5741 5645 666d 7420  RIFF....WAVEfmt 
00000010: 1000 0000 0100 0100 c05d 0000 80bb 0000  .........]......
1
12

After, Chat audio with responseFormat AUDIO_WAV, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"responseFormat":{"audio":{"mimeType":"AUDIO_WAV"}},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o explicit-wav.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' explicit-wav.json | base64 -d > explicit-wav.wav; wc -c < explicit-wav.wav; xxd -l 32 explicit-wav.wav; grep -c RIFF explicit-wav.wav; grep -ao C2PA explicit-wav.wav | wc -l
161308
00000000: 5249 4646 1476 0200 5741 5645 666d 7420  RIFF.v..WAVEfmt 
00000010: 1000 0000 0100 0100 c05d 0000 80bb 0000  .........]......
1
12

Before, Chat audio asking for AUDIO_WAV with the mime_type key, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"responseFormat":{"audio":{"mime_type":"AUDIO_WAV"}},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o snake-wav.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' snake-wav.json | base64 -d > snake-wav.wav; wc -c < snake-wav.wav; xxd -l 16 snake-wav.wav; grep -c RIFF snake-wav.wav
144028
00000000: 5249 4646 9432 0200 5741 5645 666d 7420  RIFF.2..WAVEfmt 
1

After, Chat audio asking for AUDIO_WAV with the mime_type key, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"responseFormat":{"audio":{"mime_type":"AUDIO_WAV"}},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o snake-wav.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' snake-wav.json | base64 -d > snake-wav.wav; wc -c < snake-wav.wav; xxd -l 16 snake-wav.wav; grep -c RIFF snake-wav.wav
138268
00000000: 5249 4646 141c 0200 5741 5645 666d 7420  RIFF....WAVEfmt 
1

Before, Chat audio asking for AUDIO_WAV through extra_body.generationConfig, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"extra_body":{"generationConfig":{"responseFormat":{"audio":{"mimeType":"AUDIO_WAV"}}}},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o extra-body-wav.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' extra-body-wav.json | base64 -d > extra-body-wav.wav; wc -c < extra-body-wav.wav; xxd -l 16 extra-body-wav.wav; grep -c RIFF extra-body-wav.wav
168988
00000000: 5249 4646 1494 0200 5741 5645 666d 7420  RIFF....WAVEfmt 
1

After, Chat audio asking for AUDIO_WAV through extra_body.generationConfig, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"extra_body":{"generationConfig":{"responseFormat":{"audio":{"mimeType":"AUDIO_WAV"}}}},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o extra-body-wav.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' extra-body-wav.json | base64 -d > extra-body-wav.wav; wc -c < extra-body-wav.wav; xxd -l 16 extra-body-wav.wav; grep -c RIFF extra-body-wav.wav
174748
00000000: 5249 4646 94aa 0200 5741 5645 666d 7420  RIFF....WAVEfmt 
1

Before, Chat audio with a top-level generationConfig, as the OpenAI SDK's extra_body sends it, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"generationConfig":{"responseFormat":{"audio":{"mimeType":"AUDIO_WAV"}}},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o top-gc-wav.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' top-gc-wav.json | base64 -d > top-gc-wav.wav; wc -c < top-gc-wav.wav; xxd -l 16 top-gc-wav.wav; grep -c RIFF top-gc-wav.wav
172828
00000000: 5249 4646 14a3 0200 5741 5645 666d 7420  RIFF....WAVEfmt 
1

After, Chat audio with a top-level generationConfig, as the OpenAI SDK's extra_body sends it, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"generationConfig":{"responseFormat":{"audio":{"mimeType":"AUDIO_WAV"}}},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o top-gc-wav.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' top-gc-wav.json | base64 -d > top-gc-wav.wav; wc -c < top-gc-wav.wav; xxd -l 16 top-gc-wav.wav; grep -c RIFF top-gc-wav.wav
147840
00000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0

Before, Chat audio asking for AUDIO_WAV through extra_body.generationConfig.response_format, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"extra_body":{"generationConfig":{"response_format":{"audio":{"mimeType":"AUDIO_WAV"}}}},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o extra-body-snake-wav.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' extra-body-snake-wav.json | base64 -d > extra-body-snake-wav.wav; wc -c < extra-body-snake-wav.wav; xxd -l 16 extra-body-snake-wav.wav; grep -c RIFF extra-body-snake-wav.wav
149788
00000000: 5249 4646 1449 0200 5741 5645 666d 7420  RIFF.I..WAVEfmt 
1

After, Chat audio asking for AUDIO_WAV through extra_body.generationConfig.response_format, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"extra_body":{"generationConfig":{"response_format":{"audio":{"mimeType":"AUDIO_WAV"}}}},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o extra-body-snake-wav.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' extra-body-snake-wav.json | base64 -d > extra-body-snake-wav.wav; wc -c < extra-body-snake-wav.wav; xxd -l 16 extra-body-snake-wav.wav; grep -c RIFF extra-body-snake-wav.wav
147868
00000000: 5249 4646 9441 0200 5741 5645 666d 7420  RIFF.A..WAVEfmt 
1

Before, Chat audio naming WAV by its enum number 4, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"responseFormat":{"audio":{"mimeType":4}},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o enum-wav.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' enum-wav.json | base64 -d > enum-wav.wav; wc -c < enum-wav.wav; xxd -l 16 enum-wav.wav; grep -c RIFF enum-wav.wav
147868
00000000: 5249 4646 9441 0200 5741 5645 666d 7420  RIFF.A..WAVEfmt 
1

After, Chat audio naming WAV by its enum number 4, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"responseFormat":{"audio":{"mimeType":4}},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o enum-wav.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' enum-wav.json | base64 -d > enum-wav.wav; wc -c < enum-wav.wav; xxd -l 16 enum-wav.wav; grep -c RIFF enum-wav.wav
157468
00000000: 5249 4646 1467 0200 5741 5645 666d 7420  RIFF.g..WAVEfmt 
1

Before, Chat audio naming the unspecified enum number 0, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"responseFormat":{"audio":{"mimeType":0}},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o enum-zero.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' enum-zero.json | base64 -d > enum-zero.raw; wc -c < enum-zero.raw; xxd -l 16 enum-zero.raw; grep -c RIFF enum-zero.raw
142108
00000000: 5249 4646 142b 0200 5741 5645 666d 7420  RIFF.+..WAVEfmt 
1

After, Chat audio naming the unspecified enum number 0, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"responseFormat":{"audio":{"mimeType":0}},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o enum-zero.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' enum-zero.json | base64 -d > enum-zero.raw; wc -c < enum-zero.raw; xxd -l 16 enum-zero.raw; grep -c RIFF enum-zero.raw
163200
00000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0

Before, Chat audio asking for AUDIO_WAV through a snake_case extra_body.generation_config, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","extra_body":{"generation_config":{"response_modalities":["AUDIO"],"speech_config":{"voice_config":{"prebuilt_voice_config":{"voice_name":"Kore"}}},"response_format":{"audio":{"mime_type":"AUDIO_WAV"}}}},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o snake-gc-wav.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' snake-gc-wav.json | base64 -d > snake-gc-wav.wav; wc -c < snake-gc-wav.wav; xxd -l 16 snake-gc-wav.wav; grep -c RIFF snake-gc-wav.wav
172828
00000000: 5249 4646 14a3 0200 5741 5645 666d 7420  RIFF....WAVEfmt 
1

After, Chat audio asking for AUDIO_WAV through a snake_case extra_body.generation_config, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","extra_body":{"generation_config":{"response_modalities":["AUDIO"],"speech_config":{"voice_config":{"prebuilt_voice_config":{"voice_name":"Kore"}}},"response_format":{"audio":{"mime_type":"AUDIO_WAV"}}}},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o snake-gc-wav.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' snake-gc-wav.json | base64 -d > snake-gc-wav.wav; wc -c < snake-gc-wav.wav; xxd -l 16 snake-gc-wav.wav; grep -c RIFF snake-gc-wav.wav
153628
00000000: 5249 4646 1458 0200 5741 5645 666d 7420  RIFF.X..WAVEfmt 
1

Before, Native generateContent asking for AUDIO_WAV, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1beta/models/gemini-3.8-flash-tts:generateContent -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"contents":[{"role":"user","parts":[{"text":"Say cheerfully: Have a wonderful day!"}]}],"generationConfig":{"responseModalities":["AUDIO"],"speechConfig":{"voiceConfig":{"prebuiltVoiceConfig":{"voiceName":"Kore"}}},"responseFormat":{"audio":{"mimeType":"AUDIO_WAV"}}}}' -D native.hdr -o native.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.candidates[0].content.parts[0].inlineData.data' native.json | base64 -d | xxd -l 12
00000000: 5249 4646 94b9 0200 5741 5645            RIFF....WAVE
base64: write error: Broken pipe
jq: error: writing output failed: Broken pipe

After, Native generateContent asking for AUDIO_WAV, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1beta/models/gemini-3.8-flash-tts:generateContent -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"contents":[{"role":"user","parts":[{"text":"Say cheerfully: Have a wonderful day!"}]}],"generationConfig":{"responseModalities":["AUDIO"],"speechConfig":{"voiceConfig":{"prebuiltVoiceConfig":{"voiceName":"Kore"}}},"responseFormat":{"audio":{"mimeType":"AUDIO_WAV"}}}}' -D native.hdr -o native.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.candidates[0].content.parts[0].inlineData.data' native.json | base64 -d | xxd -l 12
00000000: 5249 4646 946e 0200 5741 5645            RIFF.n..WAVE
base64: write error: Broken pipe
jq: error: writing output failed: Broken pipe

Before, Gemini pass-through generateContent asking for AUDIO_WAV, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/gemini/v1beta/models/gemini-3.8-flash-tts:generateContent -H "x-goog-api-key: $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"contents":[{"role":"user","parts":[{"text":"Say cheerfully: Have a wonderful day!"}]}],"generationConfig":{"responseModalities":["AUDIO"],"speechConfig":{"voiceConfig":{"prebuiltVoiceConfig":{"voiceName":"Kore"}}},"responseFormat":{"audio":{"mimeType":"AUDIO_WAV"}}}}' -D passthrough.hdr -o passthrough.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.candidates[0].content.parts[0].inlineData.data' passthrough.json | base64 -d | xxd -l 12
00000000: 5249 4646 1485 0200 5741 5645            RIFF....WAVE
base64: write error: Broken pipe
jq: error: writing output failed: Broken pipe

After, Gemini pass-through generateContent asking for AUDIO_WAV, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/gemini/v1beta/models/gemini-3.8-flash-tts:generateContent -H "x-goog-api-key: $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"contents":[{"role":"user","parts":[{"text":"Say cheerfully: Have a wonderful day!"}]}],"generationConfig":{"responseModalities":["AUDIO"],"speechConfig":{"voiceConfig":{"prebuiltVoiceConfig":{"voiceName":"Kore"}}},"responseFormat":{"audio":{"mimeType":"AUDIO_WAV"}}}}' -D passthrough.hdr -o passthrough.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.candidates[0].content.parts[0].inlineData.data' passthrough.json | base64 -d | xxd -l 12
00000000: 5249 4646 1494 0200 5741 5645            RIFF....WAVE
base64: write error: Broken pipe
jq: error: writing output failed: Broken pipe

Before, The logged response the Admin UI Logs page shows for each call

The Logs page reads the /spend/logs/ui/<request id> route

$ curl -s "localhost:$PORT/spend/logs/ui/0J8Fa5PdEcWXur8P7vmjuAU" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -o native-log.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.response.choices[0].message.audio.data' native-log.json | head -c 16 | base64 -d | xxd -l 12
00000000: 5249 4646 94b9 0200 5741 5645            RIFF....WAVE

$ curl -s "localhost:$PORT/spend/logs/ui/2c723a7f-51b6-4239-ae0b-8b24759f245b" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -o passthrough-log.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.response.choices[0].message.audio.data' passthrough-log.json | head -c 16 | base64 -d | xxd -l 12
00000000: 5249 4646 1485 0200 5741 5645            RIFF....WAVE

After, The logged response the Admin UI Logs page shows for each call

$ curl -s "localhost:$PORT/spend/logs/ui/u50Fa9jpM4C_odAP4sqiqQo" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -o native-log.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.response.choices[0].message.audio.data' native-log.json | head -c 16 | base64 -d | xxd -l 12
00000000: 5249 4646 946e 0200 5741 5645            RIFF.n..WAVE

$ curl -s "localhost:$PORT/spend/logs/ui/2b8f776a-2ee5-40f1-a5fa-682a15915ee9" -H "Authorization: Bearer $LITELLM_MASTER_KEY" -o passthrough-log.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.response.choices[0].message.audio.data' passthrough-log.json | head -c 16 | base64 -d | xxd -l 12
00000000: 5249 4646 1494 0200 5741 5645            RIFF....WAVE
Cache and float cases

The same proxy config plus this block, with namespace r12-base on the base proxies. Proxy 1 and proxy 2 are two processes of the same tree

Main has keyed the cache on a literal extra_body since #53898, so in the first two cache cases the base proxies no longer share one cache entry between the two asks. The third case sends the WAV ask as a top-level responseFormat, which base leaves out of the cache key and this PR adds to it

litellm_settings:
  cache: true
  cache_params:
    type: redis
    host: 127.0.0.1
    port: 28061
    namespace: r12-head

Before (25b010e), Cache, no ask first on proxy 1, then the AUDIO_WAV ask on proxy 2, then the no ask again on proxy 1

$ curl -s localhost:$P1/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"messages":[{"role":"user","content":"Say cheerfully: The cache keeps track."}]}' -o noask-first.json -D noask-first.hdr -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' noask-first.json | base64 -d > noask-first.raw; wc -c < noask-first.raw; xxd -l 16 noask-first.raw; grep -c RIFF noask-first.raw; grep -i '^x-litellm-cache-key' noask-first.hdr | cut -c1-40
159388
00000000: 5249 4646 946e 0200 5741 5645 666d 7420  RIFF.n..WAVEfmt 
1

$ curl -s localhost:$P2/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"extra_body":{"generationConfig":{"responseFormat":{"audio":{"mimeType":"AUDIO_WAV"}}}},"messages":[{"role":"user","content":"Say cheerfully: The cache keeps track."}]}' -o wavask-second.json -D wavask-second.hdr -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' wavask-second.json | base64 -d > wavask-second.raw; wc -c < wavask-second.raw; xxd -l 16 wavask-second.raw; grep -c RIFF wavask-second.raw; grep -i '^x-litellm-cache-key' wavask-second.hdr | cut -c1-40
144028
00000000: 5249 4646 9432 0200 5741 5645 666d 7420  RIFF.2..WAVEfmt 
1

$ curl -s localhost:$P1/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"messages":[{"role":"user","content":"Say cheerfully: The cache keeps track."}]}' -o noask-repeat.json -D noask-repeat.hdr -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' noask-repeat.json | base64 -d > noask-repeat.raw; wc -c < noask-repeat.raw; xxd -l 16 noask-repeat.raw; grep -c RIFF noask-repeat.raw; grep -i '^x-litellm-cache-key' noask-repeat.hdr | cut -c1-40
159388
00000000: 5249 4646 946e 0200 5741 5645 666d 7420  RIFF.n..WAVEfmt 
1
x-litellm-cache-key: r12-base:c8d6f5bfac

After (d875f7d), Cache, no ask first on proxy 1, then the AUDIO_WAV ask on proxy 2, then the no ask again on proxy 1

$ curl -s localhost:$P1/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"messages":[{"role":"user","content":"Say cheerfully: The cache keeps track."}]}' -o noask-first.json -D noask-first.hdr -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' noask-first.json | base64 -d > noask-first.raw; wc -c < noask-first.raw; xxd -l 16 noask-first.raw; grep -c RIFF noask-first.raw; grep -i '^x-litellm-cache-key' noask-first.hdr | cut -c1-40
140160
00000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0

$ curl -s localhost:$P2/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"extra_body":{"generationConfig":{"responseFormat":{"audio":{"mimeType":"AUDIO_WAV"}}}},"messages":[{"role":"user","content":"Say cheerfully: The cache keeps track."}]}' -o wavask-second.json -D wavask-second.hdr -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' wavask-second.json | base64 -d > wavask-second.raw; wc -c < wavask-second.raw; xxd -l 16 wavask-second.raw; grep -c RIFF wavask-second.raw; grep -i '^x-litellm-cache-key' wavask-second.hdr | cut -c1-40
153628
00000000: 5249 4646 1458 0200 5741 5645 666d 7420  RIFF.X..WAVEfmt 
1

$ curl -s localhost:$P1/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"messages":[{"role":"user","content":"Say cheerfully: The cache keeps track."}]}' -o noask-repeat.json -D noask-repeat.hdr -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' noask-repeat.json | base64 -d > noask-repeat.raw; wc -c < noask-repeat.raw; xxd -l 16 noask-repeat.raw; grep -c RIFF noask-repeat.raw; grep -i '^x-litellm-cache-key' noask-repeat.hdr | cut -c1-40
140160
00000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0
x-litellm-cache-key: r12-head:c8d6f5bfac

Before (25b010e), Cache, the AUDIO_WAV ask first on proxy 2, then no ask on proxy 1

$ curl -s localhost:$P2/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"extra_body":{"generationConfig":{"responseFormat":{"audio":{"mimeType":"AUDIO_WAV"}}}},"messages":[{"role":"user","content":"Say cheerfully: Order matters here."}]}' -o wavask-first.json -D wavask-first.hdr -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' wavask-first.json | base64 -d > wavask-first.raw; wc -c < wavask-first.raw; xxd -l 16 wavask-first.raw; grep -c RIFF wavask-first.raw; grep -i '^x-litellm-cache-key' wavask-first.hdr | cut -c1-40
172828
00000000: 5249 4646 14a3 0200 5741 5645 666d 7420  RIFF....WAVEfmt 
1

$ curl -s localhost:$P1/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"messages":[{"role":"user","content":"Say cheerfully: Order matters here."}]}' -o noask-second.json -D noask-second.hdr -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' noask-second.json | base64 -d > noask-second.raw; wc -c < noask-second.raw; xxd -l 16 noask-second.raw; grep -c RIFF noask-second.raw; grep -i '^x-litellm-cache-key' noask-second.hdr | cut -c1-40
147868
00000000: 5249 4646 9441 0200 5741 5645 666d 7420  RIFF.A..WAVEfmt 
1

After (d875f7d), Cache, the AUDIO_WAV ask first on proxy 2, then no ask on proxy 1

$ curl -s localhost:$P2/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"extra_body":{"generationConfig":{"responseFormat":{"audio":{"mimeType":"AUDIO_WAV"}}}},"messages":[{"role":"user","content":"Say cheerfully: Order matters here."}]}' -o wavask-first.json -D wavask-first.hdr -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' wavask-first.json | base64 -d > wavask-first.raw; wc -c < wavask-first.raw; xxd -l 16 wavask-first.raw; grep -c RIFF wavask-first.raw; grep -i '^x-litellm-cache-key' wavask-first.hdr | cut -c1-40
142108
00000000: 5249 4646 142b 0200 5741 5645 666d 7420  RIFF.+..WAVEfmt 
1

$ curl -s localhost:$P1/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"messages":[{"role":"user","content":"Say cheerfully: Order matters here."}]}' -o noask-second.json -D noask-second.hdr -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' noask-second.json | base64 -d > noask-second.raw; wc -c < noask-second.raw; xxd -l 16 noask-second.raw; grep -c RIFF noask-second.raw; grep -i '^x-litellm-cache-key' noask-second.hdr | cut -c1-40
145920
00000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0

Before (25b010e), Cache, no ask first on proxy 1, then the top-level responseFormat AUDIO_WAV ask on proxy 2

$ curl -s localhost:$P1/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"messages":[{"role":"user","content":"Say cheerfully: Top-level keys count."}]}' -o tl-noask.json -D tl-noask.hdr -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' tl-noask.json | base64 -d > tl-noask.raw; wc -c < tl-noask.raw; xxd -l 16 tl-noask.raw; grep -c RIFF tl-noask.raw; grep -i '^x-litellm-cache-key' tl-noask.hdr | cut -c1-40
186268
00000000: 5249 4646 94d7 0200 5741 5645 666d 7420  RIFF....WAVEfmt 
1

$ curl -s localhost:$P2/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"responseFormat":{"audio":{"mimeType":"AUDIO_WAV"}},"messages":[{"role":"user","content":"Say cheerfully: Top-level keys count."}]}' -o tl-wavask.json -D tl-wavask.hdr -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' tl-wavask.json | base64 -d > tl-wavask.raw; wc -c < tl-wavask.raw; xxd -l 16 tl-wavask.raw; grep -c RIFF tl-wavask.raw; grep -i '^x-litellm-cache-key' tl-wavask.hdr | cut -c1-40
186268
00000000: 5249 4646 94d7 0200 5741 5645 666d 7420  RIFF....WAVEfmt 
1
x-litellm-cache-key: r12-base:7b07045686

After (d875f7d), Cache, no ask first on proxy 1, then the top-level responseFormat AUDIO_WAV ask on proxy 2

$ curl -s localhost:$P1/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"messages":[{"role":"user","content":"Say cheerfully: Top-level keys count."}]}' -o tl-noask.json -D tl-noask.hdr -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' tl-noask.json | base64 -d > tl-noask.raw; wc -c < tl-noask.raw; xxd -l 16 tl-noask.raw; grep -c RIFF tl-noask.raw; grep -i '^x-litellm-cache-key' tl-noask.hdr | cut -c1-40
144000
00000000: 0000 0000 0000 0000 0000 0000 0000 0000  ................
0

$ curl -s localhost:$P2/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"responseFormat":{"audio":{"mimeType":"AUDIO_WAV"}},"messages":[{"role":"user","content":"Say cheerfully: Top-level keys count."}]}' -o tl-wavask.json -D tl-wavask.hdr -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' tl-wavask.json | base64 -d > tl-wavask.raw; wc -c < tl-wavask.raw; xxd -l 16 tl-wavask.raw; grep -c RIFF tl-wavask.raw; grep -i '^x-litellm-cache-key' tl-wavask.hdr | cut -c1-40
163228
00000000: 5249 4646 947d 0200 5741 5645 666d 7420  RIFF.}..WAVEfmt 
1

Before (25b010e), Chat audio naming AUDIO_WAV as the float enum number 4.0, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"responseFormat":{"audio":{"mimeType":4.0}},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o enum-float.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' enum-float.json | base64 -d > enum-float.raw; wc -c < enum-float.raw; xxd -l 16 enum-float.raw; grep -c RIFF enum-float.raw
138268
00000000: 5249 4646 141c 0200 5741 5645 666d 7420  RIFF....WAVEfmt 
1

After (d875f7d), Chat audio naming AUDIO_WAV as the float enum number 4.0, gemini-3.8-flash-tts

$ curl -s localhost:$PORT/v1/chat/completions -H "Authorization: Bearer $LITELLM_MASTER_KEY" -H 'Content-Type: application/json' -d '{"model":"gemini-3.8-flash-tts","modalities":["audio"],"audio":{"voice":"Kore"},"responseFormat":{"audio":{"mimeType":4.0}},"messages":[{"role":"user","content":"Say cheerfully: Have a wonderful day!"}]}' -o enum-float.json -w 'HTTP %{http_code}\n'
HTTP 200

$ jq -r '.choices[0].message.audio.data' enum-float.json | base64 -d > enum-float.raw; wc -c < enum-float.raw; xxd -l 16 enum-float.raw; grep -c RIFF enum-float.raw
159388
00000000: 5249 4646 946e 0200 5741 5645 666d 7420  RIFF.n..WAVEfmt 
1

/live-pr-risk (c703997)

No breaking change seen in 92 live cache, float and native cells on base, fd0ef57, c703997 and its merge with main. Its one Medium is the first Low caveat below. Full report

Carried to d875f7d. Changes since are a main merge and a refactor routing chat and pass-through responses through one helper with the same calls. Proof remains valid because the cache, float and native cells passed again live on this tip. Verification is 1730 focused unit tests and an 808-file affected run, 2 flaky reds aside

Type

🐛 Bug Fix

Caveats (if any)

High

  • With response caching on, an audio mime type ask could get the wrong container, since the cache key left out responseFormat and extra_body
    • Fixed in c703997, with a unit test and the live cache cases above

Low

  • WAV cached before the upgrade, or by an older proxy on the same cache, still reaches no-ask callers, and never expires without a ttl
    • Not worth a fix, since it repeats the old output. A new cache namespace at upgrade clears it
  • Requests carrying generationConfig, generation_config or responseFormat miss the cache once after the upgrade
    • Not worth a fix, since keeping the old key keeps serving the wrong container
  • Google's C2PA provenance chunk is dropped, see Decisions
    • Not worth a fix, since keeping it means returning WAV for pcm16
  • A top-level generationConfig, as the OpenAI SDK's extra_body sends it, now gets PCM where it got WAV
    • Not worth a fix, since honoring it means forwarding a key the proxy always dropped

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR
Bugbot summary

[!NOTE]
Medium Risk
Touches Gemini/Vertex response normalization, streaming, caching keys, and pass-through logging; behavior changes for default TTS audio and cached requests carrying generation config fields.

Overview
Fixes Gemini 3.8 TTS returning audio/wav where chat clients expect raw PCM16 (pcm16), which also caused double WAV headers on /v1/audio/speech.

Adds as_raw_pcm16_base64 to strip the WAV container when the payload is mono 16-bit @ 24 kHz; other WAV shapes (e.g. Lyria) and unparseable audio pass through unchanged. Explicit responseFormat / generationConfig audio mime requests keep Google’s container via requests_audio_mime_type and a keeps_requested_audio_format flag wired through chat, streaming, batch output, logging, and speech-bridge responses (already-WAV speech output is not re-wrapped).

Response cache keys now include responseFormat, generationConfig, and generation_config so WAV vs default PCM asks do not share entries. Gemini/Vertex pass-through paths log and return provider audio as-is via transform_pass_through_response.

Reviewed by Cursor Bugbot for commit d875f7d. Bugbot is set up for automated code reviews on this repo. Configure here.

@veria-ai

veria-ai Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

PR overview

No security issues were found in this pull request.

Reviews

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@greptile-apps

greptile-apps Bot commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge, with no new actionable issues found.

Summary

The PR returns raw PCM16 when Gemini supplies a matching WAV, while preserving explicit audio-format requests and other WAV shapes.

  • Default Gemini and Vertex chat audio returns raw PCM16 when its WAV shape matches.
  • Speech responses keep an existing WAV wrapper instead of adding another.
  • Audio format requests get separate response-cache entries.
  • Gemini and Vertex logs keep the audio format Google returned.

The description acknowledges four caveats from mika-lt. Old cache entries can still return WAV until expiry or a namespace change. Requests carrying the newly keyed fields miss the cache once. Raw PCM drops the provenance chunk. A top-level generationConfig still is not forwarded. The stated reasons are preserving existing cache behavior, separating formats correctly, honoring raw PCM, and avoiding a separate request-forwarding change.

The earlier unnumbered speech-proof thread was addressed with updated live results.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Google audio response] --> B{Preserve provider format?}
  B -->|Yes| C[Return original audio]
  B -->|No| D{WAV with mono 16-bit samples at 24 kHz?}
  D -->|No or unreadable| C
  D -->|Yes| E[Return raw PCM16]
  E --> F{Speech WAV requested?}
  F -->|Yes| G[Add one WAV header]
  F -->|No| H[Return PCM bytes]
Loading

Reviews (5) · Last reviewed commit: "refactor(gemini): log chat and pass-thro..." · Reviewed by Greptile

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@codspeed

codspeed Bot commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 2 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 43 untouched benchmarks


Comparing mika-lt:litellm_gemini_tts_wav_to_pcm16 (2490a55) with main (7ecb9ca)

Open in CodSpeed

@codecov

codecov Bot commented Nov 11, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@mika-lt mika-lt closed this Nov 12, 2026
@mika-lt

mika-lt commented Nov 12, 2026

Copy link
Copy Markdown
Contributor Author

Closed to free an open-PR slot. Branch kept, and it reopens for final CI and bot reviews once ready

…v_to_pcm16

# Conflicts:
#	tests/unit/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py
…annot read

Lyria music asked for as WAV is 48 kHz stereo, so stripping its header lost the rate and channels. Only a 24 kHz mono 16-bit WAV is unwrapped now, and audio that fails to decode or parse comes back unchanged instead of raising.
…n speech

Pass through audio/wav base64 that is not strict base64, including non-ASCII and URL-safe input, unwrap WAV sent as a data URI text part, and return audio that is already a WAV container from /v1/audio/speech as is
…ers from a prefix

A responseFormat.audio.mimeType request now returns Gemini's audio as is, audio/x-wav, audio/wave and audio/vnd.wave labels unwrap like audio/wav, and a WAV of another shape is no longer decoded in full.
… mime_type key

A responseFormat.audio.mime_type, or a responseFormat sent through extra_body.generationConfig, now counts as an explicit ask the same as mimeType. A responseFormat whose audio names no mime type still returns raw PCM
…i receives

An extra_body.generationConfig responseFormat, or response_format, replaces the top-level responseFormat on the request, so the response side now reads that same value before deciding to keep Gemini's audio as is
…i receives

The keep-or-unwrap choice for Gemini TTS chat audio now reads generationConfig.responseFormat (or response_format) from the body sent to Gemini, so a dropped or overridden extra_body value no longer flips it, and a mime type given as its enum number counts as an ask
…, and keep the audio Google sent on batch, native and pass-through logs
… is null

Gemini accepts a null generationConfig next to a snake_case generation_config and answers with the audio format the snake_case key names, so the keep-or-unwrap check now falls through to it.
Whether Gemini TTS audio comes back as raw PCM now depends on the audio mime
type a request names under responseFormat, generationConfig, or
generation_config. The response cache key left those out, so a cached PCM
answer could serve a later AUDIO_WAV ask, and a cached WAV answer could serve
a call that named no format. The cache key now includes them, top level and
under extra_body.

A float mime type such as 4.0 is matched like its enum number, and the native
generateContent pricing copy keeps Google's audio, since it only reads usage.
@mika-lt mika-lt reopened this Nov 20, 2026
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

Comment thread litellm/caching/caching.py Resolved
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

…v_to_pcm16

# Conflicts:
#	litellm/llms/vertex_ai/files/transformation.py
#	litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py
#	tests/unit/caching/test_caching.py
#	tests/unit/proxy/pass_through_endpoints/llm_provider_handlers/test_gemini_passthrough_logging_handler.py
#	tests/unit/proxy/pass_through_endpoints/llm_provider_handlers/test_vertex_passthrough_logging_handler.py
@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit d875f7d. Configure here.

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri mateo-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@mateo-berri
mateo-berri merged commit 9799ad7 into BerriAI:main Nov 24, 2026
56 checks passed
mateo-berri added a commit to norkelbyte/litellm that referenced this pull request Nov 24, 2026
…ini route

Picked from BerriAI#51145 commits 1ba64fb, 6d57373, efcc5d4, 1f5446e, d34fc9c, bd5452a, fd0ef57, c703997 and d875f7d, applied as one change since their diffs touch main-only context

LTS adaptations: no thought_signature_in_tool_call_id or speech-config normalization here, the speech bridge takes no model argument, the cache key leaves out extra_body as LTS always has, streamed chat audio is not surfaced on LTS so the streamed tests are dropped, and the native logging test calls the LTS success-logging entry point
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.

[Bug]: /v1/audio/speech returns a double WAV header for gemini-3.8 TTS models

2 participants