BerriAI/litellm · error · ValueError

model parameter is required but was None. Please provide a v

Error message

model parameter is required but was None. Please provide a valid model name.

What it means

Early guard in get_llm_provider: the model argument is None, so provider resolution is impossible. The ValueError is subsequently wrapped into a BadRequestError ('GetLLMProvider Exception - ...') by the enclosing except block, so callers see a BadRequestError mentioning the None model.

Source

Thrown at litellm/litellm_core_utils/get_llm_provider_logic.py:149

    model: str,
    custom_llm_provider: str | None = None,
    api_base: str | None = None,
    api_key: str | None = None,
    litellm_params: GenericLiteLLMParams | None = None,
) -> tuple[str, str, str | None, str | None]:
    """
    Returns the provider for a given model name - e.g. 'azure/chatgpt-v-2' -> 'azure'

    For router -> Can also give the whole litellm param dict -> this function will extract the relevant details

    Raises Error - if unable to map model to a provider

    Return model, custom_llm_provider, dynamic_api_key, api_base
    """
    try:
        # Early validation - model is required
        if model is None:
            raise ValueError("model parameter is required but was None. Please provide a valid model name.")

        if litellm.LiteLLMProxyChatConfig._should_use_litellm_proxy_by_default(
            litellm_params=cast(LiteLLM_Params | None, litellm_params)
        ):
            return litellm.LiteLLMProxyChatConfig.litellm_proxy_get_custom_llm_provider_info(
                model=model, api_base=api_base, api_key=api_key
            )

        ## IF LITELLM PARAMS GIVEN ##
        if litellm_params:
            if custom_llm_provider is None and api_base is None and api_key is None:
                custom_llm_provider = litellm_params.custom_llm_provider
                api_base = litellm_params.api_base
                api_key = litellm_params.api_key

        dynamic_api_key = None
        # check if llm provider provided
        # AZURE AI-Studio Logic - Azure AI Studio supports AZURE/Cohere

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Find where the None originates: log the value right before the call.
  2. For Router/proxy configs, ensure every model_list entry has model_name and litellm_params.model.
  3. Default to a concrete fallback model when dynamic selection returns nothing.

Example fix

# before
model = os.getenv('MODEL')  # unset -> None
litellm.completion(model=model, messages=msgs)

# after
model = os.getenv('MODEL') or 'gpt-4o-mini'
litellm.completion(model=model, messages=msgs)
Defensive patterns

Strategy: validation

Validate before calling

def model_arg_valid(model) -> bool:
    return isinstance(model, str) and len(model.strip()) > 0

Type guard

function isModelName(v: unknown): v is string {
  return typeof v === 'string' && v.trim().length > 0;
}

Try / catch

try {
  await litellm.completion({ model, messages });
} catch (e) {
  if (e instanceof litellm.BadRequestError && /model parameter is required/.test(e.message)) { /* fix model source */ }
}

Prevention

When it happens

Trigger: Calling litellm.completion(model=None, ...), passing a config field that is unset (router model_list entry without model), or a variable that was never populated (env var read returned None).

Common situations: Router/proxy config YAML missing the model_name/model field, template code with placeholder variables, or dynamic model selection logic that yields None.

Related errors


AI-assisted analysis of BerriAI/litellm@6c2dcb801b (2026-08-15). Data as JSON: /api/errors/eb0d6a9a43351fb3. Report an issue: GitHub.