LM StudioLM Studio
模型文档工作用途
  • 下载
  • 登录

主页

登录

模型目录

工作用途

文档

博客

下载


招聘

我们正在招人!

隐私政策

使用条款

lmstudio icon
应用
Python SDK
TS/JS SDK
CLI 参考

文档

lmstudio icon
应用
Python SDK
TS/JS SDK
CLI 参考

LM Studio 文档

API 更新日志

系统要求

离线操作

入门

概述

管理聊天

下载大型语言模型 (LLM)

与文档聊天

集成

模型上下文协议 (MCP)

模型 (model.yaml)

model.yaml 简介

发布 model.yaml

预设

概述

导入与共享

发布预设

拉取更新

推送新版本

API

概述

无头模式

空闲 TTL 和自动清除

结构化输出

工具与函数调用

REST 端点

OpenAI 兼容性 API

LM Studio REST API (beta)

高级

推测解码

导入模型

每个模型的默认设置

提示模板

用户界面

语言

UI 模式

颜色主题

LM Studio 文档

API 更新日志

系统要求

离线操作

入门

概述

管理聊天

下载大型语言模型 (LLM)

与文档聊天

集成

模型上下文协议 (MCP)

模型 (model.yaml)

model.yaml 简介

发布 model.yaml

预设

概述

导入与共享

发布预设

拉取更新

推送新版本

API

概述

无头模式

空闲 TTL 和自动清除

结构化输出

工具与函数调用

REST 端点

OpenAI 兼容性 API

LM Studio REST API (beta)

高级

推测解码

导入模型

每个模型的默认设置

提示模板

用户界面

语言

UI 模式

颜色主题

API

LM Studio REST API (beta)

REST API 包括增强的统计数据,如每秒Token数 (Token / Second) 和首次Token生成时间 (Time To First Token, TTFT),以及关于模型的丰富信息,如已加载与未加载、最大上下文、量化等。

实验性

需要 LM Studio 0.3.6 或更高版本。仍在开发中,端点可能会更改。

LM Studio 现在除了 OpenAI 兼容模式(了解更多)外,还拥有自己的 REST API。

REST API 包括增强的统计数据,如每秒Token数 (Token / Second) 和首次Token生成时间 (Time To First Token, TTFT),以及关于模型的丰富信息,如已加载与未加载、最大上下文、量化等。

支持的 API 端点

  • GET /api/v0/models - 列出可用模型
  • GET /api/v0/models/{model} - 获取特定模型的信息
  • POST /api/v0/chat/completions - 聊天补全(消息 → 助手回复)
  • POST /api/v0/completions - 文本补全(提示 → 补全)
  • POST /api/v0/embeddings - 文本嵌入(文本 → 嵌入)
🚧 我们正在开发此接口。请通过 Github 或 电子邮件 告知我们您认为重要的内容。

启动 REST API 服务器

要启动服务器,请运行以下命令

lms server start
专家提示

您可以将 LM Studio 作为服务运行,并在启动时自动启动服务器而无需启动 GUI。了解无头模式。

端点

GET /api/v0/models

列出所有已加载和已下载的模型

示例请求

curl https://:1234/api/v0/models

响应格式

{
  "object": "list",
  "data": [
    {
      "id": "qwen2-vl-7b-instruct",
      "object": "model",
      "type": "vlm",
      "publisher": "mlx-community",
      "arch": "qwen2_vl",
      "compatibility_type": "mlx",
      "quantization": "4bit",
      "state": "not-loaded",
      "max_context_length": 32768
    },
    {
      "id": "meta-llama-3.1-8b-instruct",
      "object": "model",
      "type": "llm",
      "publisher": "lmstudio-community",
      "arch": "llama",
      "compatibility_type": "gguf",
      "quantization": "Q4_K_M",
      "state": "not-loaded",
      "max_context_length": 131072
    },
    {
      "id": "text-embedding-nomic-embed-text-v1.5",
      "object": "model",
      "type": "embeddings",
      "publisher": "nomic-ai",
      "arch": "nomic-bert",
      "compatibility_type": "gguf",
      "quantization": "Q4_0",
      "state": "not-loaded",
      "max_context_length": 2048
    }
  ]
}

GET /api/v0/models/{model}

获取有关特定模型的信息

示例请求

curl https://:1234/api/v0/models/qwen2-vl-7b-instruct

响应格式

{
  "id": "qwen2-vl-7b-instruct",
  "object": "model",
  "type": "vlm",
  "publisher": "mlx-community",
  "arch": "qwen2_vl",
  "compatibility_type": "mlx",
  "quantization": "4bit",
  "state": "not-loaded",
  "max_context_length": 32768
}

POST /api/v0/chat/completions

聊天补全 API。您提供一个消息数组,并接收聊天中的下一个助手回复。

示例请求

curl https://:1234/api/v0/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "granite-3.0-2b-instruct",
    "messages": [
      { "role": "system", "content": "Always answer in rhymes." },
      { "role": "user", "content": "Introduce yourself." }
    ],
    "temperature": 0.7,
    "max_tokens": -1,
    "stream": false
  }'

响应格式

{
  "id": "chatcmpl-i3gkjwthhw96whukek9tz",
  "object": "chat.completion",
  "created": 1731990317,
  "model": "granite-3.0-2b-instruct",
  "choices": [
    {
      "index": 0,
      "logprobs": null,
      "finish_reason": "stop",
      "message": {
        "role": "assistant",
        "content": "Greetings, I'm a helpful AI, here to assist,\nIn providing answers, with no distress.\nI'll keep it short and sweet, in rhyme you'll find,\nA friendly companion, all day long you'll bind."
      }
    }
  ],
  "usage": {
    "prompt_tokens": 24,
    "completion_tokens": 53,
    "total_tokens": 77
  },
  "stats": {
    "tokens_per_second": 51.43709529007664,
    "time_to_first_token": 0.111,
    "generation_time": 0.954,
    "stop_reason": "eosFound"
  },
  "model_info": {
    "arch": "granite",
    "quant": "Q4_K_M",
    "format": "gguf",
    "context_length": 4096
  },
  "runtime": {
    "name": "llama.cpp-mac-arm64-apple-metal-advsimd",
    "version": "1.3.0",
    "supported_formats": ["gguf"]
  }
}

POST /api/v0/completions

文本补全 API。您提供一个提示并接收一个补全。

示例请求

curl https://:1234/api/v0/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "granite-3.0-2b-instruct",
    "prompt": "the meaning of life is",
    "temperature": 0.7,
    "max_tokens": 10,
    "stream": false,
    "stop": "\n"
  }'

响应格式

{
  "id": "cmpl-p9rtxv6fky2v9k8jrd8cc",
  "object": "text_completion",
  "created": 1731990488,
  "model": "granite-3.0-2b-instruct",
  "choices": [
    {
      "index": 0,
      "text": " to find your purpose, and once you have",
      "logprobs": null,
      "finish_reason": "length"
    }
  ],
  "usage": {
    "prompt_tokens": 5,
    "completion_tokens": 9,
    "total_tokens": 14
  },
  "stats": {
    "tokens_per_second": 57.69230769230769,
    "time_to_first_token": 0.299,
    "generation_time": 0.156,
    "stop_reason": "maxPredictedTokensReached"
  },
  "model_info": {
    "arch": "granite",
    "quant": "Q4_K_M",
    "format": "gguf",
    "context_length": 4096
  },
  "runtime": {
    "name": "llama.cpp-mac-arm64-apple-metal-advsimd",
    "version": "1.3.0",
    "supported_formats": ["gguf"]
  }
}

POST /api/v0/embeddings

文本嵌入 API。您提供一段文本,并返回该文本的嵌入向量表示。

示例请求

curl http://127.0.0.1:1234/api/v0/embeddings \
  -H "Content-Type: application/json" \
  -d '{
    "model": "text-embedding-nomic-embed-text-v1.5",
    "input": "Some text to embed"
  }

示例响应

{
  "object": "list",
  "data": [
    {
      "object": "embedding",
      "embedding": [
        -0.016731496900320053,
        0.028460891917347908,
        -0.1407836228609085,
        ... (truncated for brevity) ...,
        0.02505224384367466,
        -0.0037634256295859814,
        -0.04341062530875206
      ],
      "index": 0
    }
  ],
  "model": "text-embedding-nomic-embed-text-v1.5@q4_k_m",
  "usage": {
    "prompt_tokens": 0,
    "total_tokens": 0
  }
}

请在 Github 上提交问题以报告错误。

本页源文件可在 GitHub 上获取

本页内容

- 支持的 API 端点

启动 REST API 服务器

端点

GET /api/v0/models

GET /api/v0/models/{model}

POST /api/v0/chat/completions

POST /api/v0/completions

POST /api/v0/embeddings

页面源代码在 GitHub 上编辑