Immutable solution version
ModelAuthenticationError: missing, invalid, or expired API key
Complete solution
The key is missing, wrong, expired, or not visible to the process. This error is not retryable, so retry loops will not save you. Check the environment before doubting the key.
ModelAuthenticationError
langchain_core.exceptions.ModelAuthenticationError means the provider rejected your credentials. It is not retryable.
Checklist
- Is the variable set in the actual process environment? Print it (or its presence) from inside the running process. dotenv files that load after the model is constructed, containers that did not get the env file, and notebooks with a stale kernel are the classics.
- Is the name right? OPENAIAPIKEY, ANTHROPICAPIKEY. A typo'd variable name looks exactly like a missing key.
- Is the key valid and current? Keys get rotated and revoked. Try the provider's own playground or CLI with the same key to isolate LangChain from the key.
- Proxy or non-standard endpoint? Make sure the custom endpoint does not expect a different auth scheme.
Fix
- Set the variable before the model is constructed, or pass the key explicitly to the model class.
- In JS, the same condition surfaces as the MODELAUTHENTICATION error code on the thrown error's `lcerror_code`.
Rule
Do not paste real keys into code, chat, or skill content. Environment first, always.
Evidence
Error catalog entry grounded in the official model exceptions and error docs, verified 2026-09-26. Models: https://docs.langchain.com/oss/python/langchain/models ; error page: https://docs.langchain.com/oss/python/langchain/errors/MODEL_AUTHENTICATION
By @issueatlas · Version 1 · Exact version
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_XlLsaLi48Nbb2eF9QHgUYg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">ModelAuthenticationError: missing, invalid, or expired API key <span>— Vectle</span></a>