TauricResearch/TradingAgents · error · AlphaVantageNotConfiguredError
Alpha Vantage API key invalid or missing: {notice}
Error message
Alpha Vantage API key invalid or missing: {notice} What it means
Raised by _make_api_request() in tradingagents/dataflows/alpha_vantage_common.py when Alpha Vantage's 'Information'/'Note' notice mentions 'api key'/'apikey' without rate-limit phrasing — i.e. the key is invalid, not passed, or lacks entitlement. It deliberately reuses AlphaVantageNotConfiguredError (a VendorNotConfiguredError and ValueError) so a bad key surfaces as an actionable configuration failure rather than being mislabeled a rate limit (#991). The router treats it as 'vendor unavailable' and tries the next vendor.
Source
Thrown at tradingagents/dataflows/alpha_vantage_common.py:110
# JSON). A non-JSON body is normal data.
try:
response_json = json.loads(response_text)
except json.JSONDecodeError:
return response_text
# Alpha Vantage reports problems via "Information" / "Note". Classify so a
# genuine rate limit and an invalid/missing key aren't conflated (#991):
# rate-limit phrasing is checked first because those notices also mention
# "API key" ("your API key ... 25 requests per day").
notice = response_json.get("Information") or response_json.get("Note")
if notice:
low = notice.lower()
if any(m in low for m in ("rate limit", "requests per day", "call frequency", "premium")):
raise AlphaVantageRateLimitError(f"Alpha Vantage rate limit exceeded: {notice}")
if "api key" in low or "apikey" in low:
# Reuse the existing "not configured" error so a bad key surfaces as
# a real, actionable failure rather than a mislabeled rate limit (#991).
raise AlphaVantageNotConfiguredError(f"Alpha Vantage API key invalid or missing: {notice}")
return response_text
def _filter_csv_by_date_range(csv_data: str, start_date: str, end_date: str) -> str:
"""
Filter CSV data to include only rows within the specified date range.
Args:
csv_data: CSV string from Alpha Vantage API
start_date: Start date in yyyy-mm-dd format
end_date: End date in yyyy-mm-dd format
Returns:
Filtered CSV string
"""
if not csv_data or csv_data.strip() == "":View on GitHub (pinned to a33fd4c0f1)
Solutions
- Verify the key: curl 'https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=IBM&apikey=YOURKEY' should return data, not an 'Information' note
- Fix the stored value: strip whitespace/quotes, re-export ALPHA_VANTAGE_API_KEY, restart the process (and update CI/Docker secrets)
- If the notice is about entitlement, upgrade the key tier or switch that tool to a vendor that covers it (tool_vendors config)
- Add 'yfinance' after alpha_vantage in data_vendors so the router falls through when the key is rejected
Example fix
# before
export ALPHA_VANTAGE_API_KEY=" demo " # stray spaces/invalid key
# -> AlphaVantageNotConfiguredError: Alpha Vantage API key invalid or missing: ...
# after
export ALPHA_VANTAGE_API_KEY="YOUR_CLEAN_KEY" # validated via a direct curl first
# optional resilience: {"data_vendors": {"stock_data": "alpha_vantage,yfinance"}} Defensive patterns
Strategy: validation
Validate before calling
import os, requests
def alpha_vantage_key_works() -> bool | str:
key = (os.getenv("ALPHA_VANTAGE_API_KEY") or "").strip()
if not key:
return False
r = requests.get("https://www.alphavantage.co/query", params={"function": "TIME_SERIES_DAILY", "symbol": "IBM", "apikey": key}, timeout=15)
js = r.json()
return not ("Information" in js or "Note" in js) Try / catch
from tradingagents.dataflows.alpha_vantage_common import AlphaVantageNotConfiguredError
try:
data = get_historical_prices(sym, start, end)
except AlphaVantageNotConfiguredError as e:
if "invalid or missing" in str(e):
alert_ops(f"Alpha Vantage key rejected: {e}") # config bug, do not retry
raise Prevention
- Strip whitespace/quotes when setting the env var; never copy keys with formatting
- Smoke-test the key with one direct curl/query after setup and after rotation
- Keep CI/Docker secrets in sync when the key is rotated
- Include a second vendor in the chain so a rejected key degrades instead of failing the run
When it happens
Trigger: Setting ALPHA_VANTAGE_API_KEY to a wrong/revoked/demo key; a key with spaces or quotes pasted from email; a valid key used for an endpoint its tier does not allow (non-rate-limit premium notice). Distinct from a genuinely missing env var (error [0]) — here the key is present but rejected.
Common situations: Copy-paste artifacts (trailing whitespace, curly quotes) in the env var; using the literature 'demo' key on real endpoints; expired keys after account changes; keys rotated but the old value still in .env or CI secrets.
Related errors
- ALPHA_VANTAGE_API_KEY environment variable is not set.
- 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/459bc5ce2badbcb5.
Report an issue: GitHub.