BerriAI/litellm · error · ValueError
calculate_request_duration does not accept bare str inputs…
Error message
calculate_request_duration does not accept bare str inputs. Pass bytes, an open file handle, a (filename, content) tuple, or a pathlib.Path.
What it means
calculate_request_duration hit its bare-str guard: `file` was passed as a plain string, which is rejected (same rationale as extract_file_data — proxy-supplied strings are untrusted) in favor of bytes, file handles, tuples or Paths.
Solutions
- Pass bytes, an open file handle, a (filename, content) tuple, or a pathlib.Path instead of a bare string.
- Open the file yourself: calculate_request_duration(open(path,'rb')).
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at litellm/litellm_core_utils/audio_utils/utils.py:279 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/cb68064d6cf0b374.
Report an issue: GitHub.
Appendix: source
Thrown at litellm/litellm_core_utils/audio_utils/utils.py:279
"""
try:
import soundfile as sf
except ImportError:
# soundfile not available, cannot extract duration
return None
try:
import io
# Handle different file input types
file_content: bytes | None = None
if isinstance(file, (bytes, bytearray)):
# Raw bytes
file_content = bytes(file)
elif isinstance(file, str):
# Bare strings are rejected — see extract_file_data.
raise ValueError(
"calculate_request_duration does not accept bare str inputs. "
"Pass bytes, an open file handle, a (filename, content) "
"tuple, or a pathlib.Path."
)
elif isinstance(file, os.PathLike):
# File path (PathLike): SDK convenience.
with open(str(file), "rb") as f:
file_content = f.read()
elif isinstance(file, tuple):
# Tuple format: (filename, content, optional content_type)
if len(file) >= 2:
content: Final = file[1]
if isinstance(content, bytes):
file_content = content
elif hasattr(content, "read") and not isinstance(content, (str, os.PathLike)):
# File-like object in tuple
current_pos: Final = getattr(content, "tell", lambda: None)()
# Seek to start to ensure we read the entire contentView on GitHub (pinned to 77b7c6c40c)