{"record":{"id":"64ee1a5e2bcca3a0","repo":"hsliuping/TradingAgents-CN","slug":"volcengine-api-key-ark-api-key","errorCode":null,"errorMessage":"使用火山方舟需要设置VOLCENGINE_API_KEY或ARK_API_KEY环境变量","messagePattern":"使用火山方舟需要设置VOLCENGINE_API_KEY或ARK_API_KEY环境变量","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"critical","filePath":"tradingagents/graph/trading_graph.py","lineNumber":307,"sourceCode":"            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,\n                backend_url=self.config[\"backend_url\"],\n                api_key=api_key,\n                quick_extra_kwargs=_quick_extra if _quick_extra else None,\n                deep_extra_kwargs=_deep_extra if _deep_extra else None,","sourceCodeStart":289,"sourceCodeEnd":325,"githubUrl":"https://github.com/hsliuping/TradingAgents-CN/blob/74783e8817d6cf6de29867880631cc555153f36b/tradingagents/graph/trading_graph.py#L289-L325","documentation":"TradingAgentsGraph.__init__ raises this when provider is 'volcengine' (Volcengine Ark) and neither VOLCENGINE_API_KEY nor ARK_API_KEY is set. Two env names are accepted because Ark keys were originally exposed as ARK_API_KEY. Failure occurs at construction time, before any model call.","triggerScenarios":"Building the graph with llm_provider=\"volcengine\" while both VOLCENGINE_API_KEY and ARK_API_KEY are missing from the environment.","commonSituations":"Copied Ark key into a differently-named variable (e.g. ARK_API_TOKEN); env not propagated to docker/service; switching providers in config without provisioning the matching key.","solutions":["export VOLCENGINE_API_KEY=... or ARK_API_KEY=...","Persist the variable in .env / compose and ensure dotenv loads before TradingAgentsGraph(...) is called","Double-check the key is for the Ark (方舟) endpoint, not a generic Volcengine AccessKey"],"exampleFix":"# before\ngraph = TradingAgentsGraph(config={\"llm_provider\": \"volcengine\"})\n\n# after\n# export ARK_API_KEY=<ark-key>\ngraph = TradingAgentsGraph(config={\"llm_provider\": \"volcengine\"})","handlingStrategy":"validation","validationCode":"import os\nif provider == \"volcengine\" and not (os.getenv(\"VOLCENGINE_API_KEY\") or os.getenv(\"ARK_API_KEY\")):\n    raise SystemExit(\"Set VOLCENGINE_API_KEY or ARK_API_KEY\")","typeGuard":"def has_volcengine_key() -> bool:\n    return bool(os.getenv(\"VOLCENGINE_API_KEY\") or os.getenv(\"ARK_API_KEY\"))","tryCatchPattern":"try:\n    graph = TradingAgentsGraph(config=cfg)\nexcept ValueError as e:\n    if \"火山方舟\" in str(e):\n        raise SystemExit(\"Provision an Ark API key\") from e\n    raise","preventionTips":["Accept both env names in deployment templates","Distinguish Ark model keys from Volcengine AccessKeys when storing secrets","Add env-var presence checks to CI smoke tests"],"tags":["api-key","missing-env-var","volcengine","ark","llm"],"backgroundTag":"missing-api-key","analyzedSha":"74783e8817d6cf6de29867880631cc555153f36b","analyzedAt":"2026-08-28T11:39:07.729Z","schemaVersion":2},"datasetVersion":"2026-08-28T16:17:29.566Z"}