{"record":{"id":"0d6f2899b5dfe7cb","repo":"huggingface/smolagents","slug":"please-install-litellm-extra-to-use-litellmroute","errorCode":null,"errorMessage":"Please install 'litellm' extra to use LiteLLMRouterModel: `pip install 'smolagents[litellm]'`","messagePattern":"Please install 'litellm' extra to use LiteLLMRouterModel: `pip install 'smolagents\\[litellm\\]'`","errorType":"exception","errorClass":"ModuleNotFoundError","httpStatus":null,"severity":"error","filePath":"src/smolagents/models.py","lineNumber":1450,"sourceCode":"        flatten_messages_as_text: bool | None = None,\n        **kwargs,\n    ):\n        self.client_kwargs = {\n            \"model_list\": model_list,\n            **(client_kwargs or {}),\n        }\n        super().__init__(\n            model_id=model_id,\n            custom_role_conversions=custom_role_conversions,\n            flatten_messages_as_text=flatten_messages_as_text,\n            **kwargs,\n        )\n\n    def create_client(self):\n        try:\n            from litellm.router import Router\n        except ModuleNotFoundError as e:\n            raise ModuleNotFoundError(\n                \"Please install 'litellm' extra to use LiteLLMRouterModel: `pip install 'smolagents[litellm]'`\"\n            ) from e\n        return Router(**self.client_kwargs)\n\n\nclass InferenceClientModel(ApiModel):\n    \"\"\"A class to interact with Hugging Face's Inference Providers for language model interaction.\n\n    This model allows you to communicate with Hugging Face's models using Inference Providers. It can be used in both serverless mode, with a dedicated endpoint, or even with a local URL, supporting features like stop sequences and grammar customization.\n\n    Providers include Cerebras, Cohere, Fal, Fireworks, HF-Inference, Hyperbolic, Nebius, Novita, Replicate, SambaNova, Together, and more.\n\n    Parameters:\n        model_id (`str`, *optional*, default `\"Qwen/Qwen3-Next-80B-A3B-Thinking\"`):\n            The Hugging Face model ID to be used for inference.\n            This can be a model identifier from the Hugging Face model hub or a URL to a deployed Inference Endpoint.\n            Currently, it defaults to `\"Qwen/Qwen3-Next-80B-A3B-Thinking\"`, but this may change in the future.\n        provider (`str`, *optional*):","sourceCodeStart":1432,"sourceCodeEnd":1468,"githubUrl":"https://github.com/huggingface/smolagents/blob/30bb1161095dbae2271e6bc3cc4c219cc3897a57/src/smolagents/models.py#L1432-L1468","documentation":"LiteLLMRouterModel.create_client tries to import litellm.router.Router; the ModuleNotFoundError is caught and re-raised with a friendly message telling you the `litellm` optional extra is not installed. smolagents keeps heavy provider SDKs optional, so the class is importable but unusable without the extra.","triggerScenarios":"Instantiating LiteLLMRouterModel (which calls create_client from __init__) in an environment where the litellm package is absent, e.g. `pip install smolagents` without extras.","commonSituations":"Fresh environment with base smolagents install; CI caching a requirements file that predates litellm usage; deploying to a slim Docker image without extras; multiple virtualenvs and running in the wrong one.","solutions":["Install the extra: `pip install 'smolagents[litellm]'` (or plain `pip install litellm`).","Verify the active environment: `python -c \"import litellm\"` in the same interpreter you run the app from.","Pin litellm in requirements/pyproject once installed so builds stay reproducible."],"exampleFix":"# before\npip install smolagents\nmodel = LiteLLMRouterModel(...)  # ModuleNotFoundError: install 'litellm' extra\n\n# after\npip install 'smolagents[litellm]'","handlingStrategy":"validation","validationCode":"try:\n    import litellm.router  # noqa\n    can_use = True\nexcept ModuleNotFoundError:\n    can_use = False\nassert can_use, \"pip install 'smolagents[litellm]'\"","typeGuard":"null","tryCatchPattern":"try:\n    model = LiteLLMRouterModel(...)\nexcept ModuleNotFoundError as e:\n    print(\"Missing extra:\", e)\n    sys.exit(1)","preventionTips":["Declare extras in requirements: smolagents[litellm].","Add an environment check step in CI that imports optional deps your code uses."],"tags":["litellm","missing-dependency","pip-extra","installation"],"backgroundTag":"missing-optional-dependency","analyzedSha":"30bb1161095dbae2271e6bc3cc4c219cc3897a57","analyzedAt":"2026-08-28T18:52:54.169Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}