{"record":{"id":"11912625733e14e4","repo":"binary-husky/gpt_academic","slug":"api-key-1-api-key-119126","errorCode":null,"errorMessage":"你提供了错误的API_KEY。\n\n1. 临时解决方案：直接在输入区键入api_key，然后回车提交。\n\n2. 长效解决方案：在config.py中配置。","messagePattern":"你提供了错误的API_KEY。\n\n1\\. 临时解决方案：直接在输入区键入api_key，然后回车提交。\n\n2\\. 长效解决方案：在config\\.py中配置。","errorType":"exception","errorClass":"AssertionError","httpStatus":null,"severity":"critical","filePath":"request_llms/bridge_chatgpt_vision.py","lineNumber":251,"sourceCode":"    elif \"API key has been deactivated\" in error_msg:\n        chatbot[-1] = (chatbot[-1][0], \"[Local Message] API key has been deactivated. OpenAI以账户失效为由, 拒绝服务.\" + openai_website); report_invalid_key(api_key)\n    elif \"bad forward key\" in error_msg:\n        chatbot[-1] = (chatbot[-1][0], \"[Local Message] Bad forward key. API2D账户额度不足.\")\n    elif \"Not enough point\" in error_msg:\n        chatbot[-1] = (chatbot[-1][0], \"[Local Message] Not enough point. API2D账户点数不足.\")\n    else:\n        from toolbox import regular_txt_to_markdown\n        tb_str = '```\\n' + trimmed_format_exc() + '```'\n        chatbot[-1] = (chatbot[-1][0], f\"[Local Message] 异常 \\n\\n{tb_str} \\n\\n{regular_txt_to_markdown(chunk_decoded)}\")\n    return chatbot, history\n\n\ndef generate_payload(inputs, llm_kwargs, history, system_prompt, image_paths):\n    \"\"\"\n    整合所有信息，选择LLM模型，生成http请求，为发送请求做准备\n    \"\"\"\n    if not is_any_api_key(llm_kwargs['api_key']):\n        raise AssertionError(\"你提供了错误的API_KEY。\\n\\n1. 临时解决方案：直接在输入区键入api_key，然后回车提交。\\n\\n2. 长效解决方案：在config.py中配置。\")\n\n    api_key = select_api_key(llm_kwargs['api_key'], llm_kwargs['llm_model'])\n\n    headers = {\n        \"Content-Type\": \"application/json\",\n        \"Authorization\": f\"Bearer {api_key}\"\n    }\n    if API_ORG.startswith('org-'): headers.update({\"OpenAI-Organization\": API_ORG})\n    if llm_kwargs['llm_model'].startswith('azure-'):\n        headers.update({\"api-key\": api_key})\n        if llm_kwargs['llm_model'] in AZURE_CFG_ARRAY.keys():\n            azure_api_key_unshared = AZURE_CFG_ARRAY[llm_kwargs['llm_model']][\"AZURE_API_KEY\"]\n            headers.update({\"api-key\": azure_api_key_unshared})\n\n    base64_images = []\n    for image_path in image_paths:\n        base64_images.append(encode_image(image_path))\n","sourceCodeStart":233,"sourceCodeEnd":269,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/request_llms/bridge_chatgpt_vision.py#L233-L269","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Temporary: paste the API key into the input area and submit, then retry the image request.","Permanent: set API_KEY in config_private.py and restart gpt_academic.","For azure- vision models, also fill the model's AZURE_API_KEY inside AZURE_CFG_ARRAY in config_private.py.","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."],"exampleFix":"# config_private.py\nAPI_KEY = \"sk-your-real-key-here\"\nAZURE_CFG_ARRAY = {\n    \"azure-gpt-4-vision\": {\n        \"AZURE_API_KEY\": \"your-azure-key\",\n        \"AZURE_ENDPOINT\": \"https://your-resource.openai.azure.com\",\n        \"AZURE_API_VERSION\": \"2023-05-15\",\n    }\n}","handlingStrategy":"validation","validationCode":"from toolbox import is_any_api_key\nassert is_any_api_key(API_KEY), \"vision requests need a real API key — set API_KEY in config_private.py\"","typeGuard":null,"tryCatchPattern":"try:\n    payload = generate_payload(inputs, llm_kwargs, history, system_prompt, image_paths)\nexcept AssertionError as e:\n    if 'API_KEY' in str(e):\n        guide_user_to_enter_key_in_input_box()\n    else:\n        raise","preventionTips":["Configure the key before the first image upload; vision has no key-less path.","For azure- vision models fill AZURE_CFG_ARRAY's AZURE_API_KEY as well.","Verify the key has access to a vision-capable model on your provider.","Startup-check both the shared key and per-model Azure keys."],"tags":["openai","vision","api-key","configuration","authentication"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}