OpenBB-finance/OpenBB · error · UnauthorizedError
{error.get('code', '')} -> {error.get('message', '')}
Error message
{error.get('code', '')} -> {error.get('message', '')} What it means
UnauthorizedError raised by the congress.gov amendment-info fetcher when the API response body contains an error whose code includes 'API_KEY' — i.e. congress.gov rejected the credentials. The message concatenates the upstream code and message (e.g. 'API_KEY_NOT_FOUND -> No API key found...'). OpenBB maps this to an auth failure so callers can distinguish 'bad key' from other API errors.
Source
Thrown at openbb_platform/providers/congress_gov/openbb_congress_gov/models/amendment_info.py:107
from openbb_core.provider.utils.helpers import amake_request
api_key = credentials.get("congress_gov_api_key", "") if credentials else ""
amendment_url = query.amendment_url
if amendment_url[0].isnumeric() or (
amendment_url[0] == "/" and amendment_url[1].isnumeric()
):
amendment_url = (
"https://api.congress.gov/v3/amendment/"
+ f"{amendment_url[1:] if amendment_url[0] == '/' else amendment_url}?format=json"
)
url = amendment_url + "&api_key=" + api_key
base_info: dict = await amake_request(url) # type: ignore
if isinstance(base_info, dict) and (error := base_info.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', '')}")
base_info = base_info.get("amendment", {})
cosponsors = base_info.get("cosponsors", {})
if isinstance(cosponsors, dict) and cosponsors.get("count", 0) > 0:
cosponsors_url = cosponsors.get("url", "") + "&api_key=" + api_key
cosponsors_response: dict = await amake_request(cosponsors_url) # type: ignore
cosponsors_list = cosponsors_response.get("cosponsors", [])
if cosponsors_list:
base_info["cosponsors"] = cosponsors_list
actions = base_info.get("actions", {})
if actions.get("count", 0) > 0:
actions_url = actions.get("url", "") + "&api_key=" + api_key
actions_response: dict = await amake_request(actions_url) # type: ignoreView on GitHub (pinned to 3e071fcc2c)
Solutions
- Set the credential: obb.account.credentials.set('congress_gov_api_key', '<key>') or export CONGRESS_GOV_API_KEY.
- Verify the key works with a direct curl to https://api.congress.gov/v3/bill?format=json&api_key=<key>.
- If rate-limited, wait for the quota window to reset or request a higher tier key from congress.gov.
Example fix
# before
obb.congress.amendment_info(amendment_url='119/hamdt/2')
# after
obb.account.credentials.set('congress_gov_api_key', os.environ['CONGRESS_GOV_API_KEY'])
obb.congress.amendment_info(amendment_url='119/hamdt/2') Defensive patterns
Strategy: validation
Validate before calling
import obb
key = obb.account.credentials.get('congress_gov_api_key')
if not key:
raise RuntimeError('congress_gov_api_key is not configured') Try / catch
from openbb_core.provider.utils.errors import UnauthorizedError
try:
res = obb.congress.amendment_info(amendment_url='119/hamdt/2')
except UnauthorizedError:
raise SystemExit('Fix congress_gov_api_key in OpenBB credentials') from None Prevention
- Set credentials once per environment via obb.account.credentials.set.
- Smoke-test the key with one direct API call in deployment checks.
- Stay under 5,000 requests/hour; cache responses to avoid quota-driven suspensions.
When it happens
Trigger: Calling CongressAmendmentInfo without a congress_gov_api_key credential; a key that was revoked, exceeded its rate limit (over 5,000 requests/hour keys get suspended), or never set in the OpenBB hub credentials; env var name typo like CONGRESS_GOV_APIKEY.
Common situations: Fresh installs where the key was never provisioned; CI environments missing the credential secret; shared keys hitting the hourly quota; keys invalidated after the congress.gov key migration.
Related errors
- {error.get('code', '')} -> {error.get('message', '')}
- {error.get('code', '')} -> {error.get('message', '')}
- {error.get('code', '')} -> {error.get('message', '')}
- [Error] -> {e}
- Missing credential '{c}'.{extra_msg} Refer to the documentat
AI-assisted analysis of OpenBB-finance/OpenBB@3e071fcc2c (2026-08-14).
Data as JSON: /api/errors/3f27614feb9e9c37.
Report an issue: GitHub.