diff --git a/mpcontribs-client/mpcontribs/client/__init__.py b/mpcontribs-client/mpcontribs/client/__init__.py index 5e83250e6..5fffdcd67 100644 --- a/mpcontribs-client/mpcontribs/client/__init__.py +++ b/mpcontribs-client/mpcontribs/client/__init__.py @@ -61,6 +61,7 @@ from plotly.express._chart_types import line as line_chart from cachetools import cached, LRUCache from cachetools.keys import hashkey +from pymatgen.core import SETTINGS RETRIES = 3 MAX_WORKERS = 3 @@ -886,7 +887,9 @@ def __init__( host = os.environ.get("MPCONTRIBS_API_HOST", DEFAULT_HOST) if not apikey: - apikey = os.environ.get("MPCONTRIBS_API_KEY") + apikey = os.environ.get("MPCONTRIBS_API_KEY", SETTINGS.get("PMG_MAPI_KEY")) + if apikey and len(apikey) != 32: + raise MPContribsClientError(f"Invalid API key: {apikey}") if apikey and headers: apikey = None