{"record":{"id":"2aee98cfa0260257","repo":"OpenBB-finance/OpenBB","slug":"fred-api-error-status-code-response-error-co","errorCode":null,"errorMessage":"FRED API Error -> Status Code: {response['error_code']} -> {response.get('error_message', '')}","messagePattern":"FRED API Error -> Status Code: (.+?) -> (.+?)","errorType":"exception","errorClass":"OpenBBError","httpStatus":null,"severity":"error","filePath":"openbb_platform/providers/fred/openbb_fred/models/search.py","lineNumber":242,"sourceCode":"        url = (\n            \"https://api.stlouisfed.org/fred/release/series?\"\n            if query.release_id is not None\n            else \"https://api.stlouisfed.org/fred/series/search?\"\n        )\n\n        exclude = (\n            [\"search_text\", \"limit\"] if query.release_id is not None else [\"limit\"]\n        )\n\n        if query.release_id is not None and query.order_by == \"search_rank\":\n            query.order_by = None  # type: ignore\n\n        querystring = get_querystring(query.model_dump(), exclude).replace(\" \", \"%20\")\n        url = url + querystring + f\"&file_type=json&api_key={api_key}\"\n        response = await fred_get(url)\n\n        if isinstance(response, dict) and \"error_code\" in response:\n            raise OpenBBError(\n                f\"FRED API Error -> Status Code: {response['error_code']} -> {response.get('error_message', '')}\"\n            )\n\n        if isinstance(response, dict) and \"count\" in response:\n            results = response.get(\"seriess\", [])\n            return results\n        raise OpenBBError(\n            f\"Unexpected response format. Expected a dictionary, got {type(response)}\"\n        )\n\n    @staticmethod\n    def transform_data(\n        query: FredSearchQueryParams, data: list[dict], **kwargs: Any\n    ) -> list[FredSearchData]:\n        \"\"\"Transform data.\"\"\"\n        # pylint: disable=import-outside-toplevel\n        from numpy import nan\n        from pandas import DataFrame, Series","sourceCodeStart":224,"sourceCodeEnd":260,"githubUrl":"https://github.com/OpenBB-finance/OpenBB/blob/3e071fcc2cd9f891cac6040ae60296dba76dab46/openbb_platform/providers/fred/openbb_fred/models/search.py#L224-L260","documentation":"Raised in FredSearchFetcher.aextract_data (openbb_fred/models/search.py:242) when the FRED response is a dict containing 'error_code' - the API's structured error envelope. The message surfaces FRED's own status code and message verbatim. Common FRED codes here: 400 (invalid argument or malformed request), 401/402 (invalid or missing API key), 429 (exceeded 50 requests/minute), 500 (FRED server error).","triggerScenarios":"Invalid fred_api_key -> 'api_key' errors (40x); limit/offset beyond result count or bad order_by -> 400; bursting parallel searches -> 429 rate limit; malformed tag expressions from tag_names/exclude_tag_names.","commonSituations":"Unconfigured or expired API key; batch scripts fanning out many fred_search calls concurrently; passing order_by='search_rank' together with a release_id in older versions (the code now strips it, but hand-built queries may still hit 400).","solutions":["Read the embedded error_message - it names the exact offending parameter.","For 40x api_key errors, set a valid key via obb.user.credentials.fred_api_key.","For 429, throttle to under 50 requests/minute and retry with backoff.","For 400, simplify parameters (drop order_by, fix tag syntax) and retry."],"exampleFix":"# before - unthrottled fan-out\nawait asyncio.gather(*[obb.economy.fred.search(query=q) for q in queries])\n\n# after - serialize to respect the 50 req/min limit\nfor q in queries:\n    try:\n        res = await obb.economy.fred.search(query=q)\n    except OpenBBError as e:\n        if '429' in str(e):\n            await asyncio.sleep(60)\n            res = await obb.economy.fred.search(query=q)","handlingStrategy":"retry","validationCode":null,"typeGuard":"def is_fred_api_error(payload: dict) -> bool:\n    \"\"\"True when FRED returned its structured error envelope.\"\"\"\n    return isinstance(payload, dict) and 'error_code' in payload","tryCatchPattern":"from openbb_core.app.model.abstract.error import OpenBBError\nimport time\n\ndef search_with_backoff(**params):\n    for delay in (0, 60, 120):\n        if delay:\n            time.sleep(delay)\n        try:\n            return obb.economy.fred.search(**params)\n        except OpenBBError as e:\n            msg = str(e)\n            if '429' in msg and delay != 120:\n                continue  # rate limited -> backoff and retry\n            raise","preventionTips":["Keep aggregate FRED request rate under 50/minute (key-shared across all provider calls).","Log the full error message - FRED names the offending parameter for 400s.","Request a free higher-limit key if running batch workloads."],"tags":["fred","api-error","rate-limit","api-key"],"backgroundTag":null,"analyzedSha":"3e071fcc2cd9f891cac6040ae60296dba76dab46","analyzedAt":"2026-08-14T23:40:48.960Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}