{"record":{"id":"b7287b226cb6935f","repo":"hsliuping/TradingAgents-CN","slug":"aihubmix-aihubmix-api-key","errorCode":null,"errorMessage":"使用AiHubMix需要设置AIHUBMIX_API_KEY环境变量","messagePattern":"使用AiHubMix需要设置AIHUBMIX_API_KEY环境变量","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"tradingagents/graph/trading_graph.py","lineNumber":303,"sourceCode":"\n        elif normalized_provider in {\"openai\", \"siliconflow\", \"openrouter\", \"aihubmix\", \"volcengine\", \"ollama\"}:\n            provider = normalized_provider\n            logger.info(f\"🔧 [{provider}-快速模型] max_tokens={quick_max_tokens}, temperature={quick_temperature}, timeout={quick_timeout}s\")\n            logger.info(f\"🔧 [{provider}-深度模型] max_tokens={deep_max_tokens}, temperature={deep_temperature}, timeout={deep_timeout}s\")\n\n            api_key = None\n            if provider == \"siliconflow\":\n                api_key = os.getenv('SILICONFLOW_API_KEY')\n                if not api_key:\n                    raise ValueError(\"使用SiliconFlow需要设置SILICONFLOW_API_KEY环境变量\")\n            elif provider == \"openrouter\":\n                api_key = os.getenv('OPENROUTER_API_KEY') or os.getenv('OPENAI_API_KEY')\n                if not api_key:\n                    raise ValueError(\"使用OpenRouter需要设置OPENROUTER_API_KEY或OPENAI_API_KEY环境变量\")\n            elif provider == \"aihubmix\":\n                api_key = os.getenv('AIHUBMIX_API_KEY')\n                if not api_key:\n                    raise ValueError(\"使用AiHubMix需要设置AIHUBMIX_API_KEY环境变量\")\n            elif provider == \"volcengine\":\n                api_key = os.getenv('VOLCENGINE_API_KEY') or os.getenv('ARK_API_KEY')\n                if not api_key:\n                    raise ValueError(\"使用火山方舟需要设置VOLCENGINE_API_KEY或ARK_API_KEY环境变量\")\n            elif provider == \"volcengine_coding\":\n                api_key = os.getenv('VOLCENGINE_CODING_API_KEY')\n                if not api_key:\n                    raise ValueError(\"使用火山方舟编程需要设置VOLCENGINE_CODING_API_KEY环境变量\")\n\n            self.deep_thinking_llm, self.quick_thinking_llm = _create_provider_pair(\n                provider=provider,\n                config=self.config,\n                quick_temperature=quick_temperature,\n                quick_max_tokens=quick_max_tokens,\n                quick_timeout=quick_timeout,\n                deep_temperature=deep_temperature,\n                deep_max_tokens=deep_max_tokens,\n                deep_timeout=deep_timeout,","sourceCodeStart":285,"sourceCodeEnd":321,"githubUrl":"https://github.com/hsliuping/TradingAgents-CN/blob/74783e8817d6cf6de29867880631cc555153f36b/tradingagents/graph/trading_graph.py#L285-L321","documentation":"TradingAgentsGraph.__init__ raises this when provider is 'aihubmix' and the AIHUBMIX_API_KEY environment variable is unset. AiHubMix is an OpenAI-compatible aggregator and this branch reads the key strictly from the environment. Thrown during graph construction before any LLM call.","triggerScenarios":"Constructing TradingAgentsGraph (or the web app backend) with llm_provider=\"aihubmix\" and no AIHUBMIX_API_KEY in the process environment.","commonSituations":"Key configured only in the web UI DB but the code path reads env; .env not loaded; deploying to a new server without copying secrets.","solutions":["export AIHUBMIX_API_KEY=... before starting the app","Add AIHUBMIX_API_KEY to .env / container environment and verify it is loaded prior to graph construction","If running the bundled web app, also save the key in Settings so DB-backed paths work"],"exampleFix":"# before\ngraph = TradingAgentsGraph(config={\"llm_provider\": \"aihubmix\"})\n\n# after\nimport os; assert os.getenv(\"AIHUBMIX_API_KEY\"), \"set AIHUBMIX_API_KEY first\"\ngraph = TradingAgentsGraph(config={\"llm_provider\": \"aihubmix\"})","handlingStrategy":"validation","validationCode":"import os\nif provider == \"aihubmix\" and not os.getenv(\"AIHUBMIX_API_KEY\"):\n    raise SystemExit(\"Set AIHUBMIX_API_KEY before constructing the graph\")","typeGuard":"def has_aihubmix_key() -> bool:\n    return bool(os.getenv(\"AIHUBMIX_API_KEY\"))","tryCatchPattern":"try:\n    graph = TradingAgentsGraph(config=cfg)\nexcept ValueError as e:\n    if \"AIHUBMIX\" in str(e):\n        raise SystemExit(\"Configure AIHUBMIX_API_KEY\") from e\n    raise","preventionTips":["Maintain a secrets checklist per provider in deployment docs","Use a preflight env validation step in the app entrypoint","Copy .env when migrating deployments"],"tags":["api-key","missing-env-var","aihubmix","llm","configuration"],"backgroundTag":"missing-api-key","analyzedSha":"74783e8817d6cf6de29867880631cc555153f36b","analyzedAt":"2026-08-28T11:39:07.729Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}