TauricResearch/TradingAgents · warning · AlphaVantageRateLimitError

Alpha Vantage rate limit exceeded: {notice}

Error message

Alpha Vantage rate limit exceeded: {notice}

What it means

Raised by _make_api_request() in tradingagents/dataflows/alpha_vantage_common.py when Alpha Vantage's JSON response carries an 'Information' or 'Note' field whose text mentions 'rate limit', 'requests per day', 'call frequency', or 'premium'. It is an AlphaVantageRateLimitError (subclass of VendorRateLimitError, not a ValueError), signalling a transient throttle so the router in interface.py skips to the next configured vendor instead of aborting.

Source

Thrown at tradingagents/dataflows/alpha_vantage_common.py:106

    response_text = response.text

    # Error responses are JSON; data responses are usually CSV (or data-keyed
    # 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

View on GitHub (pinned to a33fd4c0f1)

Solutions

  1. Throttle your calls: on free keys sleep >= 60s between requests (5/min limit) or spread them under the daily cap
  2. Upgrade to a premium Alpha Vantage key for higher limits
  3. Configure a vendor chain for multi-vendor fallback, e.g. data_vendors="alpha_vantage,yfinance", so the router skips to yfinance on rate limit
  4. Cache responses (the repo already caches OHLCV per symbol/day) and reuse them across runs instead of refetching

Example fix

# before
for symbol in ["AAPL", "MSFT", "GOOG", "NVDA", "AMZN", "TSLA"]:
    get_historical_prices(symbol, "2025-01-10", "2025-01-15")  # 6 calls back-to-back
# -> AlphaVantageRateLimitError: Alpha Vantage rate limit exceeded: ...

# after
import time
for symbol in [...]:
    get_historical_prices(symbol, "2025-01-10", "2025-01-15")
    time.sleep(65)  # respect 5 requests/minute on free tier
# and/or config: {"data_vendors": {"stock_data": "alpha_vantage,yfinance"}}
Defensive patterns

Strategy: retry

Validate before calling

# Throttling is prevention: pace calls under the free-tier 5/min (or your tier's) limit
import time

class RateLimiter:
    def __init__(self, min_interval: float = 61.0):
        self.min_interval = min_interval
        self._last = 0.0
    def wait(self):
        delta = time.monotonic() - self._last
        if delta < self.min_interval:
            time.sleep(self.min_interval - delta)
        self._last = time.monotonic()

Try / catch

from tradingagents.dataflows.alpha_vantage_common import AlphaVantageRateLimitError

try:
    result = fetch(symbol)
except AlphaVantageRateLimitError:
    time.sleep(60)          # honor the throttle window
    result = fetch(symbol)  # single retry; switch vendors if it persists

Prevention

When it happens

Trigger: Exceeding the free-tier limit (25 requests/day on current free keys) or the 5-requests/minute limit; calling premium endpoints on a free key, which return a notice mentioning 'premium'. Rate-limit phrasing is deliberately checked before 'api key' because those notices also mention the key.

Common situations: Long backtest loops hammering the API without sleeps; sharing one free key across processes/CI; upgrading endpoints without upgrading the key tier; running a multi-ticker analysis where each ticker triggers several indicator calls.

Related errors


AI-assisted analysis of TauricResearch/TradingAgents@a33fd4c0f1 (2026-08-14). Data as JSON: /api/errors/ee887f61de2dbd1f. Report an issue: GitHub.