BerriAI/litellm · error · Exception

model not set

Error message

model not set

What it means

ahealth_check() runs a real minimal call against the model described in model_params; the first thing it does is read model_params.get('model'). When the key is missing or None it raises Exception('model not set') before doing anything else.

Source

Thrown at litellm/main.py:8379

    litellm_logging_obj: Final = Logging(
        model="",
        messages=[],
        stream=False,
        call_type="acompletion",
        litellm_call_id=str(uuid.uuid4()),
        start_time=datetime.datetime.now(),
        function_id=str(uuid.uuid4()),
        log_raw_request_response=True,
    )
    model_params["litellm_logging_obj"] = litellm_logging_obj
    model_params = HealthCheckHelpers._update_model_params_with_health_check_tracking_information(
        model_params=model_params
    )
    #########################################################
    try:
        model: str | None = model_params.get("model", None)
        if model is None:
            raise Exception("model not set")

        if model in litellm.model_cost and mode is None:
            mode = litellm.model_cost[model].get("mode")

        custom_llm_provider_from_params: Final = model_params.get("custom_llm_provider", None)
        api_base_from_params: Final = model_params.get("api_base", None)
        api_key_from_params: Final = model_params.get("api_key", None)

        model, custom_llm_provider, _, _ = get_llm_provider(
            model=model,
            custom_llm_provider=custom_llm_provider_from_params,
            api_base=api_base_from_params,
            api_key=api_key_from_params,
        )
        if model in litellm.model_cost and mode is None:
            mode = litellm.model_cost[model].get("mode")

        model_params["cache"] = {"no-cache": True}  # don't used cached responses for making health check calls

View on GitHub (pinned to 77b7c6c40c)

Solutions

  1. Include the model key: await litellm.ahealth_check({'model': 'openai/gpt-4o-mini', 'messages': [...]})
  2. Validate the params dict has a truthy 'model' before calling
  3. In proxy deployments, make sure the model exists in config so the check receives it

Example fix

# before
await litellm.ahealth_check({"messages": [{"role": "user", "content": "hi"}]})

# after
await litellm.ahealth_check({"model": "openai/gpt-4o-mini", "messages": [{"role": "user", "content": "hi"}]})
Defensive patterns

Strategy: validation

Validate before calling

if not model_params.get("model"):
    raise ValueError("health check requires model_params['model']")
result = await litellm.ahealth_check(model_params)

Try / catch

try:
    result = await litellm.ahealth_check(model_params)
except Exception as e:
    if "model not set" in str(e):
        raise RuntimeError("health-check params missing 'model'") from e
    raise

Prevention

When it happens

Trigger: await litellm.ahealth_check({'messages': [{'role': 'user', 'content': 'hi'}]}) — a params dict without 'model'; model loaded from config where the key is absent; model resolved to None dynamically.

Common situations: Health-check wiring copied from completion() calls that pass model as a separate argument; proxy config templates missing the model field; optional config keys defaulting to None.

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