{"record":{"id":"44dee37b99444afe","repo":"apache/seatunnel","slug":"openai-api-key-environment-variable-is-required-fo","errorCode":null,"errorMessage":"OPENAI_API_KEY environment variable is required for AI_PROVIDER=openai","messagePattern":"OPENAI_API_KEY environment variable is required for AI_PROVIDER=openai","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"seatunnel-cli/seatunnel_cli/llm_provider.py","lineNumber":713,"sourceCode":"\n# ─── OpenAI Provider ───\n\nclass OpenAIProvider(LLMProvider):\n    \"\"\"OpenAI Chat Completions API provider.\"\"\"\n\n    def __init__(self):\n        try:\n            import openai\n        except ImportError:\n            raise ImportError(\n                \"openai package required for AI_PROVIDER=openai. \"\n                \"Install it: pip install openai\"\n            )\n\n        api_key = os.environ.get(\"OPENAI_API_KEY\")\n        base_url = os.environ.get(\"OPENAI_BASE_URL\")  # Supports compatible APIs\n        if not api_key:\n            raise ValueError(\"OPENAI_API_KEY environment variable is required for AI_PROVIDER=openai\")\n\n        client_kwargs = {\"api_key\": api_key}\n        if base_url:\n            client_kwargs[\"base_url\"] = base_url\n        self._client = openai.OpenAI(**client_kwargs)\n        self._model_id = os.environ.get(\"OPENAI_MODEL\", \"gpt-4o\")\n        self._fast_model_id = os.environ.get(\"OPENAI_SMALL_FAST_MODEL\", \"gpt-4o-mini\")\n        self._echo_reasoning_content = _env_bool(\"OPENAI_ECHO_REASONING_CONTENT\", True)\n\n    @property\n    def provider_name(self) -> str:\n        return \"openai\"\n\n    @property\n    def model_id(self) -> str:\n        return self._model_id\n\n    @property","sourceCodeStart":695,"sourceCodeEnd":731,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-cli/seatunnel_cli/llm_provider.py#L695-L731","documentation":"OpenAIProvider reads OPENAI_API_KEY (and optional OPENAI_BASE_URL) and refuses to construct the client without a key, raising ValueError. The key is required to authenticate Chat Completions requests.","triggerScenarios":"AI_PROVIDER=openai with the openai package installed, but OPENAI_API_KEY is unset or empty at provider __init__ time.","commonSituations":"Key exported in a different shell/session; CI environment lacking the secret; using a compatible API but forgetting the key entirely; .env not sourced.","solutions":["export OPENAI_API_KEY=sk-... (or your provider-compatible key) before running the CLI","Ensure the secret reaches the process (CI config, shell profile, dotenv loading)","Double-check the variable name OPENAI_API_KEY and that it contains a non-empty value"],"exampleFix":"// before\nexport AI_PROVIDER=openai\n// after\nexport AI_PROVIDER=openai\nexport OPENAI_API_KEY=sk-...","handlingStrategy":"validation","validationCode":"import os, sys\nif not os.environ.get('OPENAI_API_KEY'):\n    sys.exit('OPENAI_API_KEY is not set')","typeGuard":null,"tryCatchPattern":"try:\n    provider = OpenAIProvider()\nexcept ValueError as e:\n    print(e)  # missing OPENAI_API_KEY\n    sys.exit(2)","preventionTips":["Export OPENAI_API_KEY before launching the CLI","Ensure CI secrets propagate to the subprocess","If using a compatible endpoint, also set OPENAI_BASE_URL and still provide the key","Preflight-check env vars at startup"],"tags":["python","llm","env","openai","api-key"],"backgroundTag":"missing-env-var","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}