{"record":{"id":"3a33a2309e6a6110","repo":"ATH-MaaS/Pixelle-Video","slug":"openai-api-key-not-set-configure-openai-only-when","errorCode":null,"errorMessage":"OPENAI_API_KEY not set. Configure OpenAI only when using GPT image models.","messagePattern":"OPENAI_API_KEY not set\\. Configure OpenAI only when using GPT image models\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"pixelle_video/services/api_services/image_client.py","lineNumber":84,"sourceCode":"\n    @property\n    def seedream_client(self):\n        \"\"\"Create Seedream client only when a Seedream/ARK model is selected.\"\"\"\n        if not self._ark_api_key:\n            raise RuntimeError(\"ARK_API_KEY not set. Configure ARK only when using Seedream image models.\")\n        if self._seedream_client is None:\n            self._seedream_client = SeedreamClient(\n                api_key=self._ark_api_key,\n                base_url=self._ark_base_url,\n                local_proxy=self._ark_local_proxy,\n            )\n        return self._seedream_client\n\n    @property\n    def gpt_client(self):\n        \"\"\"Create OpenAI image client only when a GPT/OpenAI image model is selected.\"\"\"\n        if not self._gpt_api_key:\n            raise RuntimeError(\"OPENAI_API_KEY not set. Configure OpenAI only when using GPT image models.\")\n        if self._gpt_client is None:\n            self._gpt_client = ImageGPT(\n                api_key=self._gpt_api_key,\n                base_url=self._gpt_base_url,\n                local_proxy=self._gpt_local_proxy,\n            )\n        return self._gpt_client\n\n    def generate_image(self,\n                       prompt: str,\n                       image_paths: Optional[List[str]] = None,\n                       model: str = \"wan2.7-image\",\n                       save_dir: Optional[str] = None,\n                       session_id: Optional[str] = None,\n                       video_ratio: Optional[str] = \"16:9\",\n                       resolution: Optional[str] = \"2K\") -> List[str]:\n        \"\"\"\n        Generate images based on prompt and optional reference images.","sourceCodeStart":66,"sourceCodeEnd":102,"githubUrl":"https://github.com/ATH-MaaS/Pixelle-Video/blob/848b054e4fae40dabc62ec58e960b573e83793ac/pixelle_video/services/api_services/image_client.py#L66-L102","documentation":"The GPT image client (ImageGPT) is created lazily via the gpt_client property and requires OPENAI_API_KEY. If the key is missing when a GPT/OpenAI image model is used, a RuntimeError is raised rather than calling the API unauthenticated.","triggerScenarios":"Selecting a GPT image model without OPENAI_API_KEY set; key defined in a different env var; config not reloaded after adding the key.","commonSituations":"Fresh CI/container without secrets mounted; .env not loaded; typos in the variable name; key revoked and removed from environment.","solutions":["Set OPENAI_API_KEY in the environment before generation","Confirm the .env/secret is actually loaded into the process","Check the config layer reads OPENAI_API_KEY into _gpt_api_key"],"exampleFix":"// before\nexport ARK_API_KEY=...\n// after\nexport ARK_API_KEY=...\nexport OPENAI_API_KEY=sk-...","handlingStrategy":"validation","validationCode":"import os\nif not os.environ.get(\"OPENAI_API_KEY\"):\n    raise SystemExit(\"Set OPENAI_API_KEY before using GPT image models\")","typeGuard":null,"tryCatchPattern":"try:\n    paths = gen.generate_image(prompt=p)\nexcept RuntimeError as e:\n    if \"OPENAI_API_KEY not set\" in str(e):\n        raise SystemExit(\"Configure OPENAI_API_KEY in your environment\") from e","preventionTips":["Fail fast at boot if required keys are missing","Mount secrets in CI/containers explicitly","Distinguish which provider key each model family needs"],"tags":["configuration","missing-env-var","authentication"],"backgroundTag":"missing-env-var","analyzedSha":"848b054e4fae40dabc62ec58e960b573e83793ac","analyzedAt":"2026-08-30T03:24:41.468Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}