BerriAI/litellm · error · ValueError

logging_obj is required

Error message

logging_obj is required

What it means

validate_input_kwargs in the speech-to-completion bridge raises ValueError("logging_obj is required") when kwargs["logging_obj"] is missing, None, or not an instance of litellm.LiteLLMLoggingObj. The logging object is forwarded into the completion call (transformation.py:46) so the bridged request is tracked like any other litellm call; a plain dict, Mock, or None all fail the isinstance check.

Solutions

  1. Create and pass a real logging object: from litellm.litellm_core_utils.logging_handler import LoggingObject (litellm.LiteLLMLoggingObj) and instantiate it per the current signature.
  2. Simplest path: call litellm.speech()/litellm.completion() so litellm constructs the logging object internally.
  3. In tests, patch litellm.completion and construct one genuine LiteLLMLoggingObj rather than a bare Mock.

Example fix

# before
handler.speech(model="gpt-4o-audio-preview", input="hi", voice="alloy", optional_params={}, litellm_params={}, headers={}, custom_llm_provider="openai")  # ValueError: logging_obj is required

# after
from litellm.litellm_core_utils.logging_handler import LoggingObject
log_obj = LoggingObject(user_identifier="", call_type="speech", litellm_params={}, kwargs={})
handler.speech(model="gpt-4o-audio-preview", input="hi", voice="alloy", optional_params={}, litellm_params={}, headers={}, logging_obj=log_obj, custom_llm_provider="openai")
Defensive patterns

Strategy: validation

Validate before calling

from litellm import LiteLLMLoggingObj

def check_logging_obj(kwargs: dict) -> None:
    if not isinstance(kwargs.get("logging_obj"), LiteLLMLoggingObj):
        raise ValueError("speech bridge requires a real LiteLLMLoggingObj instance")

Type guard

from litellm import LiteLLMLoggingObj

def is_valid_logging_obj(value: object) -> bool:
    return isinstance(value, LiteLLMLoggingObj)

Prevention

When it happens

Trigger: Calling the handler directly with logging_obj omitted or None; passing a unittest.mock.Mock or a dataclass stand-in instead of a real Logging object; constructing kwargs in tests where the import was skipped.

Common situations: Test suites mocking everything except logging_obj; custom server adapters that never create a Logging object; older code written against a handler version that tolerated None.

Understand the failure class

Background: "missing required argument" and "the following required arguments were not provided": what required-argument errors mean and how to fix them — this error's family across 20 libraries.

Related errors


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

Appendix: source

Thrown at litellm/endpoints/speech/speech_to_completion_bridge/handler.py:65

        optional_params: Final = kwargs.get("optional_params")
        if optional_params is None or not isinstance(optional_params, dict):
            raise ValueError("optional_params is required")

        litellm_params: Final = kwargs.get("litellm_params")
        if litellm_params is None or not isinstance(litellm_params, dict):
            raise ValueError("litellm_params is required")

        headers = kwargs.get("headers")
        if headers is None or not isinstance(headers, dict):
            raise ValueError("headers is required")

        headers = kwargs.get("headers")
        if headers is None or not isinstance(headers, dict):
            raise ValueError("headers is required")

        logging_obj: Final = kwargs.get("logging_obj")
        if logging_obj is None or not isinstance(logging_obj, LiteLLMLoggingObj):
            raise ValueError("logging_obj is required")

        return SpeechToCompletionBridgeHandlerInputKwargs(
            model=model,
            input=input,
            voice=kwargs.get("voice"),
            optional_params=optional_params,
            litellm_params=litellm_params,
            logging_obj=logging_obj,
            custom_llm_provider=custom_llm_provider,
            headers=headers,
        )

    def speech(
        self,
        model: str,
        input: str,
        voice: str | dict | None,
        optional_params: dict,

View on GitHub (pinned to 77b7c6c40c)