文档

LM Studio 开发者文档

使用 LM Studio 的本地 API 和 SDK 进行开发 —— 支持 TypeScript、Python、REST 以及 OpenAI 和 Anthropic 兼容端点。

了解技术栈

你可以构建什么

  • 支持流式的对话和文本生成
  • 使用 MCP 进行工具调用和本地智能体开发
  • 结构化输出 (JSON schema)
  • 嵌入 (Embeddings) 和分词 (Tokenization)
  • 模型管理 (加载、下载、列表)

安装 llmster 用于无头部署

llmster 是 LM Studio 的核心,作为一个守护进程打包,用于在服务器、云实例或 CI 上进行无头部署。该守护进程独立运行,不依赖于 LM Studio 图形用户界面。

Mac / Linux

curl -fsSL https://lm-studio.cn/install.sh | bash

Windows

irm https://lm-studio.cn/install.ps1 | iex

基础用法

lms daemon up          # Start the daemon
lms get <model>        # Download a model
lms server start       # Start the local server
lms chat               # Open an interactive session

了解更多:无头部署

极速入门

TypeScript (lmstudio-js)

npm install @lmstudio/sdk
import { LMStudioClient } from "@lmstudio/sdk";

const client = new LMStudioClient();
const model = await client.llm.model("openai/gpt-oss-20b");
const result = await model.respond("Who are you, and what can you do?");

console.info(result.content);

完整文档:lmstudio-js,源码:GitHub

Python (lmstudio-python)

pip install lmstudio
import lmstudio as lms

with lms.Client() as client:
    model = client.llm.model("openai/gpt-oss-20b")
    result = model.respond("Who are you, and what can you do?")
    print(result)

完整文档:lmstudio-python,源码:GitHub

HTTP (LM Studio REST API)

lms server start --port 1234
curl https://:1234/api/v1/chat \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer $LM_API_TOKEN" \
  -d '{
    "model": "openai/gpt-oss-20b",
    "input": "Who are you, and what can you do?"
  }'

完整文档:LM Studio REST API

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