> ## 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.

# 与您的自托管 LangSmith 实例交互

本指南将引导您完成使用自托管 LangSmith 实例的过程。

<Info>
  本指南假设您已经部署了自托管的 LangSmith 实例。如果尚未部署，请参阅 [Kubernetes 部署指南](/langsmith/kubernetes)。
</Info>

### 配置您要与 LangSmith 一起使用的应用程序

LangSmith 提供了一个统一的 API，用于与 Hub 和 LangSmith 后端进行交互。

1. 部署实例后，您可以通过 `http(s)://<host>` 访问 LangSmith 用户界面。
2. LangSmith API 将在 `http(s)://<host>/api/v1` 可用。
3. LangSmith 控制平面将在 `http(s)://<host>/api-host` 可用。

要使用您实例的 API，您需要在应用程序中设置以下环境变量：

```bash theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
LANGSMITH_ENDPOINT=http://<host>/api/v1
LANGSMITH_API_KEY=foo # 如果使用 OAuth，请设置为有效的 API 密钥
```

您也可以直接在 LangSmith SDK 客户端中配置这些变量：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import langsmith
langsmith_client = langsmith.Client(
    api_key='<api_key>',
    api_url='http(s)://<host>/api/v1',
)
```

设置上述内容后，您应该能够运行代码并在自托管实例中查看结果。我们建议您按照 [*快速入门指南*](https://docs.smith.langchain.com/#quick-start) 来熟悉如何使用 LangSmith。

### 自签名证书

如果您为自托管的 LangSmith 实例使用自签名证书，这可能会带来问题，因为 Python 自带一组受信任的证书，其中可能不包含您的自签名证书。要解决此问题，您可能需要使用类似 `truststore` 的工具将系统证书加载到您的 Python 环境中。

您可以这样操作：

1. pip install truststore（或根据您使用的包管理器进行类似操作）

然后使用以下代码加载系统证书：

```python theme={"theme":{"light":"catppuccin-latte","dark":"catppuccin-mocha"}}
import truststore
truststore.inject_into_ssl()
# 您的其余代码
import langsmith
langsmith_client = langsmith.Client(
    api_key='<api_key>',
    api_url='http(s)://<host>/api/v1',
)
```

***

## API 参考

要访问 API 参考，请在浏览器中导航至 `http://<host>/api/docs`。

***

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

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