文档

OpenAI 兼容端点

OpenAI 兼容端点

向 Responses、Chat Completions(文本和图像)、Completions 和 Embeddings 端点发送请求。

支持的端点

端点方法文档
/v1/modelsGET模型
/v1/responsesPOST响应
/v1/chat/completionsPOST对话补全
/v1/embeddingsPOST嵌入 (Embeddings)
/v1/completionsPOSTCompletions (补全)

设置 base url 以指向 LM Studio

你可以通过修改 "base URL" 属性使其指向你的 LM Studio 而非 OpenAI 服务器,从而重用现有的 OpenAI 客户端(Python、JS、C# 等)。

注意:以下示例假设服务器端口为 1234

Python 示例

from openai import OpenAI

client = OpenAI(
+    base_url="https://:1234/v1"
)

# ... the rest of your code ...

Typescript 示例

import OpenAI from 'openai';

const client = new OpenAI({
+  baseUrl: "https://:1234/v1"
});

// ... the rest of your code ...

cURL 示例

- curl https://api.openai.com/v1/chat/completions \
+ curl https://:1234/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
-     "model": "gpt-4o-mini",
+     "model": "use the model identifier from LM Studio here",
     "messages": [{"role": "user", "content": "Say this is a test!"}],
     "temperature": 0.7
   }'

在 LM Studio 中使用 Codex

Codex 得到支持,因为 LM Studio 实现了兼容 OpenAI 的 POST /v1/responses 端点。

参见:在 LM Studio 中使用 CodexResponses


其他 OpenAI 客户端库也应具有类似的设置 base URL 的选项。

如果您遇到问题,请加入我们的 Discord 并进入 #🔨-developers 频道。

此页面的源代码可在 GitHub 上找到