binary-husky/gpt_academic · error · RuntimeError

请配置讯飞星火大模型的XFYUN_APPID, XFYUN_API_KEY, XFYUN_API_SECRET

Error message

请配置讯飞星火大模型的XFYUN_APPID, XFYUN_API_KEY, XFYUN_API_SECRET

What it means

Constructor guard of SparkRequestInstance: it loads XFYUN_APPID / XFYUN_API_SECRET / XFYUN_API_KEY with get_conf and raises unless XFYUN_APPID differs from the placeholder '00000000' and the empty string. This complements bridge_spark.py's validate_key by also catching the shipped placeholder value, and fires when any Spark predict path (chat or image) builds a request instance.

Source

Thrown at request_llms/com_sparkapi.py:62

        authorization = base64.b64encode(authorization_origin.encode('utf-8')).decode(encoding='utf-8')

        # 将请求的鉴权参数组合为字典
        v = {
            "authorization": authorization,
            "date": date,
            "host": self.host
        }
        # 拼接鉴权参数,生成url
        url = self.gpt_url + '?' + urlencode(v)
        # 此处打印出建立连接时候的url,参考本demo的时候可取消上方打印的注释,比对相同参数时生成的url与自己代码生成的url是否一致
        return url



class SparkRequestInstance():
    def __init__(self):
        XFYUN_APPID, XFYUN_API_SECRET, XFYUN_API_KEY = get_conf('XFYUN_APPID', 'XFYUN_API_SECRET', 'XFYUN_API_KEY')
        if XFYUN_APPID == '00000000' or XFYUN_APPID == '': raise RuntimeError('请配置讯飞星火大模型的XFYUN_APPID, XFYUN_API_KEY, XFYUN_API_SECRET')
        self.appid = XFYUN_APPID
        self.api_secret = XFYUN_API_SECRET
        self.api_key = XFYUN_API_KEY
        self.gpt_url = "ws://spark-api.xf-yun.com/v1.1/chat"
        self.gpt_url_v2 = "ws://spark-api.xf-yun.com/v2.1/chat"
        self.gpt_url_v3 = "ws://spark-api.xf-yun.com/v3.1/chat"
        self.gpt_url_v35 = "wss://spark-api.xf-yun.com/v3.5/chat"
        self.gpt_url_img = "wss://spark-api.cn-huabei-1.xf-yun.com/v2.1/image"
        self.gpt_url_v4 = "wss://spark-api.xf-yun.com/v4.0/chat"

        self.time_to_yield_event = threading.Event()
        self.time_to_exit_event = threading.Event()

        self.result_buf = ""

    def generate(self, inputs, llm_kwargs, history, system_prompt, use_image_api=False):
        llm_kwargs = llm_kwargs
        history = history

View on GitHub (pinned to d6bde0fa54)

Solutions

  1. Set all three values (APPID is 8 hex chars from the iFlytek console) in config_private.py and restart
  2. Check that config_private.py is actually the file being loaded and that no env var overrides XFYUN_APPID back to a placeholder
  3. After runtime config edits, restart or clear the get_conf cache
  4. Validate: from toolbox import get_conf; appid, sec, key = get_conf('XFYUN_APPID','XFYUN_API_SECRET','XFYUN_API_KEY'); assert appid not in ('', '00000000')

Example fix

# before (config.py defaults)
XFYUN_APPID = '00000000'
XFYUN_API_KEY = ''
XFYUN_API_SECRET = ''

# after (config_private.py)
XFYUN_APPID = '1a2b3c4d'
XFYUN_API_KEY = 'real-key'
XFYUN_API_SECRET = 'real-secret'
Defensive patterns

Strategy: validation

Validate before calling

from toolbox import get_conf
appid, sec, key = get_conf('XFYUN_APPID', 'XFYUN_API_SECRET', 'XFYUN_API_KEY')
assert appid not in ('', '00000000'), 'XFYUN_APPID is still the placeholder'

Try / catch

try:
    sri = SparkRequestInstance()
except RuntimeError as e:
    if 'XFYUN' in str(e):
        raise ConfigurationError('Spark credentials not set (appid placeholder?)') from e
    raise

Prevention

When it happens

Trigger: Constructing SparkRequestInstance in request_llms/com_sparkapi.py:62 while XFYUN_APPID is still the default '00000000' (config.py placeholder) or '' — i.e. the appid was never replaced even if api_key/api_secret were set.

Common situations: User set XFYUN_API_KEY/SECRET but forgot APPID; docker image built with default config.py; appid copied with surrounding quotes/whitespace so it equals placeholder; get_conf LRU cache still serving old values after editing config.

Related errors


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