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

# 连接到 OpenAI 兼容的模型提供商/代理

演练场允许您使用任何符合 OpenAI API 规范的模型。您可以通过在演练场中设置模型的代理提供商来使用您的模型。

## 部署一个 OpenAI 兼容的模型

许多提供商提供 OpenAI 兼容的模型或代理服务。一些例子包括：

* [LiteLLM Proxy](https://github.com/BerriAI/litellm?tab=readme-ov-file#quick-start-proxy---cli)
* [Ollama](https://ollama.com/)

您可以使用这些提供商来部署您的模型，并获得一个符合 OpenAI API 规范的 API 端点。

请查看完整的[规范](https://platform.openai.com/docs/api-reference/chat)以获取更多信息。

## 在演练场中使用模型

一旦您部署了模型服务器，就可以在[演练场](/langsmith/prompt-engineering-concepts#playground)中使用它。

要访问**提示设置**菜单：

1. 在 **Prompts** 标题下，选择模型名称旁边的齿轮 <Icon icon="settings" iconType="solid" /> 图标。
2. 在 **Model Configuration** 选项卡中，从下拉菜单中选择要编辑的模型。
3. 对于 **Provider** 下拉菜单，选择 **OpenAI Compatible Endpoint**。
4. 将您的 OpenAI 兼容端点添加到 **Base URL** 输入框中。有关示例，请参阅 [Base URL 格式](#base-url-format)。

   <div style={{ textAlign: 'center' }}>
     <img className="block dark:hidden" src="https://mintcdn.com/other-405835d4/4uxGFmQj9AQhEaXK/langsmith/images/openai-compatible-endpoint.png?fit=max&auto=format&n=4uxGFmQj9AQhEaXK&q=85&s=2aac728ae0a4bfaa77f63323c83236ad" alt="LangSmith UI 中的模型配置窗口，已选择一个模型，并且 Provider 下拉菜单中选择了 OpenAI Compatible Endpoint。" width="897" height="572" data-path="langsmith/images/openai-compatible-endpoint.png" />

     <img className="hidden dark:block" src="https://mintcdn.com/other-405835d4/4uxGFmQj9AQhEaXK/langsmith/images/openai-compatible-endpoint-dark.png?fit=max&auto=format&n=4uxGFmQj9AQhEaXK&q=85&s=ff15a676da092d58f01b034e908aae51" alt="LangSmith UI 中的模型配置窗口，已选择一个模型，并且 Provider 下拉菜单中选择了 OpenAI Compatible Endpoint。" width="896" height="552" data-path="langsmith/images/openai-compatible-endpoint-dark.png" />
   </div>

如果一切设置正确，您应该能在演练场中看到模型的响应。您也可以使用此功能来调用下游管道。

有关如何存储模型配置的信息，请参阅[配置提示设置](/langsmith/managing-model-configurations)。

## Base URL 格式

**Base URL** 应指向您的 OpenAI 兼容 API 服务器的根路径。
LangSmith 会自动附加 `/chat/completions`——请勿将其包含在 Base URL 中。

### Base URL 示例

| 提供商                                                      | 示例 Base URL                              |
| -------------------------------------------------------- | ---------------------------------------- |
| [Ollama](https://ollama.com/) (本地)                       | `http://localhost:11434/v1`              |
| [LiteLLM Proxy](https://github.com/BerriAI/litellm) (本地) | `http://localhost:4000`                  |
| [vLLM](https://docs.vllm.ai/) (本地)                       | `http://localhost:8000/v1`               |
| 自托管 (远程)                                                 | `https://my-model-server.example.com/v1` |

支持自定义路径前缀。如果您的服务器在 `/api/v2/chat/completions` 提供补全服务，
请将 Base URL 设置为 `https://my-server.example.com/api/v2`。

***

<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/custom-openai-compliant-model.mdx) 或 [提交问题](https://github.com/langchain-ai/docs/issues/new/choose)。
  </Callout>
</div>
