BerriAI/litellm · error · ValueError

Could not extract file content from audio_file

Error message

Could not extract file content from audio_file

What it means

Safety-net guard in process_audio_file: the input passed an earlier isinstance/hasattr check (e.g. an object exposing .read) but reading it yielded no usable content, so the helper raises instead of sending an empty audio payload.

Solutions

  1. Ensure the audio file object yields content: bytes are non-empty and file handles are opened in binary read mode.
  2. Verify the file exists and is readable before passing it.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at litellm/litellm_core_utils/audio_utils/utils.py:110 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of BerriAI/litellm@77b7c6c40c (2026-08-18). Data as JSON: /api/errors/a485bf6dba7962a1. Report an issue: GitHub.

Appendix: source

Thrown at litellm/litellm_core_utils/audio_utils/utils.py:110

                file_content = content.read()
                if hasattr(content, "seek"):
                    content.seek(0)
            else:
                raise ValueError(f"Unsupported content type in tuple: {type(content)}")
        else:
            raise ValueError("Tuple must have at least 2 elements: (filename, content)")
    elif hasattr(audio_file, "read") and not isinstance(audio_file, (str, bytes, bytearray, tuple, os.PathLike)):
        # File-like object (IO) - check this after all other types
        filename = getattr(audio_file, "name", "audio.wav")
        file_content = audio_file.read()
        # Reset file pointer if possible
        if hasattr(audio_file, "seek"):
            audio_file.seek(0)
    else:
        raise ValueError(f"Unsupported audio_file type: {type(audio_file)}")

    if file_content is None:
        raise ValueError("Could not extract file content from audio_file")

    # Determine content type using LiteLLM's file type utilities
    content_type = "audio/wav"  # Default fallback
    if filename:
        try:
            # Extract extension from filename
            extension: Final = filename.split(".")[-1].lower() if "." in filename else "wav"
            content_type = get_file_mime_type_from_extension(extension)
        except ValueError:
            # If extension is not recognized, fallback to audio/wav
            content_type = "audio/wav"

    return ProcessedAudioFile(file_content=file_content, filename=filename, content_type=content_type)


BARE_ISO_639_1_TO_BCP47: Final = {
    "en": "en-US",
    "es": "es-ES",

View on GitHub (pinned to 77b7c6c40c)