> ## Documentation Index
> Fetch the complete documentation index at: https://cndoc-langchain.site/llms.txt
> Use this file to discover all available pages before exploring further.

# MODEL_AUTHENTICATION

<Note>
  目前仅在 `langchainjs`（JavaScript/TypeScript）中使用。
</Note>

您的模型提供商拒绝您访问其服务。

此错误通常发生在您的身份验证凭据或 API 密钥存在问题时。

## 故障排除

* 确认您的 API 密钥或身份验证凭据准确且有效。
* 如果使用基于环境的身份验证，请验证：
  * 变量名拼写正确
  * 变量包含已分配的值
  * 第三方包（如 `dotenv`）未干扰加载过程
* 如果使用代理或非标准端点，请确保您的自定义提供商不期望使用替代身份验证方案。
* 通过显式传递凭据来绕过环境变量问题：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
from langchain_openai import ChatOpenAI

model = ChatOpenAI(api_key="YOUR_KEY_HERE")
```

***

<div className="source-links">
  <Callout icon="terminal-2">
    [将这些文档连接](/use-these-docs)到 Claude、VSCode 等，通过 MCP 获取实时答案。
  </Callout>

  <Callout icon="edit">
    [在 GitHub 上编辑此页面](https://github.com/langchain-ai/docs/edit/main/src/oss/langchain/errors/MODEL_AUTHENTICATION.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
