OpenBB-finance/OpenBB · error · OpenBBError

{query.source} not a valid source. Valid sources: {sources}

Error message

{query.source} not a valid source. Valid sources: {sources}

What it means

Raised by the Biztoc world_news fetcher when query.source is provided but its lowercase form is not in the list of source IDs fetched live from the Biztoc /sources endpoint. The valid set is discovered at runtime, so the error message itself contains the authoritative list. This is an OpenBBError caused purely by invalid user input.

Source

Thrown at openbb_platform/providers/biztoc/openbb_biztoc/models/world_news.py:127

            "Accept-Encoding": "gzip",
        }
        base_url = "https://biztoc.p.rapidapi.com/"
        url = ""
        response: list | dict = []
        if query.term:
            query.term = query.term.replace(" ", "%20")
            url = base_url + f"search?q={query.term}"
            response = await amake_request(
                url, headers=headers, response_callback=response_callback
            )
        elif query.source is not None:
            sources_response = make_request(
                "https://biztoc.p.rapidapi.com/sources",
                headers=headers,
            ).json()
            sources = [source["id"] for source in sources_response]
            if query.source.lower() not in sources:
                raise OpenBBError(
                    f"{query.source} not a valid source. Valid sources: {sources}"
                )
            url = base_url + f"news/source/{query.source.lower()}"
            response = await amake_request(
                url, headers=headers, response_callback=response_callback
            )
        else:
            url1 = base_url + "news/latest"
            response = await amake_request(
                url1, headers=headers, response_callback=response_callback
            )

        return response  # type: ignore

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

View on GitHub (pinned to 3e071fcc2c)

Solutions

  1. Read the valid ids from the error message itself - it prints the current list
  2. Query https://biztoc.p.rapidapi.com/sources once to cache the source catalog before batch jobs
  3. Use the exact lowercase id (e.g. 'blm', 'bbc', 'nbc') rather than display names
  4. Leave source unset to get latest news across all sources

Example fix

// before
obb.news(provider='biztoc', source='BBC News')  # OpenBBError: not a valid source

// after
obb.news(provider='biztoc', source='bbc')  # use the source id from /sources
Defensive patterns

Strategy: validation

Validate before calling

import requests

def valid_biztoc_sources(key: str) -> set[str]:
    r = requests.get('https://biztoc.p.rapidapi.com/sources',
                     headers={'X-RapidAPI-Key': key,
                              'X-RapidAPI-Host': 'biztoc.p.rapidapi.com'})
    return {s['id'] for s in r.json()}

# assert my_source.lower() in valid_biztoc_sources(key) before calling

Try / catch

try:
    news = obb.news(provider='biztoc', source=src)
except OpenBBError as e:
    if 'not a valid source' in str(e):
        print('invalid source; valid list in message:', e)

Prevention

When it happens

Trigger: Calling obb.news(provider='biztoc', source='Bloomberg') when Biztoc's source id is e.g. 'blm' - full display names, wrong casing with no match, or sources that Biztoc dropped since the last check.

Common situations: Developers guessing source names instead of ids; source catalogs changing over time; passing a source valid in another provider (e.g. FMP's source values) to Biztoc.

Related errors


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