{"record":{"id":"eb0d6a9a43351fb3","repo":"BerriAI/litellm","slug":"model-parameter-is-required-but-was-none-please-p","errorCode":null,"errorMessage":"model parameter is required but was None. Please provide a valid model name.","messagePattern":"model parameter is required but was None\\. Please provide a valid model name\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"litellm/litellm_core_utils/get_llm_provider_logic.py","lineNumber":149,"sourceCode":"    model: str,\n    custom_llm_provider: str | None = None,\n    api_base: str | None = None,\n    api_key: str | None = None,\n    litellm_params: GenericLiteLLMParams | None = None,\n) -> tuple[str, str, str | None, str | None]:\n    \"\"\"\n    Returns the provider for a given model name - e.g. 'azure/chatgpt-v-2' -> 'azure'\n\n    For router -> Can also give the whole litellm param dict -> this function will extract the relevant details\n\n    Raises Error - if unable to map model to a provider\n\n    Return model, custom_llm_provider, dynamic_api_key, api_base\n    \"\"\"\n    try:\n        # Early validation - model is required\n        if model is None:\n            raise ValueError(\"model parameter is required but was None. Please provide a valid model name.\")\n\n        if litellm.LiteLLMProxyChatConfig._should_use_litellm_proxy_by_default(\n            litellm_params=cast(LiteLLM_Params | None, litellm_params)\n        ):\n            return litellm.LiteLLMProxyChatConfig.litellm_proxy_get_custom_llm_provider_info(\n                model=model, api_base=api_base, api_key=api_key\n            )\n\n        ## IF LITELLM PARAMS GIVEN ##\n        if litellm_params:\n            if custom_llm_provider is None and api_base is None and api_key is None:\n                custom_llm_provider = litellm_params.custom_llm_provider\n                api_base = litellm_params.api_base\n                api_key = litellm_params.api_key\n\n        dynamic_api_key = None\n        # check if llm provider provided\n        # AZURE AI-Studio Logic - Azure AI Studio supports AZURE/Cohere","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/BerriAI/litellm/blob/6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d/litellm/litellm_core_utils/get_llm_provider_logic.py#L131-L167","documentation":"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.","triggerScenarios":"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).","commonSituations":"Router/proxy config YAML missing the model_name/model field, template code with placeholder variables, or dynamic model selection logic that yields None.","solutions":["Find where the None originates: log the value right before the call.","For Router/proxy configs, ensure every model_list entry has model_name and litellm_params.model.","Default to a concrete fallback model when dynamic selection returns nothing."],"exampleFix":"# before\nmodel = os.getenv('MODEL')  # unset -> None\nlitellm.completion(model=model, messages=msgs)\n\n# after\nmodel = os.getenv('MODEL') or 'gpt-4o-mini'\nlitellm.completion(model=model, messages=msgs)","handlingStrategy":"validation","validationCode":"def model_arg_valid(model) -> bool:\n    return isinstance(model, str) and len(model.strip()) > 0","typeGuard":"function isModelName(v: unknown): v is string {\n  return typeof v === 'string' && v.trim().length > 0;\n}","tryCatchPattern":"try {\n  await litellm.completion({ model, messages });\n} catch (e) {\n  if (e instanceof litellm.BadRequestError && /model parameter is required/.test(e.message)) { /* fix model source */ }\n}","preventionTips":["Assert model is a non-empty string before every call.","Give router/proxy model_list entries explicit model_name and litellm_params.model.","Default dynamic model selection to a known-good fallback."],"tags":["validation","model-none","config","bad-request"],"backgroundTag":null,"analyzedSha":"6c2dcb801bf2b75c18f1bb24140e7cf57465cc4d","analyzedAt":"2026-08-15T07:12:03.035Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}