apache/seatunnel · error · ImportError
openai package required for AI_PROVIDER=openai. Install it…
Error message
openai package required for AI_PROVIDER=openai. Install it: pip install openai
What it means
Raised by OpenAIProvider.__init__ when the optional openai Python package is absent while AI_PROVIDER=openai is configured. The provider lazily imports the dependency, so the config selection is the input at fault, not missing core functionality.
Solutions
- Run: pip install openai in the environment running the CLI
- Install via the CLI's LLM extra if available
- Verify with 'python -c "import openai"' using the same interpreter
Example fix
// before export AI_PROVIDER=openai seatunnel-cli ... # ImportError // after pip install openai export AI_PROVIDER=openai
Defensive patterns
Strategy: try-catch
Validate before calling
python -c "import openai" || pip install openai
Try / catch
try:
provider = OpenAIProvider()
except ImportError as e:
print(f'Missing LLM dependency: {e}. Run: pip install openai')
sys.exit(2) Prevention
- Install the openai package in the CLI's interpreter
- Pin openai version compatible with the CLI
- Run an import smoke test in CI
- Install the matching extra when switching AI_PROVIDER
When it happens
Trigger: AI_PROVIDER=openai selects OpenAIProvider and 'import openai' fails in __init__ because the package is not installed in the environment.
Common situations: Fresh venv/container without the openai package; switched AI_PROVIDER from another provider; very old CLI where openai was not a dependency.
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
- anthropic package required for AI_PROVIDER=anthropic…
- bedrock-mantle provider requires: pip install openai…
- OPENAI_API_KEY environment variable is required for…
- openai package required for AI_PROVIDER=orcarouter. Install…
- ANTHROPIC_API_KEY environment variable is required for…
AI-assisted analysis of apache/seatunnel@cf67b549a7 (2026-09-10).
Data as JSON: /api/errors/9b7fe49b12215758.
Report an issue: GitHub.
Appendix: source
Thrown at seatunnel-cli/seatunnel_cli/llm_provider.py:705
stop_reason = "tool_use"
return {
"output": {"message": {"role": "assistant", "content": content}},
"stopReason": stop_reason,
}
# ─── OpenAI Provider ───
class OpenAIProvider(LLMProvider):
"""OpenAI Chat Completions API provider."""
def __init__(self):
try:
import openai
except ImportError:
raise ImportError(
"openai package required for AI_PROVIDER=openai. "
"Install it: pip install openai"
)
api_key = os.environ.get("OPENAI_API_KEY")
base_url = os.environ.get("OPENAI_BASE_URL") # Supports compatible APIs
if not api_key:
raise ValueError("OPENAI_API_KEY environment variable is required for AI_PROVIDER=openai")
client_kwargs = {"api_key": api_key}
if base_url:
client_kwargs["base_url"] = base_url
self._client = openai.OpenAI(**client_kwargs)
self._model_id = os.environ.get("OPENAI_MODEL", "gpt-4o")
self._fast_model_id = os.environ.get("OPENAI_SMALL_FAST_MODEL", "gpt-4o-mini")
self._echo_reasoning_content = _env_bool("OPENAI_ECHO_REASONING_CONTENT", True)
@propertyView on GitHub (pinned to cf67b549a7)