Skip to content

[BUG] LiteLLM fallback is reported as not installed with litellm older than 1.97.0 (since 1.15.31) #8723

Closed

Description

@pylaterreur

Description

Since crewAI 1.15.31, a model that needs the LiteLLM fallback can't be built when the installed litellm is older than 1.97.0. LLM(...) raises ImportError: ... and the LiteLLM fallback package is not installed, even though litellm is installed.

#8676 made _ensure_litellm() (lib/crewai/src/crewai/llm.py) import ChatCompletionDeltaCustomToolCall from litellm.types.utils. litellm added that class in 1.97.0. On older releases the import raises ImportError, which _ensure_litellm() takes to mean that litellm is missing. The name is only used in a local variable annotation in _ahandle_streaming_response, which Python never evaluates, so the import isn't needed at runtime.

Steps to Reproduce

  1. pip install crewai==1.15.32 litellm==1.95.0 (the same happens with crewai 1.15.31 and with litellm 1.96.0).
  2. Run the script below. It makes no network requests.

Expected behavior

The LiteLLM fallback loads whenever litellm can be imported, and the script prints LLM is_litellm = True. That is what crewai 1.15.30 prints, and what 1.15.31/1.15.32 print with litellm 1.97.0.

Screenshots/Code snippets

import os

os.environ["LITELLM_LOCAL_MODEL_COST_MAP"] = "True"  # keep litellm offline

from crewai import LLM

llm = LLM(model="openai/qwen-turbo")  # no native model by that name -> LiteLLM
print(type(llm).__name__, "is_litellm =", llm.is_litellm)

Operating System

Other (specify in additional context)

Python Version

3.12

crewAI Version

1.15.32 (also 1.15.31)

crewAI Tools Version

Not installed

Virtual Environment

Venv

Evidence

ImportError: Unable to initialize LLM with model 'openai/qwen-turbo'. The model did not match any supported native provider (openai, anthropic, claude, azure, azure_openai, google, gemini, bedrock, aws, openrouter, deepseek, ollama, ollama_chat, hosted_vllm, cerebras, dashscope, snowflake, deepinfra), and the LiteLLM fallback package is not installed.

The script's output on Python 3.12:

crewai litellm 1.95.0 litellm 1.96.0 litellm 1.97.0
1.15.30 works works works
1.15.31 ImportError ImportError works
1.15.32 ImportError ImportError works

Possible Solution

Import ChatCompletionDeltaCustomToolCall only under TYPE_CHECKING, where it is already imported, and drop the runtime import and the global rebinding in _ensure_litellm(). A PR follows.

Separately, the error could say why litellm failed to import, because "not installed" is misleading when litellm is installed.

Additional context

OS: Ubuntu 25.10.

crewai[litellm] pins litellm 1.100.4, but litellm is often installed separately: the error message itself suggests pip install litellm, and other packages' constraints can hold litellm back. For example, every litellm release after 1.95.0 needs aiohttp 3.14.2 or later, so a project that caps aiohttp below that gets litellm 1.95.0. This broke the CrewAI instrumentation tests of alibaba/loongsuite-python (alibaba/loongsuite-python#290).

This report was drafted with an AI coding assistant (Claude Code), per CONTRIBUTING.md (llm-generated).

🤖 Generated with Claude Code

https://claude.ai/code/session_01GwUvhmzgfkiZ6vo4uGyesN

Activity

  1. pylaterreur commented on Oct 30, 2026

    @pylaterreur
    Author

    Fixed by #8777. Closing.

    🤖 Generated with Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions