binary-husky/gpt_academic · error · RuntimeError
没有配置BAIDU_CLOUD_SECRET_KEY
Error message
没有配置BAIDU_CLOUD_SECRET_KEY
What it means
RuntimeError from get_access_token in bridge_qianfan: the BAIDU_CLOUD_SECRET_KEY read via get_conf is an empty string, so the OAuth client_credentials flow cannot be attempted. It fails before any network call; the companion check for BAIDU_CLOUD_API_KEY sits directly below. get_access_token is cached (timeout=3600), but a raise is not cached so fixing config takes effect on next call after restart.
Source
Thrown at request_llms/bridge_qianfan.py:39
return result
# Call the function and cache the result
result = func(*args, **kwargs)
cache[key] = (result, datetime.now())
return result
return wrapper
return decorator
@cache_decorator(timeout=3600)
def get_access_token():
"""
使用 AK,SK 生成鉴权签名(Access Token)
:return: access_token,或是None(如果错误)
"""
# if (access_token_cache is None) or (time.time() - last_access_token_obtain_time > 3600):
BAIDU_CLOUD_API_KEY, BAIDU_CLOUD_SECRET_KEY = get_conf('BAIDU_CLOUD_API_KEY', 'BAIDU_CLOUD_SECRET_KEY')
if len(BAIDU_CLOUD_SECRET_KEY) == 0: raise RuntimeError("没有配置BAIDU_CLOUD_SECRET_KEY")
if len(BAIDU_CLOUD_API_KEY) == 0: raise RuntimeError("没有配置BAIDU_CLOUD_API_KEY")
url = "https://aip.baidubce.com/oauth/2.0/token"
params = {"grant_type": "client_credentials", "client_id": BAIDU_CLOUD_API_KEY, "client_secret": BAIDU_CLOUD_SECRET_KEY}
access_token_cache = str(requests.post(url, params=params).json().get("access_token"))
return access_token_cache
# else:
# return access_token_cache
def generate_message_payload(inputs, llm_kwargs, history, system_prompt):
conversation_cnt = len(history) // 2
if system_prompt == "": system_prompt = "Hello"
messages = [{"role": "user", "content": system_prompt}]
messages.append({"role": "assistant", "content": 'Certainly!'})
if conversation_cnt:
for index in range(0, 2*conversation_cnt, 2):
what_i_have_asked = {}View on GitHub (pinned to d6bde0fa54)
Solutions
- Set BAIDU_CLOUD_SECRET_KEY in config_private.py (from Baidu Qianfan console > application credentials)
- Also set BAIDU_CLOUD_API_KEY - both are required
- Restart the process after config changes
- If you did not intend to use Qianfan, switch the model back to an OpenAI-compatible one
Example fix
# config_private.py # before BAIDU_CLOUD_SECRET_KEY = "" # after BAIDU_CLOUD_SECRET_KEY = "your-qianfan-secret-key"
Defensive patterns
Strategy: validation
Validate before calling
from shared_utils.config_loader import get_conf
api_key, secret = get_conf('BAIDU_CLOUD_API_KEY', 'BAIDU_CLOUD_SECRET_KEY')
assert api_key and secret, 'Baidu Qianfan credentials missing - set BAIDU_CLOUD_API_KEY and BAIDU_CLOUD_SECRET_KEY' Type guard
def qianfan_configured() -> bool:
api_key, secret = get_conf('BAIDU_CLOUD_API_KEY', 'BAIDU_CLOUD_SECRET_KEY')
return len(api_key) > 0 and len(secret) > 0 Try / catch
try:
token = get_access_token()
except RuntimeError as e:
if 'BAIDU_CLOUD_SECRET_KEY' in str(e):
raise SystemExit('Set BAIDU_CLOUD_SECRET_KEY in config_private.py') from e Prevention
- Gate qianfan model selection on both Baidu keys being non-empty
- Add credential checks to a startup lint so misconfiguration surfaces at boot
- Store keys in config_private.py, never config.py which updates overwrite
When it happens
Trigger: Using a qianfan (Baidu Qianfan/ERNIE) model without setting BAIDU_CLOUD_SECRET_KEY in config_private.py; key defined under the wrong variable name; Docker/env deployment missing the variable.
Common situations: Selecting an ERNIE Bot model in model dropdown before configuring Baidu credentials; copying config template and skipping Baidu section.
Related errors
- 没有配置BAIDU_CLOUD_API_KEY
- 请配置YUNQUE_SECRET_KEY
- 你提供了错误的API_KEY。 1. 临时解决方案:直接在输入区键入api_key,然后回车提交。 2. 长效解决方
- 你提供了错误的API_KEY。 1. 临时解决方案:直接在输入区键入api_key,然后回车提交。 2. 长效解决方
- 没有设置ANTHROPIC_API_KEY选项
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/3957852c47e6e502.
Report an issue: GitHub.