OpenBB-finance/OpenBB · error · UnauthorizedError
{error.get('code', '')} -> {error.get('message', '')}
Error message
{error.get('code', '')} -> {error.get('message', '')} What it means
UnauthorizedError from the bills listing fetcher when the congress.gov error payload's code contains 'API_KEY' — the request was rejected for missing/invalid/quota-exhausted credentials. The code and message from the API are embedded in the exception text.
Source
Thrown at openbb_platform/providers/congress_gov/openbb_congress_gov/models/congress_bills.py:301
+ (
f"&toDateTime={query.end_date.strftime('%Y-%m-%d') + 'T23:59:59Z'}"
if query.end_date
else ""
)
)
url += (
f"{'?' if '?' not in url else '&'}"
+ f"limit={query.limit if query.limit is not None else '100'}"
+ (f"&offset={query.offset if query.offset else '0'}")
+ f"&sort=updateDate+{query.sort_by}"
+ f"&format=json&api_key={api_key}"
)
try:
response = await amake_request(url=url)
if isinstance(response, dict) and (error := response.get("error", {})):
if "API_KEY" in error.get("code", ""):
raise UnauthorizedError(
f"{error.get('code', '')} -> {error.get('message', '')}"
)
raise OpenBBError(
f"{error.get('code', '')} -> {error.get('message', '')}"
)
except Exception as e:
# Handle exceptions
raise OpenBBError(e) from e
return response.get("bills", []) # type: ignore
@staticmethod
def transform_data(
query: CongressBillsQueryParams, data: list, **kwargs: Any
) -> list[CongressBillsData]:
"""Transform raw data into CongressBillsData models."""
transformed_data: list[CongressBillsData] = []View on GitHub (pinned to 3e071fcc2c)
Solutions
- Set and verify congress_gov_api_key.
- Test the key with a direct API call.
- Throttle and cache to respect the hourly quota.
Example fix
# before
obb.congress.bills(congress=119)
# after
obb.account.credentials.set('congress_gov_api_key', KEY)
obb.congress.bills(congress=119) Defensive patterns
Strategy: validation
Validate before calling
assert obb.account.credentials.get('congress_gov_api_key'), 'congress_gov_api_key required' Try / catch
from openbb_core.provider.utils.errors import UnauthorizedError
try:
res = obb.congress.bills(congress=119)
except UnauthorizedError:
raise SystemExit('configure congress_gov_api_key') from None Prevention
- Preflight credentials before batch runs.
- One key per workload with per-workload throttling.
- Treat UnauthorizedError as an operational alert, not a code defect.
When it happens
Trigger: Calling obb.congress.bills without a working congress_gov_api_key; suspended key after rate-limit breaches; credential set only in a different profile/environment.
Common situations: Fresh setups, CI secrets not exported, multi-process jobs sharing a key past 5,000 req/hour.
Related errors
- {error.get('code', '')} -> {error.get('message', '')}
- {error.get('code', '')} -> {error.get('message', '')}
- {error.get('code', '')} -> {error.get('message', '')}
- [Error] -> {e}
- Invalid bill_type: {values.bill_type}. Must be one of: {', '
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/577e6dabfece072f.
Report an issue: GitHub.