{"record":{"id":"d6740269236c999e","repo":"BerriAI/litellm","slug":"optional-params-is-required-d67402","errorCode":null,"errorMessage":"optional_params is required","messagePattern":"optional_params is required","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/endpoints/speech/speech_to_completion_bridge/handler.py","lineNumber":49,"sourceCode":"\n    def validate_input_kwargs(self, kwargs: dict) -> SpeechToCompletionBridgeHandlerInputKwargs:\n        from litellm import LiteLLMLoggingObj\n\n        model: Final = kwargs.get(\"model\")\n        if model is None or not isinstance(model, str):\n            raise ValueError(\"model is required\")\n\n        custom_llm_provider: Final = kwargs.get(\"custom_llm_provider\")\n        if custom_llm_provider is None or not isinstance(custom_llm_provider, str):\n            raise ValueError(\"custom_llm_provider is required\")\n\n        input: Final = kwargs.get(\"input\")\n        if input is None or not isinstance(input, str):\n            raise ValueError(\"input is required\")\n\n        optional_params: Final = kwargs.get(\"optional_params\")\n        if optional_params is None or not isinstance(optional_params, dict):\n            raise ValueError(\"optional_params is required\")\n\n        litellm_params: Final = kwargs.get(\"litellm_params\")\n        if litellm_params is None or not isinstance(litellm_params, dict):\n            raise ValueError(\"litellm_params is required\")\n\n        headers = kwargs.get(\"headers\")\n        if headers is None or not isinstance(headers, dict):\n            raise ValueError(\"headers is required\")\n\n        headers = kwargs.get(\"headers\")\n        if headers is None or not isinstance(headers, dict):\n            raise ValueError(\"headers is required\")\n\n        logging_obj: Final = kwargs.get(\"logging_obj\")\n        if logging_obj is None or not isinstance(logging_obj, LiteLLMLoggingObj):\n            raise ValueError(\"logging_obj is required\")\n\n        return SpeechToCompletionBridgeHandlerInputKwargs(","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/endpoints/speech/speech_to_completion_bridge/handler.py#L31-L67","documentation":"Thrown by SpeechToCompletionBridgeHandler.validate_input_kwargs when 'optional_params' is absent from kwargs or is not a dict (handler.py:49). optional_params carries extra call options (e.g. audio voice/format, response_format) that the bridge forwards to the underlying completion() call; it must be a dict even when empty.","triggerScenarios":"Calling speech_to_completion_bridge_handler.speech() directly with optional_params=None or omitted; passing optional_params as a list or object instead of dict.","commonSituations":"Custom direct invocations of the handler; refactors where optional_params is conditionally built and ends up None; mocked tests that skip the argument.","solutions":["Call litellm.audio_speech() instead of the handler directly so optional_params is populated as {} by default","If invoking directly, always pass optional_params={} when there are no extra options","Verify no middleware mutates optional_params to a non-dict value"],"exampleFix":"# before\nhandler.speech(model=m, input=i, voice=v, optional_params=None, litellm_params={}, headers={}, logging_obj=log, custom_llm_provider=\"openai\")\n\n# after\nhandler.speech(model=m, input=i, voice=v, optional_params={}, litellm_params={}, headers={}, logging_obj=log, custom_llm_provider=\"openai\")","handlingStrategy":"validation","validationCode":"optional_params = optional_params if isinstance(optional_params, dict) else {}\n# then pass through, or simply rely on litellm.audio_speech() defaults","typeGuard":"def is_optional_params_valid(params: object) -> bool:\n    return isinstance(params, dict)","tryCatchPattern":"try:\n    handler.speech(..., optional_params=optional_params, ...)\nexcept ValueError as e:\n    if \"optional_params is required\" in str(e):\n        optional_params = {}\n        # retry once with corrected args","preventionTips":["Default optional_params to {} wherever you build TTS kwargs","Call litellm.audio_speech() instead of the internal handler","Add a shape check on dynamically assembled kwargs before invocation"],"tags":["validation","tts","optional-params"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}