{"record":{"id":"ec9cb71e3a5e3d43","repo":"binary-husky/gpt_academic","slug":"apikey-apikey","errorCode":null,"errorMessage":"APIKEY为空,请检查配置文件的{APIKEY}","messagePattern":"APIKEY为空,请检查配置文件的(.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"request_llms/oai_std_model_template.py","lineNumber":175,"sourceCode":"        console_silence=False,\n    ):\n        \"\"\"\n        发送至chatGPT，等待回复，一次性完成，不显示中间过程。但内部用stream的方法避免中途网线被掐。\n        inputs：\n            是本次问询的输入\n        sys_prompt:\n            系统静默prompt\n        llm_kwargs：\n            chatGPT的内部调优参数\n        history：\n            是之前的对话列表\n        observe_window = None：\n            用于负责跨越线程传递已经输出的部分，大部分时候仅仅为了fancy的视觉效果，留空即可。observe_window[0]：观测窗。observe_window[1]：看门狗\n        \"\"\"\n        from .bridge_all import model_info\n        watch_dog_patience = 5  # 看门狗的耐心，设置5秒不准咬人 (咬的也不是人)\n        if len(APIKEY) == 0:\n            raise RuntimeError(f\"APIKEY为空,请检查配置文件的{APIKEY}\")\n        if inputs == \"\":\n            inputs = \"你好👋\"\n\n\n        headers, payload = generate_message(\n            input=inputs,\n            model=remove_prefix(llm_kwargs[\"llm_model\"]),\n            key=APIKEY,\n            history=history,\n            max_output_token=max_output_token,\n            system_prompt=sys_prompt,\n            temperature=llm_kwargs[\"temperature\"],\n        )\n\n        reasoning = model_info[llm_kwargs['llm_model']].get('enable_reasoning', False)\n\n        retry = 0\n        while True:","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/request_llms/oai_std_model_template.py#L157-L193","documentation":"predict_no_ui_long_connection in the OpenAI-compatible template validates that APIKEY (resolved from config/environment) is non-empty before building the request; empty means the model's key variable was never configured, and it raises RuntimeError('APIKEY为空...'). The f-string interpolates the empty key, so the message literally ends with an empty value.","triggerScenarios":"Using an OpenAI-style model (e.g. via oai_std_model_template) when the corresponding API key config entry (e.g. GPT_4_API_KEY or custom APIKEY layout) is unset/empty in config.py or its environment variable.","commonSituations":"New deployment where only some keys were filled in; switching LLM_MODEL to a provider whose key variable was never set; docker/env deployment where the key env var was not passed; key set in a different config than the one loaded.","solutions":["Find which key variable the model maps to (config.py APIKEY_LAYOUT / bridge_all model_info) and set it.","Set the key via environment variable using the shared_utils/config_loader convention and reload.","Restart the app after editing config so the cached config loader picks up the new value.","Verify no trailing quotes/whitespace turned the value into an empty string."],"exampleFix":"# config.py\n# before\nGPT_4_64K_API_KEY = \"\"\n\n# after\nGPT_4_64K_API_KEY = \"sk-...\"","handlingStrategy":"validation","validationCode":"from toolbox import get_conf\nAPIKEY = get_conf('GPT_4_API_KEY')  # whichever var the model maps to\nif not APIKEY:\n    raise ConfigError('GPT_4_API_KEY is empty — set it in config.py or env')","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Validate all mapped key variables for the selected LLM_MODEL at startup.","Use the same key-variable mapping conventions as bridge_all model_info.","Fail fast in CI/deploy checks when a selected model's key is empty."],"tags":["api-key","configuration","openai","validation"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}