There is a consistent 500 INTERNAL server error when trying to generate content from audio files using the gemini-3.1-flash-lite model.
The issue occurs specifically when an audio file (tested with .wav and .ogg formats) is uploaded using the Gemini File API (client.files.upload) and then passed to client.models.generate_content.
Key Findings:
- Isolated to gemini-3.1-flash-lite: The same audio files and the exact same code work perfectly fine with other models like gemini-3.5-flash and gemini-2.5-flash (which successfully process the file without any server errors).
- Text-only works: Sending simple text prompts to gemini-3.1-flash-lite works successfully, isolating the issue purely to audio/file input processing for this specific model.
- API Versions: The issue is present in both v1 and v1beta API versions.
- Payload Formats: The error occurs regardless of how the file is passed into contents — whether passing the File object directly, wrapping it via types.Part.from_uri(), or using types.Part(file_data=types.FileData(...)).
Environment
- SDK: google-genai (Python)
- API Version: v1beta and v1
- Model: gemini-3.1-flash-lite
- Python Version: 3.11 / 3.12
Steps to Reproduce
Here is a minimal, self-contained Python script to reproduce the issue. It generates a small valid 3-second sine-wave WAV file, uploads it to the File API, waits for it to become ACTIVE, and attempts to generate content using gemini-3.1-flash-lite.
import os
import asyncio
import wave
import struct
import math
from google import genai
from google.genai import types
from google.genai import errors
# Helper to create a valid sine wave audio file
def create_sinewave_wav(filename="test_audio.wav", duration=3, sample_rate=16000, frequency=440.0):
with wave.open(filename, "wb") as w:
w.setnchannels(1)
w.setsampwidth(2)
w.setframerate(sample_rate)
n_samples = int(duration * sample_rate)
samples = [int(10000.0 * math.sin(2.0 * math.pi * frequency * i / sample_rate)) for i in range(n_samples)]
data = struct.pack("<" + "h" * n_samples, *samples)
w.writeframes(data)
async def _wait_for_file_active(client, file):
current_file = file
while current_file.state == "PROCESSING":
await asyncio.sleep(2)
current_file = await client.aio.files.get(name=current_file.name)
if current_file.state != "ACTIVE":
raise Exception(f"File failed to process. State: {current_file.state}")
return current_file
async def main():
api_key = os.environ.get("GOOGLE_API_KEY")
client = genai.Client(api_key=api_key, http_options={"api_version": "v1beta"})
audio_path = "test_audio.wav"
create_sinewave_wav(audio_path)
try:
# 1. Upload audio to Gemini File API
uploaded_file = await client.aio.files.upload(
file=audio_path,
config=dict(mime_type="audio/wav")
)
active_file = await _wait_for_file_active(client, uploaded_file)
# 2. Attempt content generation with gemini-3.1-flash-lite
print("Testing gemini-3.1-flash-lite...")
try:
response = await client.aio.models.generate_content(
model="gemini-3.1-flash-lite",
contents=["Summarize this audio.", active_file]
)
print(f"Success: {response.text}")
except Exception as e:
print(f"FAILED with gemini-3.1-flash-lite: {e}")
finally:
if os.path.exists(audio_path):
os.remove(audio_path)
if __name__ == "__main__":
asyncio.run(main())
Traceback / Error Log
google.genai.errors.ServerError: 500 INTERNAL. {'error': {'code': 500, 'message': 'Internal error encountered.', 'status': 'INTERNAL'}}
Traceback (most recent call last):
File "test_audio_gemini.py", line 43, in main
response = await client.aio.models.generate_content(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/site-packages/google/genai/models.py", line 8586, in generate_content
response = await self._generate_content(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/site-packages/google/genai/models.py", line 7117, in _generate_content
response = await self._api_client.async_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/site-packages/google/genai/_api_client.py", line 1657, in async_request
result = await self._async_request(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/site-packages/google/genai/_api_client.py", line 1590, in _async_request
return await self._async_retry(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/site-packages/tenacity/asyncio/__init__.py", line 112, in __call__
do = await self.iter(retry_state=retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/site-packages/tenacity/asyncio/__init__.py", line 157, in iter
result = await action(retry_state)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/site-packages/tenacity/_utils.py", line 111, in inner
return call(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^
File "/site-packages/tenacity/__init__.py", line 413, in exc_check
raise retry_exc.reraise()
^^^^^^^^^^^^^^^^^^^
File "/site-packages/tenacity/__init__.py", line 184, in reraise
raise self.last_attempt.result()
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/concurrent/futures/_base.py", line 449, in result
return self.__get_result()
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/concurrent/futures/_base.py", line 401, in __get_result
raise self._exception
File "/site-packages/tenacity/asyncio/__init__.py", line 116, in __call__
result = await fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/site-packages/google/genai/_api_client.py", line 1521, in _async_request_once
await errors.APIError.raise_for_async_response(response)
File "/site-packages/google/genai/errors.py", line 247, in raise_for_async_response
await cls.raise_error_async(status_code, response_json, response)
File "/site-packages/google/genai/errors.py", line 271, in raise_error_async
raise ServerError(status_code, response_json, response)
google.genai.errors.ServerError: 500 INTERNAL. {'error': {'code': 500, 'message': 'Internal error encountered.', 'status': 'INTERNAL'}}
Expected Behavior
gemini-3.1-flash-lite should successfully process and transcribe the audio file without throwing a 500 INTERNAL server error, matching the behavior of gemini-3.5-flash.
There is a consistent 500 INTERNAL server error when trying to generate content from audio files using the gemini-3.1-flash-lite model.
The issue occurs specifically when an audio file (tested with .wav and .ogg formats) is uploaded using the Gemini File API (client.files.upload) and then passed to client.models.generate_content.
Key Findings:
Environment
Steps to Reproduce
Here is a minimal, self-contained Python script to reproduce the issue. It generates a small valid 3-second sine-wave WAV file, uploads it to the File API, waits for it to become ACTIVE, and attempts to generate content using gemini-3.1-flash-lite.
Traceback / Error Log
Expected Behavior
gemini-3.1-flash-lite should successfully process and transcribe the audio file without throwing a 500 INTERNAL server error, matching the behavior of gemini-3.5-flash.