{"record":{"id":"3f9a1b4041f8256b","repo":"binary-husky/gpt_academic","slug":"xfyun-appid-xfyun-api-key-xfyun-api-s-3f9a1b","errorCode":null,"errorMessage":"请配置讯飞星火大模型的XFYUN_APPID, XFYUN_API_KEY, XFYUN_API_SECRET","messagePattern":"请配置讯飞星火大模型的XFYUN_APPID, XFYUN_API_KEY, XFYUN_API_SECRET","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"request_llms/com_sparkapi.py","lineNumber":62,"sourceCode":"        authorization = base64.b64encode(authorization_origin.encode('utf-8')).decode(encoding='utf-8')\n\n        # 将请求的鉴权参数组合为字典\n        v = {\n            \"authorization\": authorization,\n            \"date\": date,\n            \"host\": self.host\n        }\n        # 拼接鉴权参数，生成url\n        url = self.gpt_url + '?' + urlencode(v)\n        # 此处打印出建立连接时候的url,参考本demo的时候可取消上方打印的注释，比对相同参数时生成的url与自己代码生成的url是否一致\n        return url\n\n\n\nclass SparkRequestInstance():\n    def __init__(self):\n        XFYUN_APPID, XFYUN_API_SECRET, XFYUN_API_KEY = get_conf('XFYUN_APPID', 'XFYUN_API_SECRET', 'XFYUN_API_KEY')\n        if XFYUN_APPID == '00000000' or XFYUN_APPID == '': raise RuntimeError('请配置讯飞星火大模型的XFYUN_APPID, XFYUN_API_KEY, XFYUN_API_SECRET')\n        self.appid = XFYUN_APPID\n        self.api_secret = XFYUN_API_SECRET\n        self.api_key = XFYUN_API_KEY\n        self.gpt_url = \"ws://spark-api.xf-yun.com/v1.1/chat\"\n        self.gpt_url_v2 = \"ws://spark-api.xf-yun.com/v2.1/chat\"\n        self.gpt_url_v3 = \"ws://spark-api.xf-yun.com/v3.1/chat\"\n        self.gpt_url_v35 = \"wss://spark-api.xf-yun.com/v3.5/chat\"\n        self.gpt_url_img = \"wss://spark-api.cn-huabei-1.xf-yun.com/v2.1/image\"\n        self.gpt_url_v4 = \"wss://spark-api.xf-yun.com/v4.0/chat\"\n\n        self.time_to_yield_event = threading.Event()\n        self.time_to_exit_event = threading.Event()\n\n        self.result_buf = \"\"\n\n    def generate(self, inputs, llm_kwargs, history, system_prompt, use_image_api=False):\n        llm_kwargs = llm_kwargs\n        history = history","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/request_llms/com_sparkapi.py#L44-L80","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Set all three values (APPID is 8 hex chars from the iFlytek console) in config_private.py and restart","Check that config_private.py is actually the file being loaded and that no env var overrides XFYUN_APPID back to a placeholder","After runtime config edits, restart or clear the get_conf cache","Validate: from toolbox import get_conf; appid, sec, key = get_conf('XFYUN_APPID','XFYUN_API_SECRET','XFYUN_API_KEY'); assert appid not in ('', '00000000')"],"exampleFix":"# before (config.py defaults)\nXFYUN_APPID = '00000000'\nXFYUN_API_KEY = ''\nXFYUN_API_SECRET = ''\n\n# after (config_private.py)\nXFYUN_APPID = '1a2b3c4d'\nXFYUN_API_KEY = 'real-key'\nXFYUN_API_SECRET = 'real-secret'","handlingStrategy":"validation","validationCode":"from toolbox import get_conf\nappid, sec, key = get_conf('XFYUN_APPID', 'XFYUN_API_SECRET', 'XFYUN_API_KEY')\nassert appid not in ('', '00000000'), 'XFYUN_APPID is still the placeholder'","typeGuard":null,"tryCatchPattern":"try:\n    sri = SparkRequestInstance()\nexcept RuntimeError as e:\n    if 'XFYUN' in str(e):\n        raise ConfigurationError('Spark credentials not set (appid placeholder?)') from e\n    raise","preventionTips":["Treat placeholder values as missing: check both '' and '00000000'","Copy the 8-char APPID from the iFlytek console exactly","Restart after config edits due to the get_conf LRU cache"],"tags":["config","authentication","xfyun-spark","placeholder"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}