BerriAI/litellm · error · ValueError

headers is required

Error message

headers is required

What it means

validate_input_kwargs in the speech-to-completion bridge raises ValueError("headers is required") when kwargs["headers"] is missing, None, or not a dict. headers (incoming request headers) are forwarded into the completion call (transformation.py:45) so auth and client hints survive the bridge. This is the FIRST of two identical checks (lines 55-57 and 59-61) — this instance is the one that actually fires.

Solutions

  1. Pass a plain dict, even empty: handler.speech(..., headers={}, ...).
  2. Convert httpx objects: headers=dict(httpx_headers).
  3. Route through litellm.speech(), which supplies headers from its standard path.

Example fix

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

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

Strategy: validation

Validate before calling

def check_headers(kwargs: dict) -> None:
    if not isinstance(kwargs.get("headers"), dict):
        raise ValueError("speech bridge requires plain dict 'headers' (use {} or dict(httpx.Headers(...)))")

Type guard

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

Prevention

When it happens

Trigger: Calling the bridge handler directly without a headers argument; passing headers=None; passing an httpx.Headers object instead of a plain dict.

Common situations: Standalone scripts adapted from proxy code where headers came from the inbound request; passing httpx.Headers instead of dict(headers); test kwargs omitting the field.

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

Appendix: source

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

        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(
            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,

View on GitHub (pinned to 77b7c6c40c)