{"record":{"id":"67ecd3a2c74cb401","repo":"ATH-MaaS/Pixelle-Video","slug":"dashscope-vlm-api-key-is-not-configured","errorCode":null,"errorMessage":"DashScope VLM API key is not configured.","messagePattern":"DashScope VLM API key is not configured\\.","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"critical","filePath":"pixelle_video/services/api_services/vlm_client.py","lineNumber":58,"sourceCode":"            print(f\"Prompt: {prompt}\")\n            if image_paths:\n                print(f\"Images: {len(image_paths)}\")\n                for p in image_paths:\n                    if p.startswith(\"data:\"):\n                        print(f\" - [Base64图片]\")\n                    else:\n                        print(f\" - {p}\")\n            if video_paths:\n                print(f\"Videos: {len(video_paths)}\")\n                for p in video_paths:\n                    print(f\" - {p}\")\n            print(f\"Model: {selected_model}\")\n            if session_id:\n                print(f\"Session ID: {session_id}\")\n            print(\"-\" * 30)\n\n        if self.dashscope_client is None:\n            raise RuntimeError(\"DashScope VLM API key is not configured.\")\n\n        image_urls = [self._to_dashscope_file_url(path, allow_data_url=True) for path in image_paths or []]\n        video_urls = [self._to_dashscope_file_url(path, allow_data_url=False) for path in video_paths or []]\n        return self.dashscope_client.chat(\n            text=prompt,\n            images=image_urls,\n            videos=video_urls,\n            model=selected_model,\n            stream=False,\n        )\n\n    def _to_dashscope_file_url(self, path: str, allow_data_url: bool) -> str:\n        if path.startswith(\"data:\"):\n            if not allow_data_url:\n                raise ValueError(\"DashScope video input does not support data URLs in this adapter.\")\n\n            import base64 as b64\n            import tempfile","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/ATH-MaaS/Pixelle-Video/blob/848b054e4fae40dabc62ec58e960b573e83793ac/pixelle_video/services/api_services/vlm_client.py#L40-L76","documentation":"query raises RuntimeError when self.dashscope_client is None, meaning the DashScope SDK client was never constructed because DASHSCOPE_API_KEY was not configured at initialization time. No chat request can be made without it.","triggerScenarios":"Constructing VlmClient without a DashScope API key (client stays None) and then calling query() with a valid model.","commonSituations":"DASHSCOPE_API_KEY missing from environment/.env; key loaded after VlmClient was instantiated (load_dotenv called too late); different process/container lacking the secret; SDK init silently skipped on import error.","solutions":["Set DASHSCOPE_API_KEY in the environment before creating VlmClient","Ensure load_dotenv()/secret loading runs before client construction, not after","Re-instantiate VlmClient after fixing configuration — it does not hot-reload credentials","Verify with: python -c \"import os; print(bool(os.environ.get('DASHSCOPE_API_KEY')))\""],"exampleFix":"// before\nclient = VlmClient()          # key not loaded yet\nload_dotenv()\n// after\nload_dotenv()\nclient = VlmClient()","handlingStrategy":"validation","validationCode":"import os\nif not os.environ.get(\"DASHSCOPE_API_KEY\"):\n    raise SystemExit(\"Set DASHSCOPE_API_KEY before initializing VlmClient\")","typeGuard":null,"tryCatchPattern":"try:\n    answer = vlm.query(prompt=p, model=\"qwen-vl-max\")\nexcept RuntimeError as e:\n    if \"API key is not configured\" in str(e):\n        logging.critical(\"DASHSCOPE_API_KEY missing; re-create VlmClient after loading secrets\")\n    else:\n        raise","preventionTips":["Call load_dotenv()/secret loading before constructing VlmClient","Check client.dashscope_client is not None right after construction","Add the key to deployment env templates and CI secrets"],"tags":["dashscope","api-key","environment","initialization"],"backgroundTag":"missing-env-var","analyzedSha":"848b054e4fae40dabc62ec58e960b573e83793ac","analyzedAt":"2026-08-30T03:24:41.468Z","schemaVersion":2},"datasetVersion":"2026-08-30T08:17:16.595Z"}