hsliuping/TradingAgents-CN · critical · ValueError
使用火山方舟编程需要设置VOLCENGINE_CODING_API_KEY环境变量
Error message
使用火山方舟编程需要设置VOLCENGINE_CODING_API_KEY环境变量
What it means
TradingAgentsGraph.__init__ raises this when provider is 'volcengine_coding' and VOLCENGINE_CODING_API_KEY is unset. This is the separate Volcengine coding-plan credential, distinct from the general Ark key. Raised during LLM client pair creation at graph construction.
Source
Thrown at tradingagents/graph/trading_graph.py:311
api_key = os.getenv('SILICONFLOW_API_KEY')
if not api_key:
raise ValueError("使用SiliconFlow需要设置SILICONFLOW_API_KEY环境变量")
elif provider == "openrouter":
api_key = os.getenv('OPENROUTER_API_KEY') or os.getenv('OPENAI_API_KEY')
if not api_key:
raise ValueError("使用OpenRouter需要设置OPENROUTER_API_KEY或OPENAI_API_KEY环境变量")
elif provider == "aihubmix":
api_key = os.getenv('AIHUBMIX_API_KEY')
if not api_key:
raise ValueError("使用AiHubMix需要设置AIHUBMIX_API_KEY环境变量")
elif provider == "volcengine":
api_key = os.getenv('VOLCENGINE_API_KEY') or os.getenv('ARK_API_KEY')
if not api_key:
raise ValueError("使用火山方舟需要设置VOLCENGINE_API_KEY或ARK_API_KEY环境变量")
elif provider == "volcengine_coding":
api_key = os.getenv('VOLCENGINE_CODING_API_KEY')
if not api_key:
raise ValueError("使用火山方舟编程需要设置VOLCENGINE_CODING_API_KEY环境变量")
self.deep_thinking_llm, self.quick_thinking_llm = _create_provider_pair(
provider=provider,
config=self.config,
quick_temperature=quick_temperature,
quick_max_tokens=quick_max_tokens,
quick_timeout=quick_timeout,
deep_temperature=deep_temperature,
deep_max_tokens=deep_max_tokens,
deep_timeout=deep_timeout,
backend_url=self.config["backend_url"],
api_key=api_key,
quick_extra_kwargs=_quick_extra if _quick_extra else None,
deep_extra_kwargs=_deep_extra if _deep_extra else None,
)
elif normalized_provider == "anthropic":
from langchain_anthropic import ChatAnthropic
View on GitHub (pinned to 74783e8817)
Solutions
- export VOLCENGINE_CODING_API_KEY=<coding-plan-key>
- Ensure .env / compose environment includes it and dotenv loads before graph init
- Confirm your Volcengine account actually has a coding-plan key — a regular ARK key will not be accepted here
Example fix
# before
# only VOLCENGINE_API_KEY set
graph = TradingAgentsGraph(config={"llm_provider": "volcengine_coding"})
# after
# export VOLCENGINE_CODING_API_KEY=<coding-key>
graph = TradingAgentsGraph(config={"llm_provider": "volcengine_coding"}) Defensive patterns
Strategy: validation
Validate before calling
import os
if provider == "volcengine_coding" and not os.getenv("VOLCENGINE_CODING_API_KEY"):
raise SystemExit("Set VOLCENGINE_CODING_API_KEY (coding-plan credential)") Type guard
def has_volcengine_coding_key() -> bool:
return bool(os.getenv("VOLCENGINE_CODING_API_KEY")) Try / catch
try:
graph = TradingAgentsGraph(config=cfg)
except ValueError as e:
if "VOLCENGINE_CODING_API_KEY" in str(e):
raise SystemExit("Provision coding-plan key") from e
raise Prevention
- Document that coding-plan keys differ from general Ark keys
- Namespace secrets clearly in your secret store
- Preflight-check the exact env name for the chosen provider
When it happens
Trigger: llm_provider="volcengine_coding" in config without VOLCENGINE_CODING_API_KEY exported in the running process.
Common situations: User set VOLCENGINE_API_KEY thinking it covers the coding plan tier; env var missing in containerized deployment; typo in variable name.
Understand the failure class
Background: "API key is required" / "API key not found" / "No API key was set": the missing-api-key error family across 16 libraries — this error's family across 16 libraries.
Related errors
- 使用火山方舟需要设置VOLCENGINE_API_KEY或ARK_API_KEY环境变量
- 使用Google需要设置GOOGLE_API_KEY环境变量或在数据库中配置API Key
- 使用SiliconFlow需要设置SILICONFLOW_API_KEY环境变量
- 使用OpenRouter需要设置OPENROUTER_API_KEY或OPENAI_API_KEY环境变量
- 使用AiHubMix需要设置AIHUBMIX_API_KEY环境变量
AI-assisted analysis of hsliuping/TradingAgents-CN@74783e8817 (2026-08-28).
Data as JSON: /api/errors/df27ccb19d1509d4.
Report an issue: GitHub.