{"record":{"id":"40f11b3c982d69b1","repo":"PrefectHQ/fastmcp","slug":"the-openai-package-is-not-installed-please-inst","errorCode":null,"errorMessage":"The `openai` package is not installed. Please install `fastmcp-slim[openai]` or add `openai` to your dependencies manually.","messagePattern":"The `openai` package is not installed\\. Please install `fastmcp-slim\\[openai\\]` or add `openai` to your dependencies manually\\.","errorType":"exception","errorClass":"ImportError","httpStatus":null,"severity":"error","filePath":"fastmcp_slim/fastmcp/client/sampling/handlers/openai.py","lineNumber":46,"sourceCode":"    from openai.types.chat import (\n        ChatCompletion,\n        ChatCompletionAssistantMessageParam,\n        ChatCompletionContentPartImageParam,\n        ChatCompletionContentPartInputAudioParam,\n        ChatCompletionContentPartParam,\n        ChatCompletionContentPartTextParam,\n        ChatCompletionMessageParam,\n        ChatCompletionMessageToolCallParam,\n        ChatCompletionSystemMessageParam,\n        ChatCompletionToolChoiceOptionParam,\n        ChatCompletionToolMessageParam,\n        ChatCompletionToolParam,\n        ChatCompletionUserMessageParam,\n    )\n    from openai.types.shared.chat_model import ChatModel\n    from openai.types.shared_params import FunctionDefinition\nexcept ImportError as e:\n    raise ImportError(\n        \"The `openai` package is not installed. \"\n        \"Please install `fastmcp-slim[openai]` or add `openai` to your dependencies manually.\"\n    ) from e\n\n# OpenAI only supports wav and mp3 for input audio\n_OPENAI_AUDIO_FORMATS: dict[str, Literal[\"wav\", \"mp3\"]] = {\n    \"audio/wav\": \"wav\",\n    \"audio/x-wav\": \"wav\",\n    \"audio/mp3\": \"mp3\",\n    \"audio/mpeg\": \"mp3\",\n}\n\n_OPENAI_IMAGE_MEDIA_TYPES: frozenset[str] = frozenset(\n    {\"image/jpeg\", \"image/png\", \"image/gif\", \"image/webp\"}\n)\n\n\ndef _image_content_to_openai_part(","sourceCodeStart":28,"sourceCodeEnd":64,"githubUrl":"https://github.com/PrefectHQ/fastmcp/blob/1f021142978e0861cd910c8df4e8074bc7cf3978/fastmcp_slim/fastmcp/client/sampling/handlers/openai.py#L28-L64","documentation":"The OpenAI sampling handler imports the openai package at module load time. If openai is not installed, ImportError is raised with instructions to install the optional dependency via the fastmcp-slim[openai] extra.","triggerScenarios":"Importing fastmcp.client.sampling.handlers.openai (or triggering any code path that loads it, e.g. using OpenAI sampling handler) in an environment without the openai package installed.","commonSituations":"Fresh environments where fastmcp-slim was installed without extras; CI images missing optional deps; switching from full fastmcp to fastmcp-slim without updating dependency lists.","solutions":["Install the extra: pip install 'fastmcp-slim[openai]' (or uv add 'fastmcp-slim[openai]').","Or add openai to your project dependencies directly: pip install openai.","If using uv: uv sync --extra openai.","If you don't need OpenAI sampling, avoid importing/using the OpenAI handler and use another handler."],"exampleFix":"// before\npip install fastmcp-slim\n// after\npip install \"fastmcp-slim[openai]\"","handlingStrategy":"validation","validationCode":"import importlib.util\nif importlib.util.find_spec('openai') is None:\n    raise SystemExit(\"Install the openai package: pip install 'fastmcp-slim[openai]'\")","typeGuard":"null","tryCatchPattern":"try:\n    from fastmcp.client.sampling.handlers.openai import OpenAIHandler\nexcept ImportError:\n    OpenAIHandler = None  # fall back to another handler","preventionTips":["Install fastmcp-slim with the [openai] extra in all environments.","Pin the extra in CI/docker images and requirements files.","Run a startup dependency check before using OpenAI sampling."],"tags":["dependency","openai","import-error"],"backgroundTag":"missing-optional-dependency","analyzedSha":"1f021142978e0861cd910c8df4e8074bc7cf3978","analyzedAt":"2026-08-29T14:31:16.082Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}