{"record":{"id":"387078ac98de738b","repo":"TauricResearch/TradingAgents","slug":"fred-api-key-environment-variable-is-not-set-get","errorCode":null,"errorMessage":"FRED_API_KEY environment variable is not set. Get a free key at https://fred.stlouisfed.org/docs/api/api_key.html.","messagePattern":"FRED_API_KEY environment variable is not set\\. Get a free key at https://fred\\.stlouisfed\\.org/docs/api/api_key\\.html\\.","errorType":"exception","errorClass":"FredNotConfiguredError","httpStatus":null,"severity":"error","filePath":"tradingagents/dataflows/fred.py","lineNumber":88,"sourceCode":"    \"housing_starts\": \"HOUST\",\n    \"retail_sales\": \"RSAFS\",\n}\n\n\nclass FredNotConfiguredError(VendorNotConfiguredError):\n    \"\"\"Raised when FRED is selected but no API key is configured.\n\n    A VendorNotConfiguredError (and thus still a ValueError), so the routing\n    layer's \"vendor unavailable\" handling and existing ValueError callers both\n    keep working.\n    \"\"\"\n\n\ndef get_api_key() -> str:\n    \"\"\"Retrieve the FRED API key from the environment.\"\"\"\n    api_key = os.getenv(\"FRED_API_KEY\")\n    if not api_key:\n        raise FredNotConfiguredError(\n            \"FRED_API_KEY environment variable is not set. Get a free key at \"\n            \"https://fred.stlouisfed.org/docs/api/api_key.html.\"\n        )\n    return api_key\n\n\ndef _resolve_series_id(indicator: str) -> str:\n    \"\"\"Map a friendly alias to a FRED series ID, or pass a raw ID through.\n\n    Raises ``ValueError`` when the input is neither a known alias nor a plausible\n    series ID — typically a descriptive phrase the LLM passed instead (e.g.\n    \"bank of japan rate\"). FRED IDs are short and alphanumeric, so this rejects\n    it up front with guidance rather than letting it 400 the API.\n    \"\"\"\n    key = indicator.strip().lower().replace(\" \", \"_\").replace(\"-\", \"_\")\n    if key in MACRO_SERIES:\n        return MACRO_SERIES[key]\n    candidate = indicator.strip().upper()","sourceCodeStart":70,"sourceCodeEnd":106,"githubUrl":"https://github.com/TauricResearch/TradingAgents/blob/a33fd4c0f134485a43553a2c23a63cb14adbd88f/tradingagents/dataflows/fred.py#L70-L106","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Register a free key at https://fred.stlouisfed.org/docs/api/api_key.html and export FRED_API_KEY=\"yourkey\" in the running environment","Add FRED_API_KEY=... to your .env (or CI secret / docker -e) and restart the process","If FRED was enabled accidentally, remove 'fred' from tool_vendors/get_macro_data so the default vendor is used"],"exampleFix":"# before\n# FRED_API_KEY unset, config routes get_macro_data to fred\n# -> FredNotConfiguredError: FRED_API_KEY environment variable is not set. ...\n\n# after\nexport FRED_API_KEY=\"your_fred_key\"   # free at https://fred.stlouisfed.org/docs/api/api_key.html","handlingStrategy":"validation","validationCode":"import os\n\ndef fred_ready() -> bool:\n    return bool(os.getenv(\"FRED_API_KEY\"))","typeGuard":null,"tryCatchPattern":"from tradingagents.dataflows.fred import FredNotConfiguredError\n\ntry:\n    report = get_macro_data(\"cpi\", curr_date)\nexcept FredNotConfiguredError:  # also ValueError\n    report = \"Macro data unavailable: FRED not configured\"","preventionTips":["Add FRED_API_KEY to the same .env/secret store as your other keys on day one","Run a startup check that logs which vendor keys are present before the first agent run","Keep the free-key signup URL (fred.stlouisfed.org/docs/api/api_key.html) in onboarding docs"],"tags":["configuration","api-key","fred","environment","macro-data"],"backgroundTag":null,"analyzedSha":"a33fd4c0f134485a43553a2c23a63cb14adbd88f","analyzedAt":"2026-08-14T19:45:16.920Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}