huggingface/smolagents · error · ModuleNotFoundError
Please install 'openai' extra to use AzureOpenAIModel: `pip
Error message
Please install 'openai' extra to use AzureOpenAIModel: `pip install 'smolagents[openai]'`
What it means
AzureOpenAIModel.create_client needs the openai package (openai.AzureOpenAI client); if absent, the ModuleNotFoundError is re-raised telling you to install the `openai` extra. As with other model classes, the import is deferred to client creation, so the error appears at construction time, not import time.
Source
Thrown at src/smolagents/models.py:1849
client_kwargs.update(
{
"api_version": api_version,
"azure_endpoint": azure_endpoint,
}
)
super().__init__(
model_id=model_id,
api_key=api_key,
client_kwargs=client_kwargs,
custom_role_conversions=custom_role_conversions,
**kwargs,
)
def create_client(self):
try:
import openai
except ModuleNotFoundError as e:
raise ModuleNotFoundError(
"Please install 'openai' extra to use AzureOpenAIModel: `pip install 'smolagents[openai]'`"
) from e
return openai.AzureOpenAI(**self.client_kwargs)
AzureOpenAIServerModel = AzureOpenAIModel
class AmazonBedrockModel(ApiModel):
"""
A model class for interacting with Amazon Bedrock Server models through the Bedrock API.
This class provides an interface to interact with various Bedrock language models,
allowing for customized model inference, guardrail configuration, message handling,
and other parameters allowed by boto3 API.
Authentication:View on GitHub (pinned to 30bb116109)
Solutions
- Install the extra: `pip install 'smolagents[openai]'`.
- Verify with `python -c "import openai; print(openai.__version__)"` in the runtime interpreter.
- Commit the extra to your dependency manifest (requirements.txt / pyproject).
Example fix
# before pip install smolagents model = AzureOpenAIModel(model_id="gpt-4o", azure_endpoint=...) # ModuleNotFoundError # after pip install 'smolagents[openai]'
Defensive patterns
Strategy: validation
Validate before calling
try:
import openai # noqa
ok = True
except ModuleNotFoundError:
ok = False
assert ok, "pip install 'smolagents[openai]'" Type guard
null
Try / catch
try:
model = AzureOpenAIModel(model_id=mid, azure_endpoint=endpoint)
except ModuleNotFoundError as e:
print("Install the extra:", e)
sys.exit(1) Prevention
- Include smolagents[openai] in deployment manifests for Azure setups.
- Verify dependencies in the actual runtime image/interpreter, not just locally.
When it happens
Trigger: Instantiating AzureOpenAIModel in an environment without the openai package installed (base smolagents install).
Common situations: Enterprise Azure OpenAI setups where the deployment env only installed base smolagents; CI matrices missing the extra; migrating from OpenAIModel without reinstalling deps.
Understand the failure class
Background: "X is not installed. Please install it with pip install Y": missing optional dependency errors — ImportError/ValueError raised when a library's optional extra was never installed — this error's family across 22 libraries.
Related errors
- Please install 'openai' extra to use OpenAIModel: `pip insta
- Please install 'litellm' extra to use LiteLLMRouterModel: `p
- Please install 'bedrock' extra to use AmazonBedrockServerMod
AI-assisted analysis of huggingface/smolagents@30bb116109 (2026-08-28).
Data as JSON: /api/errors/88bd44426eff169a.
Report an issue: GitHub.