binary-husky/gpt_academic · critical · AssertionError
你提供了错误的API_KEY。 1. 临时解决方案:直接在输入区键入api_key,然后回车提交。 2. 长效解决方
Error message
你提供了错误的API_KEY。 1. 临时解决方案:直接在输入区键入api_key,然后回车提交。 2. 长效解决方案:在config.py中配置。
What it means
AssertionError raised at the top of generate_payload in the main ChatGPT bridge: is_any_api_key(llm_kwargs['api_key']) returned False, meaning the key string is empty or contains no usable key (it checks for non-placeholder, non-'sk-'-missing values). The bridge builds Authorization: Bearer headers from this key, so it aborts before any request. The message offers both a quick fix (type the key in the chat box) and a durable one (config.py).
Source
Thrown at request_llms/bridge_chatgpt.py:456
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.")
elif "Not enough point" in error_msg:
chatbot[-1] = (chatbot[-1][0], "[Local Message] Not enough point.")
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
- Temporary: type the API key directly into the gpt_academic input box and press Enter — it is picked up for the session.
- Permanent: set API_KEY = "sk-..." (and if sharing, API_KEY_EXPOSE) in config_private.py at the repo root and restart.
- Verify the variable spelling and that config_private.py is in the project root (it shadows config.py).
- For vllm- models no key is needed — the code path assigns 'no-api-key' — so the error means you are on an OpenAI/Azure model that requires one.
Example fix
# config_private.py API_KEY = "sk-your-real-key-here" API_KEY_EXPOSE = 0
Defensive patterns
Strategy: validation
Validate before calling
from toolbox import is_any_api_key assert is_any_api_key(API_KEY), "API_KEY empty/placeholder — set it in config_private.py before starting"
Try / catch
try:
payload = generate_payload(inputs, llm_kwargs, history, system_prompt)
except AssertionError as e:
if 'API_KEY' in str(e):
prompt_user_for_key_in_chat() # the documented temporary fix
else:
raise Prevention
- Validate keys at startup with is_any_api_key and fail fast with a clear message.
- Keep config_private.py in the repo root and double-check variable names against config.py.
- For docker installs, mount config_private.py into the container.
- Remember vllm- models need no key; openai/azure models always do.
When it happens
Trigger: API_KEY/API_KEY_EXPOSE left empty or as the default placeholder in config.py and config_private.py; user selected an OpenAI-family model but never configured a key; env var override not picked up because config was already loaded; key typed into the UI but the model branch reads the config value instead.
Common situations: Fresh install where only config.py (template) exists; user filled config_private.py but misspelled the variable name; docker deployments missing the mounted config; selecting gpt models before any key was ever provided.
Related errors
- 你提供了错误的API_KEY。 1. 临时解决方案:直接在输入区键入api_key,然后回车提交。 2. 长效解决方
- 没有设置ANTHROPIC_API_KEY选项
- 请配置 GEMINI_API_KEY。
- 你提供了错误的API_KEY。 1. 临时解决方案:直接在输入区键入api_key,然后回车提交。 2. 长效解决方
- APIKEY为空,请检查配置文件的{APIKEY}
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/c56c01a8e0ad0658.
Report an issue: GitHub.