{"record":{"id":"2df7e013adabc1b6","repo":"hsliuping/TradingAgents-CN","slug":"api-key-web-qia","errorCode":null,"errorMessage":"千帆模型需要配置 API Key。请在 Web 界面配置 (设置 -> 大模型厂家) 或设置 QIANFAN_API_KEY 环境变量，格式为: bce-v3/ALTAK-xxx/xxx","messagePattern":"千帆模型需要配置 API Key。请在 Web 界面配置 \\(设置 -> 大模型厂家\\) 或设置 QIANFAN_API_KEY 环境变量，格式为: bce-v3/ALTAK-xxx/xxx","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"tradingagents/llm_adapters/openai_compatible_base.py","lineNumber":283,"sourceCode":"                        return False\n                    if key.startswith('your_') or key.startswith('your-'):\n                        return False\n                    if key.endswith('_here') or key.endswith('-here'):\n                        return False\n                    if '...' in key:\n                        return False\n                    return True\n\n            env_api_key = os.getenv('QIANFAN_API_KEY')\n            if env_api_key and is_valid_api_key(env_api_key):\n                qianfan_api_key = env_api_key\n            else:\n                qianfan_api_key = None\n        else:\n            qianfan_api_key = api_key\n\n        if not qianfan_api_key:\n            raise ValueError(\n                \"千帆模型需要配置 API Key。\"\n                \"请在 Web 界面配置 (设置 -> 大模型厂家) 或设置 QIANFAN_API_KEY 环境变量，\"\n                \"格式为: bce-v3/ALTAK-xxx/xxx\"\n            )\n\n        if not qianfan_api_key.startswith('bce-v3/'):\n            raise ValueError(\n                \"QIANFAN_API_KEY格式错误，应为: bce-v3/ALTAK-xxx/xxx\"\n            )\n        \n        super().__init__(\n            provider_name=\"qianfan\",\n            model=model,\n            api_key_env_var=\"QIANFAN_API_KEY\",\n            base_url=\"https://qianfan.baidubce.com/v2\",\n            api_key=qianfan_api_key,\n            temperature=temperature,\n            max_tokens=max_tokens,","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/hsliuping/TradingAgents-CN/blob/74783e8817d6cf6de29867880631cc555153f36b/tradingagents/llm_adapters/openai_compatible_base.py#L265-L301","documentation":"The Qianfan (Baidu) branch of OpenAICompatibleBase.__init__ raises this when no API key is found from kwargs/config or the QIANFAN_API_KEY environment variable. Baidu Qianfan keys have a distinctive composite format (bce-v3/ALTAK-xxx/xxx), which the message documents. Thrown before the format check and parent init.","triggerScenarios":"Creating the Qianfan adapter without api_key while QIANFAN_API_KEY is unset; common when the user copied an old-style QIANFAN_ACCESS_KEY/SECRET pair instead of the new bce-v3 API key.","commonSituations":"Migrating from Qianfan SDK auth (AK/SK) to the API-key model; key stored in web UI but adapter constructed directly; env var misspelled; empty-string env value.","solutions":["Generate a bce-v3 API key in the Baidu Qianfan console and export QIANFAN_API_KEY='bce-v3/ALTAK-xxx/xxx'","Or configure the key in the web UI (设置 -> 大模型厂家) so it is passed via api_key kwarg","Verify with: python -c \"import os; print(os.getenv('QIANFAN_API_KEY','')[:7])\" — should print 'bce-v3/'"],"exampleFix":"# before\n# QIANFAN_API_KEY unset or old AK/SK\nllm = create_llm_client(provider=\"qianfan\", model=\"ernie-4.0\")\n\n# after\n# export QIANFAN_API_KEY='bce-v3/ALTAK-xxxx/yyyy'\nllm = create_llm_client(provider=\"qianfan\", model=\"ernie-4.0\")","handlingStrategy":"validation","validationCode":"import os\nk = api_key or os.getenv(\"QIANFAN_API_KEY\")\nif not k:\n    raise SystemExit(\"Set QIANFAN_API_KEY='bce-v3/ALTAK-xxx/xxx' (new-style key, not AK/SK)\")","typeGuard":"def has_qianfan_key(api_key: str | None) -> bool:\n    return bool(api_key or os.getenv(\"QIANFAN_API_KEY\"))","tryCatchPattern":"try:\n    llm = create_llm_client(provider=\"qianfan\", model=m)\nexcept ValueError as e:\n    if \"千帆\" in str(e):\n        raise SystemExit(\"Provision bce-v3 Qianfan API key\") from e\n    raise","preventionTips":["Use the console-generated bce-v3 API key, not legacy AK/SK","Store the full composite key verbatim (no truncation)","Preflight presence and format before adapter creation"],"tags":["api-key","missing-env-var","qianfan","baidu","llm"],"backgroundTag":"missing-api-key","analyzedSha":"74783e8817d6cf6de29867880631cc555153f36b","analyzedAt":"2026-08-28T11:39:07.729Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}