binary-husky/gpt_academic · error · RuntimeError
APIKEY为空,请检查配置文件的{APIKEY}
Error message
APIKEY为空,请检查配置文件的{APIKEY} What it means
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.
Source
Thrown at request_llms/oai_std_model_template.py:175
console_silence=False,
):
"""
发送至chatGPT,等待回复,一次性完成,不显示中间过程。但内部用stream的方法避免中途网线被掐。
inputs:
是本次问询的输入
sys_prompt:
系统静默prompt
llm_kwargs:
chatGPT的内部调优参数
history:
是之前的对话列表
observe_window = None:
用于负责跨越线程传递已经输出的部分,大部分时候仅仅为了fancy的视觉效果,留空即可。observe_window[0]:观测窗。observe_window[1]:看门狗
"""
from .bridge_all import model_info
watch_dog_patience = 5 # 看门狗的耐心,设置5秒不准咬人 (咬的也不是人)
if len(APIKEY) == 0:
raise RuntimeError(f"APIKEY为空,请检查配置文件的{APIKEY}")
if inputs == "":
inputs = "你好👋"
headers, payload = generate_message(
input=inputs,
model=remove_prefix(llm_kwargs["llm_model"]),
key=APIKEY,
history=history,
max_output_token=max_output_token,
system_prompt=sys_prompt,
temperature=llm_kwargs["temperature"],
)
reasoning = model_info[llm_kwargs['llm_model']].get('enable_reasoning', False)
retry = 0
while True:View on GitHub (pinned to d6bde0fa54)
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.
Example fix
# config.py # before GPT_4_64K_API_KEY = "" # after GPT_4_64K_API_KEY = "sk-..."
Defensive patterns
Strategy: validation
Validate before calling
from toolbox import get_conf
APIKEY = get_conf('GPT_4_API_KEY') # whichever var the model maps to
if not APIKEY:
raise ConfigError('GPT_4_API_KEY is empty — set it in config.py or env') Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- 你提供了错误的API_KEY。 1. 临时解决方案:直接在输入区键入api_key,然后回车提交。 2. 长效解决方
- 你提供了错误的API_KEY。 1. 临时解决方案:直接在输入区键入api_key,然后回车提交。 2. 长效解决方
- 用户代理或助理代理未定义
- AZURE_CFG_ARRAY中配置的模型必须以azure开头
- 模型覆盖参数 '{model_override}' 指向一个暂不支持的模型,请检查配置文件。
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/ec9cb71e3a5e3d43.
Report an issue: GitHub.