OpenBB-finance/OpenBB · error · OpenBBError

Error fetching data from the EIA API -> {e}

Error message

Error fetching data from the EIA API -> {e}

What it means

Extraction wrapper in the EIA Short-Term Energy Outlook model: all URL fetches run via asyncio.gather, and any exception inside a single request (HTTP error, JSON decode failure, auth error surfaced by the callback) aborts the gather and is re-raised with this prefix. The text after '->' is the underlying error string.

Source

Thrown at openbb_platform/providers/eia/openbb_us_eia/models/short_term_energy_outlook.py:219

                    additional_data = additional_response.get("response", {}).get("data", [])  # type: ignore
                    if not additional_data:
                        series_id = (
                            res.get("request", {}).get("params", {}).get("facets", {}).get("seriesId", [])  # type: ignore
                        )
                        masked_url = url.replace(api_key, "API_KEY")
                        messages.append(
                            f"No additional data returned for {series_id or masked_url}"
                        )
                    if additional_data:
                        results.extend(additional_data)
                    n_results += len(additional_data)
                    url = url.replace(f"&offset={offset}", f"&offset={offset + 5000}")
                    offset += 5000

        try:
            await asyncio.gather(*[get_one(url) for url in urls])
        except Exception as e:
            raise OpenBBError(f"Error fetching data from the EIA API -> {e}") from e

        if not results and not messages:
            raise EmptyDataError(
                "The request was returned empty with no error messages."
            )
        if not results and messages:
            raise OpenBBError("\n".join(messages))
        if results and messages:
            warn("\n".join(messages))

        return results

    @staticmethod
    def transform_data(
        query: EiaShortTermEnergyOutlookQueryParams,
        data: list[dict],
        **kwargs: Any,
    ) -> list[EiaShortTermEnergyOutlookData]:

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Check the chained cause after '->' — '403' plus an api_key message means fix the key first.
  2. Validate the EIA API key (obb.user.credentials.eia.api_key) and re-run.
  3. Retry after a short delay for transient network/API failures.
  4. Update the openbb-us-eia provider in case series URL construction changed.
Defensive patterns

Strategy: retry

Try / catch

try:
    res = await obb.energy.short_term_energy_outlook(provider='eia', ...)
except OpenBBError as e:
    msg = str(e)
    if 'api_key' in msg or '403' in msg:
        raise RuntimeError('EIA API key invalid') from e
    await asyncio.sleep(backoff)  # transient network/5xx
    res = await obb.energy.short_term_energy_outlook(provider='eia', ...)

Prevention

When it happens

Trigger: EIA API v2 returning a non-2xx (403 invalid api_key, 400 malformed series_id); network timeout mid-request; the offset-pagination replace producing a bad URL; JSON decode errors when the API returns HTML/error bodies.

Common situations: Expired or mistyped EIA API key; querying a series_id that no longer exists in EIA's STEO API; transient eia.gov outages; rate limiting when fan-out across many URLs.

Related errors


AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14). Data as JSON: /api/errors/a1376d98c51b891b. Report an issue: GitHub.