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

Same failed-key guard as the main bridge, but in the vision bridge's generate_payload: before building the multimodal payload (image inputs + Authorization header), is_any_api_key rejects the key. The vision path (GPT-4V style image chat) always needs a real OpenAI-compatible key — unlike the main bridge there is no vllm 'no-api-key' bypass here — so an empty or placeholder key aborts before the request with the standard guidance message.

Source

Thrown at request_llms/bridge_chatgpt_vision.py:251

    elif "API key has been deactivated" in error_msg:
        chatbot[-1] = (chatbot[-1][0], "[Local Message] API key has been deactivated. OpenAI以账户失效为由, 拒绝服务." + openai_website); report_invalid_key(api_key)
    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, llm_kwargs, history, system_prompt, image_paths):
    """
    整合所有信息,选择LLM模型,生成http请求,为发送请求做准备
    """
    if not is_any_api_key(llm_kwargs['api_key']):
        raise AssertionError("你提供了错误的API_KEY。\n\n1. 临时解决方案:直接在输入区键入api_key,然后回车提交。\n\n2. 长效解决方案:在config.py中配置。")

    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})

    base64_images = []
    for image_path in image_paths:
        base64_images.append(encode_image(image_path))

View on GitHub (pinned to d6bde0fa54)

Solutions

  1. Temporary: paste the API key into the input area and submit, then retry the image request.
  2. Permanent: set API_KEY in config_private.py and restart gpt_academic.
  3. For azure- vision models, also fill the model's AZURE_API_KEY inside AZURE_CFG_ARRAY in config_private.py.
  4. Confirm you have access to a vision-capable model (gpt-4-xxx-vision / gpt-4o); a non-vision key on a relay without that model will fail later regardless.

Example fix

# config_private.py
API_KEY = "sk-your-real-key-here"
AZURE_CFG_ARRAY = {
    "azure-gpt-4-vision": {
        "AZURE_API_KEY": "your-azure-key",
        "AZURE_ENDPOINT": "https://your-resource.openai.azure.com",
        "AZURE_API_VERSION": "2023-05-15",
    }
}
Defensive patterns

Strategy: validation

Validate before calling

from toolbox import is_any_api_key
assert is_any_api_key(API_KEY), "vision requests need a real API key — set API_KEY in config_private.py"

Try / catch

try:
    payload = generate_payload(inputs, llm_kwargs, history, system_prompt, image_paths)
except AssertionError as e:
    if 'API_KEY' in str(e):
        guide_user_to_enter_key_in_input_box()
    else:
        raise

Prevention

When it happens

Trigger: Uploading an image and asking a vision model while API_KEY is empty/placeholder; using azure- vision models where the key must come from AZURE_CFG_ARRAY but the shared key check failed first; session where the key was never typed into the input box.

Common situations: New installs testing image chat before finishing key setup; users whose normal text chat works (key cached in session) but vision requests go through a fresh payload build that reads the still-empty config key.

Related errors


AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14). Data as JSON: /api/errors/11912625733e14e4. Report an issue: GitHub.