binary-husky/gpt_academic · error · RuntimeError
请配置 DASHSCOPE_API_KEY
Error message
请配置 DASHSCOPE_API_KEY
What it means
Constructor guard of QwenRequestInstance in the DashScope (Tongyi Qianwen) client: __init__ reads DASHSCOPE_API_KEY via get_conf and raises RuntimeError('请配置 DASHSCOPE_API_KEY') when it is empty, before assigning dashscope.api_key. Any predict entry in bridge_qwen.py that instantiates this class will fail immediately.
Source
Thrown at request_llms/com_qwenapi.py:21
import threading
timeout_bot_msg = '[Local Message] Request timeout. Network error.'
model_prefix_to_remove = 'dashscope-'
class QwenRequestInstance():
def __init__(self):
import dashscope
self.time_to_yield_event = threading.Event()
self.time_to_exit_event = threading.Event()
self.result_buf = ""
def validate_key():
DASHSCOPE_API_KEY = get_conf("DASHSCOPE_API_KEY")
if DASHSCOPE_API_KEY == '': return False
return True
if not validate_key():
raise RuntimeError('请配置 DASHSCOPE_API_KEY')
dashscope.api_key = get_conf("DASHSCOPE_API_KEY")
def format_reasoning(self, reasoning_content:str, main_content:str):
if reasoning_content:
reasoning_content_paragraphs = ''.join([f'<p style="margin: 1.25em 0;">{line}</p>' for line in reasoning_content.split('\n')])
formatted_reasoning_content = f'<div class="reasoning_process">{reasoning_content_paragraphs}</div>\n\n---\n\n'
return formatted_reasoning_content + main_content
else:
return main_content
def generate(self, inputs, llm_kwargs, history, system_prompt):
# import _thread as thread
from dashscope import Generation
top_p = llm_kwargs.get('top_p', 0.8)
if top_p == 0: top_p += 1e-5
if top_p == 1: top_p -= 1e-5
model_name = llm_kwargs['llm_model']View on GitHub (pinned to d6bde0fa54)
Solutions
- Get a key from DashScope (bailian.console.aliyun.com) and set DASHSCOPE_API_KEY in config_private.py or env, then restart
- If config was changed at runtime, clear the get_conf LRU cache or restart the process
- For docker deployments, add DASHSCOPE_API_KEY to docker-compose.yml environment
Example fix
# before DASHSCOPE_API_KEY = '' # after (config_private.py) DASHSCOPE_API_KEY = 'sk-xxxxxxxxxxxxxxxx'
Defensive patterns
Strategy: validation
Validate before calling
from toolbox import get_conf
assert get_conf('DASHSCOPE_API_KEY'), 'DASHSCOPE_API_KEY not configured' Try / catch
try:
from request_llms.com_qwenapi import QwenRequestInstance
q = QwenRequestInstance()
except RuntimeError as e:
if 'DASHSCOPE_API_KEY' in str(e):
raise ConfigurationError(str(e)) from e
raise Prevention
- Restart the app after editing config; get_conf is LRU-cached
- In docker, fail fast on missing env vars with an entrypoint check
When it happens
Trigger: Instantiating QwenRequestInstance (request_llms/com_qwenapi.py:21) while DASHSCOPE_API_KEY == '' in the resolved configuration. Triggered by selecting a qwen model in the UI or any plugin that spawns the qwen bridge.
Common situations: DASHSCOPE_API_KEY missing from config.py/config_private.py; aliyun DashScope key not propagated into docker container; key added after process start without restart (get_conf uses an LRU cache).
Related errors
- 程序终止。
- 请配置讯飞星火大模型的XFYUN_APPID, XFYUN_API_KEY, XFYUN_API_SECRET
- 请配置 TAICHU_API_KEY
- 请配置ZHIPUAI_API_KEY
- 请配置讯飞星火大模型的XFYUN_APPID, XFYUN_API_KEY, XFYUN_API_SECRET
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/88ef163544af16b0.
Report an issue: GitHub.