binary-husky/gpt_academic · error · AssertionError
你提供了错误的API_KEY。 1. 临时解决方案:直接在输入区键入api_key,然后回车提交。 2. 长效解决方
Error message
你提供了错误的API_KEY。 1. 临时解决方案:直接在输入区键入api_key,然后回车提交。 2. 长效解决方案:在config.py中配置。
What it means
AssertionError from generate_payload in bridge_openrouter: is_any_api_key(llm_kwargs['api_key']) returned False, meaning the key is empty or matches a known placeholder. The message gives both a quick fix (paste the key in the chat input, which the WebUI intercepts) and the durable fix (set it in config.py). Note it is raised as AssertionError, so it inherits from Exception but not RuntimeError.
Source
Thrown at request_llms/bridge_openrouter.py:414
chatbot[-1] = (chatbot[-1][0], "[Local Message] API key has been deactivated. OpenAI以账户失效为由, 拒绝服务." + openai_website)
elif "bad forward key" in error_msg:
chatbot[-1] = (chatbot[-1][0], "[Local Message] Bad forward key. API2D账户额度不足.")
elif "Not enough point" in error_msg:
chatbot[-1] = (chatbot[-1][0], "[Local Message] Not enough point. API2D账户点数不足.")
else:
from toolbox import regular_txt_to_markdown
tb_str = '```\n' + trimmed_format_exc() + '```'
chatbot[-1] = (chatbot[-1][0], f"[Local Message] 异常 \n\n{tb_str} \n\n{regular_txt_to_markdown(chunk_decoded)}")
return chatbot, history
def generate_payload(inputs:str, llm_kwargs:dict, history:list, system_prompt:str, image_base64_array:list=[], has_multimodal_capacity:bool=False, stream:bool=True):
"""
整合所有信息,选择LLM模型,生成http请求,为发送请求做准备
"""
from request_llms.bridge_all import model_info
if not is_any_api_key(llm_kwargs['api_key']):
raise AssertionError("你提供了错误的API_KEY。\n\n1. 临时解决方案:直接在输入区键入api_key,然后回车提交。\n\n2. 长效解决方案:在config.py中配置。")
if llm_kwargs['llm_model'].startswith('vllm-'):
api_key = 'no-api-key'
else:
api_key = select_api_key(llm_kwargs['api_key'], llm_kwargs['llm_model'])
headers = {
"Content-Type": "application/json",
"Authorization": f"Bearer {api_key}"
}
if API_ORG.startswith('org-'): headers.update({"OpenAI-Organization": API_ORG})
if llm_kwargs['llm_model'].startswith('azure-'):
headers.update({"api-key": api_key})
if llm_kwargs['llm_model'] in AZURE_CFG_ARRAY.keys():
azure_api_key_unshared = AZURE_CFG_ARRAY[llm_kwargs['llm_model']]["AZURE_API_KEY"]
headers.update({"api-key": azure_api_key_unshared})
if has_multimodal_capacity:View on GitHub (pinned to d6bde0fa54)
Solutions
- Set API_KEY = "sk-..." (list or string) in config_private.py and restart
- Or paste the api_key directly into the WebUI input box and press Enter (temporary session-scoped fix)
- Check is_any_api_key's placeholder list to ensure your key format is not being rejected
- For vllm-* models no key is needed - use the vllm- model prefix instead
Example fix
# config_private.py # before API_KEY = "" # after API_KEY = "sk-xxxxxxxxxxxxxxxx"
Defensive patterns
Strategy: validation
Validate before calling
from common_utils import is_any_api_key
if not is_any_api_key(llm_kwargs.get('api_key', '')):
raise SystemExit('Configure API_KEY in config_private.py before calling LLM functions') Type guard
def has_valid_api_key(llm_kwargs: dict) -> bool:
return is_any_api_key(llm_kwargs.get('api_key', '')) Try / catch
try:
payload = generate_payload(inputs, llm_kwargs, history, system_prompt)
except AssertionError as e:
prompt_user_for_api_key(chatbot) # WebUI flow: let them paste it
return Prevention
- Validate api_key presence in plugin entry points before spawning worker threads
- Keep config_private.py as the single source for keys and gitignore it
- Remember this raises AssertionError - catch that type, not RuntimeError
When it happens
Trigger: API_KEY / OPENAI_API_KEY unset in config_private.py; key still the template placeholder ('sk-...' sample values is_any_api_key rejects); key passed empty through a plugin that builds llm_kwargs itself.
Common situations: First-run without editing config_private.py; Docker deploy missing the env var; user typed the key into the wrong config field.
Related errors
- 你提供了错误的API_KEY。 1. 临时解决方案:直接在输入区键入api_key,然后回车提交。 2. 长效解决方
- 你提供了错误的API_KEY。 1. 临时解决方案:直接在输入区键入api_key,然后回车提交。 2. 长效解决方
- 没有设置ANTHROPIC_API_KEY选项
- 请配置 GEMINI_API_KEY。
- Endpoint不正确, 请检查AZURE_ENDPOINT的配置! 当前的Endpoint为:{endpoint}
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/9f04c908b5eed447.
Report an issue: GitHub.