BerriAI/litellm · error · Exception
'models' param not in kwargs
Error message
'models' param not in kwargs
What it means
Generic Exception raised by litellm.batch_completion_models when the kwargs dict does not contain a 'models' key. The function is designed to be called as batch_completion_models(**kwargs) with 'models' supplied among the kwargs; it pops 'models' (and 'model') out and fans the rest out to litellm.completion per model. Without 'models' there is nothing to parallelize.
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 6c2dcb801b)
Solutions
- Call it as litellm.batch_completion_models(models=['gpt-4o', 'claude-3-5-sonnet'], messages=[...]).
- If you meant many prompts for one model, use litellm.batch_completion(models='gpt-4o', messages=[...]) instead.
- Ensure 'models' is a keyword argument, not positional.
Example fix
# before
litellm.batch_completion_models(["gpt-4o", "claude-3-5-sonnet"], messages=[{"role": "user", "content": "hi"}])
# after
litellm.batch_completion_models(models=["gpt-4o", "claude-3-5-sonnet"], messages=[{"role": "user", "content": "hi"}]) Defensive patterns
Strategy: validation
Validate before calling
if "models" not in kwargs or not kwargs["models"]:
raise ValueError("batch_completion_models requires a non-empty 'models' kwarg")
kwargs.setdefault("models", list(kwargs["models"])) Type guard
def is_valid_batch_models_arg(kwargs: dict) -> bool:
return isinstance(kwargs.get("models"), (str, list, tuple)) and len(kwargs.get("models", ())) or isinstance(kwargs.get("models"), str) Prevention
- Always call batch_completion_models(models=..., ...) with models as a keyword.
- Use batch_completion (singular model, many prompts) when you have one model.
- Add a wrapper function with an explicit models: list[str] parameter to get static checking.
When it happens
Trigger: Calling litellm.batch_completion_models() without a models kwarg, e.g. passing models as a positional arg (unsupported) or forgetting it entirely: litellm.batch_completion_models(prompt='hi'). Note 'model' is silently popped first, so passing only model=... does not help.
Common situations: Confusing batch_completion_models (list of models, one prompt) with batch_completions (list of prompts); passing models positionally because the signature accepts *args for completion args; refactoring that drops the kwarg.
Related errors
- 'models' must be a string or list of strings
- Invalid value passed in for aget_assistants. Only bool or No
- Invalid value passed in for async_create_assistants. Only bo
- Invalid value passed in for async_delete_assistants. Only bo
- duration needs to be one of ["daily", "weekly", "monthly", "
AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15).
Data as JSON: /api/errors/fc5288be39e955c2.
Report an issue: GitHub.