BerriAI/litellm · error · ValueError

messages is required

Error message

messages is required

What it means

The bridge requires 'messages' to be a non-None list before transforming a chat-completions request into a Responses API request. The messages list is what gets converted into Responses API input items (message, function_call, function_call_output). A missing, None, or non-list messages value aborts the call up front.

Solutions

  1. Call litellm.completion(model, messages=[...]) so validation happens upstream with better errors
  2. Ensure messages is a list of dicts each with role and content keys
  3. If you only have a prompt string, wrap it: messages=[{"role":"user","content":prompt}]
  4. Type-check kwargs before calling the bridge directly

Example fix

// before
handler.completion(model=m, messages=("user", "hi"), ...)  # ValueError: messages is required

// after
handler.completion(model=m, messages=[{"role": "user", "content": "hi"}], ...)
Defensive patterns

Strategy: validation

Validate before calling

def messages_are_valid(messages) -> bool:
    return isinstance(messages, list) and all(
        isinstance(m, dict) and isinstance(m.get("role"), str) for m in messages
    )

Type guard

def is_message_list(messages) -> bool:
    return isinstance(messages, list)

Try / catch

try:
    handler.completion(**kwargs)
except ValueError as e:
    if "messages is required" in str(e):
        raise TypeError("messages must be a list of {role, content} dicts") from e
    raise

Prevention

When it happens

Trigger: Direct bridge invocation without messages; passing messages as a tuple/generator/SingleMessage dict instead of a list; a custom pipeline that consumed or reassigned the messages variable before forwarding.

Common situations: Adapters converting single-prompt APIs to litellm's message format; refactors that changed messages to an iterator; tests with hand-built kwargs.

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

Appendix: source

Thrown at litellm/completion_extras/litellm_responses_transformation/handler.py:118

        return response

    def validate_input_kwargs(self, kwargs: dict) -> ResponsesToCompletionBridgeHandlerInputKwargs:
        from litellm import LiteLLMLoggingObj
        from litellm.types.utils import ModelResponse

        typed_kwargs: Final[dict[str, object]] = kwargs

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

        custom_llm_provider: Final = typed_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")

        messages: Final = typed_kwargs.get("messages")
        if messages is None or not isinstance(messages, list):
            raise ValueError("messages is required")

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

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

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

        model_response: Final = typed_kwargs.get("model_response")
        if model_response is None or not isinstance(model_response, ModelResponse):
            raise ValueError("model_response is required")

        logging_obj: Final = typed_kwargs.get("logging_obj")

View on GitHub (pinned to 77b7c6c40c)