{"record":{"id":"9f04c908b5eed447","repo":"binary-husky/gpt_academic","slug":"api-key-1-api-key-9f04c9","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":"error","filePath":"request_llms/bridge_openrouter.py","lineNumber":414,"sourceCode":"        chatbot[-1] = (chatbot[-1][0], \"[Local Message] API key has been deactivated. OpenAI以账户失效为由, 拒绝服务.\" + openai_website)\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\ndef generate_payload(inputs:str, llm_kwargs:dict, history:list, system_prompt:str, image_base64_array:list=[], has_multimodal_capacity:bool=False, stream:bool=True):\n    \"\"\"\n    整合所有信息，选择LLM模型，生成http请求，为发送请求做准备\n    \"\"\"\n    from request_llms.bridge_all import model_info\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    if llm_kwargs['llm_model'].startswith('vllm-'):\n        api_key = 'no-api-key'\n    else:\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    if has_multimodal_capacity:","sourceCodeStart":396,"sourceCodeEnd":432,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/request_llms/bridge_openrouter.py#L396-L432","documentation":"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.","triggerScenarios":"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.","commonSituations":"First-run without editing config_private.py; Docker deploy missing the env var; user typed the key into the wrong config field.","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"],"exampleFix":"# config_private.py\n# before\nAPI_KEY = \"\"\n\n# after\nAPI_KEY = \"sk-xxxxxxxxxxxxxxxx\"","handlingStrategy":"validation","validationCode":"from common_utils import is_any_api_key\nif not is_any_api_key(llm_kwargs.get('api_key', '')):\n    raise SystemExit('Configure API_KEY in config_private.py before calling LLM functions')","typeGuard":"def has_valid_api_key(llm_kwargs: dict) -> bool:\n    return is_any_api_key(llm_kwargs.get('api_key', ''))","tryCatchPattern":"try:\n    payload = generate_payload(inputs, llm_kwargs, history, system_prompt)\nexcept AssertionError as e:\n    prompt_user_for_api_key(chatbot)  # WebUI flow: let them paste it\n    return","preventionTips":["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"],"tags":["openrouter","api-key","configuration","authentication"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}