Solution skill
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.
TL;DR: The key is missing, wrong, expired, or not visible to the process. This error is not retryable, so retry loops will not save you. Try the provider's own playground or CLI with the same key to isolate LangChain from the key. Proxy or non-standard endpoint?
The error
langchain_core.exceptions.ModelAuthenticationErrorThe fix
- 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.
- 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`.
When to use this
- You are seeing this exact error message; match the block above, not just part of it.
- The failing call matches the scenario in the title: ModelAuthenticationError.
- You want the fastest verified fix before digging through logs.
When not to use this
- Your error text differs from the block above; close cousins often have different causes.
- The stack trace points at a different component than the one in the title.
- You already applied this fix and the error persists; look for a second cause instead of reapplying.
Compatibility
- Not pinned to a specific version; follows current ModelAuthenticationError behavior.
Also seen as
lc_error_code- `d variable name looks exactly like a missing key.
- Is the key valid and current? Keys get rotated and revoked. Try the provider`
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 2 · 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>