{"record":{"id":"88ef163544af16b0","repo":"binary-husky/gpt_academic","slug":"dashscope-api-key","errorCode":null,"errorMessage":"请配置 DASHSCOPE_API_KEY","messagePattern":"请配置 DASHSCOPE_API_KEY","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"request_llms/com_qwenapi.py","lineNumber":21,"sourceCode":"import threading\n\ntimeout_bot_msg = '[Local Message] Request timeout. Network error.'\nmodel_prefix_to_remove = 'dashscope-'\n\nclass QwenRequestInstance():\n    def __init__(self):\n        import dashscope\n        self.time_to_yield_event = threading.Event()\n        self.time_to_exit_event = threading.Event()\n        self.result_buf = \"\"\n\n        def validate_key():\n            DASHSCOPE_API_KEY = get_conf(\"DASHSCOPE_API_KEY\")\n            if DASHSCOPE_API_KEY == '': return False\n            return True\n\n        if not validate_key():\n            raise RuntimeError('请配置 DASHSCOPE_API_KEY')\n        dashscope.api_key = get_conf(\"DASHSCOPE_API_KEY\")\n\n    def format_reasoning(self, reasoning_content:str, main_content:str):\n        if reasoning_content:\n            reasoning_content_paragraphs = ''.join([f'<p style=\"margin: 1.25em 0;\">{line}</p>' for line in reasoning_content.split('\\n')])\n            formatted_reasoning_content = f'<div class=\"reasoning_process\">{reasoning_content_paragraphs}</div>\\n\\n---\\n\\n'\n            return formatted_reasoning_content + main_content\n        else:\n            return main_content\n\n    def generate(self, inputs, llm_kwargs, history, system_prompt):\n        # import _thread as thread\n        from dashscope import Generation\n        top_p = llm_kwargs.get('top_p', 0.8)\n        if top_p == 0: top_p += 1e-5\n        if top_p == 1: top_p -= 1e-5\n\n        model_name = llm_kwargs['llm_model']","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/request_llms/com_qwenapi.py#L3-L39","documentation":"Constructor guard of QwenRequestInstance in the DashScope (Tongyi Qianwen) client: __init__ reads DASHSCOPE_API_KEY via get_conf and raises RuntimeError('请配置 DASHSCOPE_API_KEY') when it is empty, before assigning dashscope.api_key. Any predict entry in bridge_qwen.py that instantiates this class will fail immediately.","triggerScenarios":"Instantiating QwenRequestInstance (request_llms/com_qwenapi.py:21) while DASHSCOPE_API_KEY == '' in the resolved configuration. Triggered by selecting a qwen model in the UI or any plugin that spawns the qwen bridge.","commonSituations":"DASHSCOPE_API_KEY missing from config.py/config_private.py; aliyun DashScope key not propagated into docker container; key added after process start without restart (get_conf uses an LRU cache).","solutions":["Get a key from DashScope (bailian.console.aliyun.com) and set DASHSCOPE_API_KEY in config_private.py or env, then restart","If config was changed at runtime, clear the get_conf LRU cache or restart the process","For docker deployments, add DASHSCOPE_API_KEY to docker-compose.yml environment"],"exampleFix":"# before\nDASHSCOPE_API_KEY = ''\n\n# after (config_private.py)\nDASHSCOPE_API_KEY = 'sk-xxxxxxxxxxxxxxxx'","handlingStrategy":"validation","validationCode":"from toolbox import get_conf\nassert get_conf('DASHSCOPE_API_KEY'), 'DASHSCOPE_API_KEY not configured'","typeGuard":null,"tryCatchPattern":"try:\n    from request_llms.com_qwenapi import QwenRequestInstance\n    q = QwenRequestInstance()\nexcept RuntimeError as e:\n    if 'DASHSCOPE_API_KEY' in str(e):\n        raise ConfigurationError(str(e)) from e\n    raise","preventionTips":["Restart the app after editing config; get_conf is LRU-cached","In docker, fail fast on missing env vars with an entrypoint check"],"tags":["config","authentication","dashscope","qwen"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}