BerriAI/litellm · error · ValueError

optional_params is required

Error message

optional_params is required

What it means

validate_input_kwargs in the speech-to-completion bridge raises ValueError("optional_params is required") when kwargs["optional_params"] is missing, None, or not a dict. optional_params carries per-request options (response_format, etc.); transform_request filters it against OPENAI_CHAT_COMPLETION_PARAMS and folds the survivors into the completion call (transformation.py:24-26).

Solutions

  1. Always pass a dict, even an empty one: handler.speech(..., optional_params={}, ...).
  2. If your options arrive as a JSON string, parse first: optional_params=json.loads(raw).
  3. Prefer litellm.speech(), which constructs optional_params from its own keyword arguments.

Example fix

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

# after
handler.speech(model="gpt-4o-audio-preview", input="hi", voice="alloy", optional_params={}, litellm_params={}, headers={}, logging_obj=log, custom_llm_provider="openai")
Defensive patterns

Strategy: validation

Validate before calling

def check_optional_params(kwargs: dict) -> None:
    if not isinstance(kwargs.get("optional_params"), dict):
        raise ValueError("speech bridge requires dict 'optional_params' (use {} if none)")

Type guard

def is_valid_optional_params(value: object) -> bool:
    return isinstance(value, dict)

Prevention

When it happens

Trigger: Calling the bridge handler directly with optional_params omitted or set to None; forwarding a non-dict such as a list of params or a JSON string.

Common situations: Custom integrations that only pass the fields they consider relevant; refactors where optional_params was renamed; defaults of None leaking from config loaders.

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/d6740269236c999e. Report an issue: GitHub.

Appendix: source

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

    def validate_input_kwargs(self, kwargs: dict) -> SpeechToCompletionBridgeHandlerInputKwargs:
        from litellm import LiteLLMLoggingObj

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

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

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

        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(

View on GitHub (pinned to 77b7c6c40c)