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

  1. Run: pip install openai in the environment running the CLI
  2. Install via the CLI's LLM extra if available
  3. 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

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


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)

    @property

View on GitHub (pinned to cf67b549a7)