BerriAI/litellm · error · Exception

'models' param not in kwargs

Error message

'models' param not in kwargs

What it means

batch_completion_models_all_responses() fans a prompt out to several models concurrently and requires the model list via a models kwarg (it even strips a conflicting model kwarg first). If models is not present in kwargs it raises this generic Exception before doing any work. The sibling batch_completion() uses positional model args, which is why callers frequently mix the two conventions up.

Solutions

  1. Pass the model list as the models kwarg: batch_completion_models_all_responses(models=[...], **kwargs)
  2. Remove any model kwarg — it is intentionally ignored/popped by this function
  3. If you wanted per-call model strings instead, use batch_completion(model=..., ...)
  4. Guard dynamic kwargs: assert 'models' in kwargs before calling

Example fix

# before
responses = batch_completion_models_all_responses(
    model=["gpt-4o-mini", "claude-3-5-haiku"],
    messages=[{"role": "user", "content": "hello"}],
)

# after
responses = batch_completion_models_all_responses(
    models=["gpt-4o-mini", "claude-3-5-haiku"],
    messages=[{"role": "user", "content": "hello"}],
)
Defensive patterns

Strategy: validation

Validate before calling

if "models" not in kwargs or not kwargs["models"]:
    raise ValueError("models kwarg (str or list[str]) is required")
responses = batch_completion_models_all_responses(**kwargs)

Type guard

def has_models_kwarg(kwargs: dict) -> bool:
    return "models" in kwargs

Try / catch

try:
    responses = batch_completion_models_all_responses(**kwargs)
except Exception as e:
    if "'models' param not in kwargs" in str(e):
        raise TypeError("call with models=[...] kwarg") from e
    raise

Prevention

When it happens

Trigger: Calling batch_completion_models_all_responses(prompt=..., model=["a","b"]) — model is popped and discarded, models is missing; passing models positionally; refactoring from batch_completion(model=[...], ...) without renaming the kwarg to models.

Common situations: Confusing the two batch helpers' signatures; dynamic kwargs construction where the models key is conditionally absent; tutorials mixing batch_completion and batch_completion_models_all_responses examples.

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

Appendix: source

Thrown at litellm/batch_completion/main.py:230

            - Other keyword arguments to be passed to the completion function.

    Returns:
        list: A list of responses from the language models that responded.

    Note:
        This function utilizes a ThreadPoolExecutor to parallelize requests to multiple models.
        It sends requests concurrently and collects responses from all models that respond.
    """
    import concurrent.futures

    # ANSI escape codes for colored output

    if "model" in kwargs:
        kwargs.pop("model")
    if "models" in kwargs:
        models = kwargs.pop("models")
    else:
        raise Exception("'models' param not in kwargs")

    if isinstance(models, str):
        models = [models]
    elif isinstance(models, (list, tuple)):
        models = list(models)
    else:
        raise TypeError("'models' must be a string or list of strings")

    if len(models) == 0:
        return []

    responses: Final = []

    with concurrent.futures.ThreadPoolExecutor(max_workers=len(models)) as executor:
        futures: Final = [executor.submit(litellm.completion, *args, model=model, **kwargs) for model in models]

        for future in futures:
            try:

View on GitHub (pinned to 77b7c6c40c)