TauricResearch/TradingAgents · error · AlphaVantageNotConfiguredError
ALPHA_VANTAGE_API_KEY environment variable is not set.
Error message
ALPHA_VANTAGE_API_KEY environment variable is not set.
What it means
Raised by get_api_key() in tradingagents/dataflows/alpha_vantage_common.py when the ALPHA_VANTAGE_API_KEY environment variable is unset or empty. It is an AlphaVantageNotConfiguredError, a subclass of VendorNotConfiguredError (which is also a ValueError), so the router treats it as 'vendor unavailable' and tries the next vendor in the chain. It only surfaces to you when no configured vendor can serve the request.
Source
Thrown at tradingagents/dataflows/alpha_vantage_common.py:32
# CLI/agents indefinitely (#990).
REQUEST_TIMEOUT = 30
class AlphaVantageNotConfiguredError(VendorNotConfiguredError):
"""Raised when Alpha Vantage is selected but no API key is configured.
A VendorNotConfiguredError (and thus still a ValueError), so the routing
layer's "vendor unavailable" handling and existing ValueError callers both
keep working.
"""
pass
def get_api_key() -> str:
"""Retrieve the API key for Alpha Vantage from environment variables."""
api_key = os.getenv("ALPHA_VANTAGE_API_KEY")
if not api_key:
raise AlphaVantageNotConfiguredError(
"ALPHA_VANTAGE_API_KEY environment variable is not set."
)
return api_key
def format_datetime_for_api(date_input) -> str:
"""Convert various date formats to YYYYMMDDTHHMM format required by Alpha Vantage API."""
if isinstance(date_input, str):
# If already in correct format, return as-is
if len(date_input) == 13 and 'T' in date_input:
return date_input
# Try to parse common date formats
try:
dt = datetime.strptime(date_input, "%Y-%m-%d")
return dt.strftime("%Y%m%dT0000")
except ValueError:
try:
dt = datetime.strptime(date_input, "%Y-%m-%d %H:%M")
return dt.strftime("%Y%m%dT%H%M")View on GitHub (pinned to a33fd4c0f1)
Solutions
- Export the key in the shell where you run the app: export ALPHA_VANTAGE_API_KEY="yourkey" (get a free key at https://www.alphavantage.co/support/#api-key)
- If the project uses a .env file, add ALPHA_VANTAGE_API_KEY=... there and confirm it is loaded before dataflows code runs
- For Docker/CI, pass the variable explicitly: docker run -e ALPHA_VANTAGE_API_KEY=... or set it in the pipeline secrets
- If you do not want Alpha Vantage, change config data_vendors (or tool_vendors) for the category back to 'yfinance' or 'default' so alpha_vantage is never attempted
Example fix
# before
# (ALPHA_VANTAGE_API_KEY not set, data_vendors="alpha_vantage")
# -> AlphaVantageNotConfiguredError: ALPHA_VANTAGE_API_KEY environment variable is not set.
# after
export ALPHA_VANTAGE_API_KEY="yourkey" # in shell / .env / docker -e
# or switch the vendor
# config: {"data_vendors": {"stock_data": "yfinance"}} Defensive patterns
Strategy: validation
Validate before calling
import os
from tradingagents.dataflows.alpha_vantage_common import AlphaVantageNotConfiguredError
def alpha_vantage_ready() -> bool:
return bool(os.getenv("ALPHA_VANTAGE_API_KEY")) Type guard
def is_configured_env(name: str) -> bool:
v = os.getenv(name)
return isinstance(v, str) and v.strip() != "" Try / catch
try:
get_historical_prices("AAPL", "2025-01-10", "2025-01-15")
except AlphaVantageNotConfiguredError as e: # also a ValueError
logger.warning("Alpha Vantage skipped: %s", e)
# fall back to yfinance explicitly, or report data unavailable Prevention
- Put ALPHA_VANTAGE_API_KEY in your .env / shell profile and confirm with printenv before running
- Pass env vars explicitly in Docker (docker run -e) and CI secrets
- Configure a vendor chain (data_vendors="alpha_vantage,yfinance") so a missing key degrades instead of aborting
When it happens
Trigger: Calling any Alpha Vantage-backed tool (get_stock_data_indicators, get_historical_prices, etc.) with data_vendors containing 'alpha_vantage' while the ALPHA_VANTAGE_API_KEY env var is not exported, is set to an empty string, or is only set in a shell where the process wasn't restarted.
Common situations: New machine/container without the key in .env or the shell profile; running in CI or Docker where the env var was not passed (--env/-e omitted); typos in the variable name; assuming yfinance works the same without keys after switching the data_vendors config to alpha_vantage.
Related errors
- Alpha Vantage API key invalid or missing: {notice}
- FRED_API_KEY environment variable is not set. Get a free key
- Unsupported date format: {date_input}
- Date must be string or datetime object, got {type(date_input
- Alpha Vantage rate limit exceeded: {notice}
AI-assisted analysis of TauricResearch/TradingAgents@a33fd4c0f1 (2026-08-14).
Data as JSON: /api/errors/85f8e5815b0b0a85.
Report an issue: GitHub.