{"record":{"id":"1e83d0c482cee872","repo":"binary-husky/gpt_academic","slug":"zhipuai-api-key","errorCode":null,"errorMessage":"请配置ZHIPUAI_API_KEY","messagePattern":"请配置ZHIPUAI_API_KEY","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"request_llms/bridge_zhipu.py","lineNumber":33,"sourceCode":"def make_media_input(inputs, image_paths):\n    for image_path in image_paths:\n        inputs = inputs + f'<br/><br/><div align=\"center\"><img src=\"file={os.path.abspath(image_path)}\"></div>'\n    return inputs\n\ndef predict_no_ui_long_connection(inputs:str, llm_kwargs:dict, history:list=[], sys_prompt:str=\"\",\n                                  observe_window:list=[], console_silence:bool=False):\n    \"\"\"\n        ⭐多线程方法\n        函数的说明请见 request_llms/bridge_all.py\n    \"\"\"\n    watch_dog_patience = 5\n    response = \"\"\n\n    if llm_kwargs[\"llm_model\"] == \"zhipuai\":\n        llm_kwargs[\"llm_model\"] = zhipuai_default_model\n\n    if validate_key() is False:\n        raise RuntimeError('请配置ZHIPUAI_API_KEY')\n\n    # 开始接收回复\n    from .com_zhipuglm import ZhipuChatInit\n    zhipu_bro_init = ZhipuChatInit()\n    for chunk, response in zhipu_bro_init.generate_chat(inputs, llm_kwargs, history, sys_prompt):\n        if len(observe_window) >= 1:\n            observe_window[0] = response\n        if len(observe_window) >= 2:\n            if (time.time() - observe_window[1]) > watch_dog_patience:\n                raise RuntimeError(\"程序终止。\")\n    return response\n\n\ndef predict(inputs:str, llm_kwargs:dict, plugin_kwargs:dict, chatbot:ChatBotWithCookies,\n            history:list=[], system_prompt:str='', stream:bool=True, additional_fn:str=None):\n    \"\"\"\n        ⭐单线程方法\n        函数的说明请见 request_llms/bridge_all.py","sourceCodeStart":15,"sourceCodeEnd":51,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/request_llms/bridge_zhipu.py#L15-L51","documentation":"Configuration guard of the Zhipu GLM bridge: predict_no_ui_longconnection raises RuntimeError('请配置ZHIPUAI_API_KEY') when validate_key() reports the ZHIPUAI_API_KEY config empty. Note it fires after normalizing llm_kwargs['llm_model'] to the default zhipuai model, before any API call.","triggerScenarios":"Calling request_llms/bridge_zhipu.py:33 predict_no_ui_long_connection() with ZHIPUAI_API_KEY == '' from get_conf (config.py / config_private.py / env).","commonSituations":"Fresh install with placeholder config; user switched the model dropdown to zhipuai without a key; key set only in the shell that launched a different process (systemd/docker missing the env var).","solutions":["Set ZHIPUAI_API_KEY in config_private.py (or docker-compose env), restart the service","Verify: from toolbox import get_conf; assert get_conf('ZHIPUAI_API_KEY')","Ensure the key comes from open.bigmodel.cn and is active (no quota/binding issues)"],"exampleFix":"# before\nZHIPUAI_API_KEY = ''\n\n# after (config_private.py)\nZHIPUAI_API_KEY = 'your-zhipuai-key'","handlingStrategy":"validation","validationCode":"from toolbox import get_conf\nassert get_conf('ZHIPUAI_API_KEY'), 'ZHIPUAI_API_KEY not configured'","typeGuard":null,"tryCatchPattern":"try:\n    predict_no_ui_long_connection(...)\nexcept RuntimeError as e:\n    if 'ZHIPUAI_API_KEY' in str(e):\n        raise ConfigurationError(str(e)) from e\n    raise","preventionTips":["Store provider keys in config_private.py committed nowhere","Preflight-validate keys for the model selected in the UI dropdown"],"tags":["config","authentication","zhipu","llm-bridge"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}