TauricResearch/TradingAgents · error · FredNotConfiguredError

FRED_API_KEY environment variable is not set. Get a free key

Error message

FRED_API_KEY environment variable is not set. Get a free key at https://fred.stlouisfed.org/docs/api/api_key.html.

What it means

Raised by get_api_key() in tradingagents/dataflows/fred.py when the FRED_API_KEY environment variable is unset or empty. It is a FredNotConfiguredError (subclass of VendorNotConfiguredError, hence also a ValueError), so the router classifies it as 'vendor unavailable' and continues down the vendor chain. The message includes the URL where a free key can be obtained.

Source

Thrown at tradingagents/dataflows/fred.py:88

    "housing_starts": "HOUST",
    "retail_sales": "RSAFS",
}


class FredNotConfiguredError(VendorNotConfiguredError):
    """Raised when FRED 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.
    """


def get_api_key() -> str:
    """Retrieve the FRED API key from the environment."""
    api_key = os.getenv("FRED_API_KEY")
    if not api_key:
        raise FredNotConfiguredError(
            "FRED_API_KEY environment variable is not set. Get a free key at "
            "https://fred.stlouisfed.org/docs/api/api_key.html."
        )
    return api_key


def _resolve_series_id(indicator: str) -> str:
    """Map a friendly alias to a FRED series ID, or pass a raw ID through.

    Raises ``ValueError`` when the input is neither a known alias nor a plausible
    series ID — typically a descriptive phrase the LLM passed instead (e.g.
    "bank of japan rate"). FRED IDs are short and alphanumeric, so this rejects
    it up front with guidance rather than letting it 400 the API.
    """
    key = indicator.strip().lower().replace(" ", "_").replace("-", "_")
    if key in MACRO_SERIES:
        return MACRO_SERIES[key]
    candidate = indicator.strip().upper()

View on GitHub (pinned to a33fd4c0f1)

Solutions

  1. Register a free key at https://fred.stlouisfed.org/docs/api/api_key.html and export FRED_API_KEY="yourkey" in the running environment
  2. Add FRED_API_KEY=... to your .env (or CI secret / docker -e) and restart the process
  3. If FRED was enabled accidentally, remove 'fred' from tool_vendors/get_macro_data so the default vendor is used

Example fix

# before
# FRED_API_KEY unset, config routes get_macro_data to fred
# -> FredNotConfiguredError: FRED_API_KEY environment variable is not set. ...

# after
export FRED_API_KEY="your_fred_key"   # free at https://fred.stlouisfed.org/docs/api/api_key.html
Defensive patterns

Strategy: validation

Validate before calling

import os

def fred_ready() -> bool:
    return bool(os.getenv("FRED_API_KEY"))

Try / catch

from tradingagents.dataflows.fred import FredNotConfiguredError

try:
    report = get_macro_data("cpi", curr_date)
except FredNotConfiguredError:  # also ValueError
    report = "Macro data unavailable: FRED not configured"

Prevention

When it happens

Trigger: Enabling the FRED vendor for get_macro_data (tool_vendors/data_vendors config) without exporting FRED_API_KEY; empty-string value in .env; env var present only in a different shell/container than the one running the process.

Common situations: Fresh clones that set only the LLM keys; deploying to Docker/k8s without mapping the secret; renaming the key incorrectly (e.g. FRED_KEY); CI runners lacking project env vars.

Related errors


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