{"record":{"id":"cb68064d6cf0b374","repo":"BerriAI/litellm","slug":"calculate-request-duration-does-not-accept-bare-st","errorCode":null,"errorMessage":"calculate_request_duration does not accept bare str inputs. Pass bytes, an open file handle, a (filename, content) tuple, or a pathlib.Path.","messagePattern":"calculate_request_duration does not accept bare str inputs\\. Pass bytes, an open file handle, a \\(filename, content\\) tuple, or a pathlib\\.Path\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/audio_utils/utils.py","lineNumber":279,"sourceCode":"    \"\"\"\n    try:\n        import soundfile as sf\n    except ImportError:\n        # soundfile not available, cannot extract duration\n        return None\n\n    try:\n        import io\n\n        # Handle different file input types\n        file_content: bytes | None = None\n\n        if isinstance(file, (bytes, bytearray)):\n            # Raw bytes\n            file_content = bytes(file)\n        elif isinstance(file, str):\n            # Bare strings are rejected — see extract_file_data.\n            raise ValueError(\n                \"calculate_request_duration does not accept bare str inputs. \"\n                \"Pass bytes, an open file handle, a (filename, content) \"\n                \"tuple, or a pathlib.Path.\"\n            )\n        elif isinstance(file, os.PathLike):\n            # File path (PathLike): SDK convenience.\n            with open(str(file), \"rb\") as f:\n                file_content = f.read()\n        elif isinstance(file, tuple):\n            # Tuple format: (filename, content, optional content_type)\n            if len(file) >= 2:\n                content: Final = file[1]\n                if isinstance(content, bytes):\n                    file_content = content\n                elif hasattr(content, \"read\") and not isinstance(content, (str, os.PathLike)):\n                    # File-like object in tuple\n                    current_pos: Final = getattr(content, \"tell\", lambda: None)()\n                    # Seek to start to ensure we read the entire content","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/BerriAI/litellm/blob/77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8/litellm/litellm_core_utils/audio_utils/utils.py#L261-L297","documentation":"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.","triggerScenarios":"Thrown at litellm/litellm_core_utils/audio_utils/utils.py:279 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","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'))."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"77b7c6c40c0c5aa5fbcb1d6a1825ac39ca8829b8","analyzedAt":"2026-08-18T11:44:31.656Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}