BerriAI/litellm · error · BadRequestError

OllamaException: Invalid Model/Model not loaded - {original_

Error message

OllamaException: Invalid Model/Model not loaded - {original_exception}

What it means

litellm maps Ollama errors containing 'no such file or directory' to litellm.BadRequestError with message 'OllamaException: Invalid Model/Model not loaded'. The named model's weights are absent from the local Ollama instance, so the runtime cannot open its files.

Source

Thrown at litellm/litellm_core_utils/exception_mapping_utils.py:1809

    raise cast(Exception, original_exception)


def _map_ollama_exception(
    *,
    model: str,
    original_exception: _ProviderHTTPException,
    custom_llm_provider: str,
    error_str: str,
    exception_type: str,
    exception_provider: str,
    extra_information: str,
) -> None:
    if isinstance(original_exception, dict):
        error_str = original_exception.get("error", "")
    else:
        error_str = str(original_exception)
    if "no such file or directory" in error_str:
        raise BadRequestError(
            message=f"OllamaException: Invalid Model/Model not loaded - {original_exception}",
            model=model,
            llm_provider="ollama",
            response=getattr(original_exception, "response", None),
        )
    elif "Failed to establish a new connection" in error_str:
        raise ServiceUnavailableError(
            message=f"OllamaException: {original_exception}",
            llm_provider="ollama",
            model=model,
            response=getattr(original_exception, "response", None),
        )
    elif "Invalid response object from API" in error_str:
        raise BadRequestError(
            message=f"OllamaException: {original_exception}",
            llm_provider="ollama",
            model=model,
            response=getattr(original_exception, "response", None),

View on GitHub (pinned to 6c2dcb801b)

Solutions

  1. Run `ollama pull <model>` with the exact tag you reference
  2. Verify with `ollama list` that the tag matches the model string passed to litellm
  3. If using a remote/custom host, confirm OLLAMA_API_BASE points at the machine that has the model
  4. In containers, ensure the models volume is mounted and OLLAMA_MODELS matches

Example fix

# before
litellm.completion(model='ollama/llama3:70b', messages=msgs)  # never pulled
# after
# shell: ollama pull llama3:70b
litellm.completion(model='ollama/llama3:70b', messages=msgs)
Defensive patterns

Strategy: validation

Validate before calling

import requests, os
base = os.environ.get('OLLAMA_API_BASE', 'http://localhost:11434')
tags = {m['name'] for m in requests.get(f'{base}/api/tags', timeout=5).json().get('models', [])}
assert 'llama3:70b' in tags, f'pull it first: ollama pull llama3:70b (have: {tags})'

Type guard

import litellm

def is_ollama_model_missing(e: Exception) -> bool:
    return isinstance(e, litellm.BadRequestError) and 'Model not loaded' in str(e)

Try / catch

try:
    litellm.completion(model='ollama/llama3', messages=msgs)
except litellm.BadRequestError as e:
    if 'Model not loaded' in str(e):
        subprocess.run(['ollama', 'pull', 'llama3'])
        return litellm.completion(model='ollama/llama3', messages=msgs)
    raise

Prevention

When it happens

Trigger: Calling model='ollama/...' for a model that was never pulled (or whose tag/files vanished from OLLAMA_MODELS storage) - Ollama raises a file-not-found error and litellm surfaces it as this BadRequestError.

Common situations: Fresh machines where `ollama pull` was skipped, typo'd model tags ('llama3' vs 'llama3:8b'), custom OLLAMA_MODELS dirs not mounted in containers, or models removed during cleanup.

Related errors


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