文档
POST /api/v1/chat
请求体
model : string
要使用的模型的唯一标识符。
input : string | array<object>
要发送给模型的消息。
输入文本 : string
消息的文本内容。
输入对象 : object
包含附加元数据的消息对象。
文本输入 (可选) : object
提供用户消息的文本输入
type : "message"
输入项的类型。
content : string
消息的文本内容。
图像输入 (可选) : object
提供用户消息的图像输入
type : "image"
输入项的类型。
data_url : string
以 base64 编码的数据 URL 形式表示的图像数据。
system_prompt (可选) : string
设置模型行为或指令的系统消息。
integrations (可选) : array<string | object>
为此请求启用的集成列表(插件、临时 MCP 服务器等)。
插件 ID : string
要使用的插件的唯一标识符。插件包含通过 mcp.json 安装的 MCP 服务器(ID 为 mcp/<server_label>)。这是不带自定义配置的插件对象的简写形式。
插件 : object
要使用的插件规范。插件包含通过 mcp.json 安装的 MCP 服务器(ID 为 mcp/<server_label>)。
type : "plugin"
集成类型。
id : string
插件的唯一标识符。
allowed_tools (可选) : array<string>
模型可以从该插件调用的工具名称列表。如果未提供,则允许使用该插件中的所有工具。
临时 MCP 服务器规范 : object
临时 MCP 服务器的规范。允许实时定义 MCP 服务器,而无需在 mcp.json 中预先配置。
type : "ephemeral_mcp"
集成类型。
server_label : string
用于识别 MCP 服务器的标签。
server_url : string
MCP 服务器的 URL。
allowed_tools (可选) : array<string>
模型可以从该服务器调用的工具名称列表。如果未提供,则允许使用该服务器中的所有工具。
headers (可选) : object
发送给服务器的请求中包含的自定义 HTTP 请求头。
stream (可选) : boolean
是否通过 SSE 流式传输部分输出。默认为 false。有关更多信息,请参阅 流式事件。
temperature (可选) : number
Token 选择的随机性。0 表示确定性,较高的值会增加创造力 [0,1]。
top_p (可选) : number
下一个可能 token 的最小累积概率 [0,1]。
top_k (可选) : integer
将下一个 token 的选择限制在概率最高的 top-k 个 token 内。
min_p (可选) : number
token 被选为输出的最小基础概率 [0,1]。
repeat_penalty (可选) : number
对重复 token 序列的惩罚。1 表示不惩罚,较高的值会抑制重复。
max_output_tokens (可选) : integer
生成的最大 token 数量。
reasoning (可选) : "off" | "low" | "medium" | "high" | "on"
推理设置。如果所使用的模型不支持该推理设置,将报错。默认为模型自动选择的设置。
context_length (可选) : integer
作为上下文考虑的 token 数量。使用 MCP 时建议设置较高的值。
store (可选) : boolean
是否存储该对话。如果设置,响应将返回一个 "response_id" 字段。默认为 true。
previous_response_id (可选) : string
要追加到的现有响应的标识符。必须以 "resp_" 开头。
curl https://:1234/api/v1/chat \
-H "Authorization: Bearer $LM_API_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"model": "ibm/granite-4-micro",
"input": "Tell me the top trending model on hugging face and navigate to https://lm-studio.cn",
"integrations": [
{
"type": "ephemeral_mcp",
"server_label": "huggingface",
"server_url": "https://hugging-face.cn/mcp",
"allowed_tools": [
"model_search"
]
},
{
"type": "plugin",
"id": "mcp/playwright",
"allowed_tools": [
"browser_navigate"
]
}
],
"context_length": 8000,
"temperature": 0
}'
响应字段
model_instance_id : string
生成响应的已加载模型实例的唯一标识符。
output : array<object>
生成的输出项数组。每个项可以是三种类型之一。
消息 : object
来自模型的文本消息。
type : "message"
输出项的类型。
content : string
消息的文本内容。
工具调用 : object
模型发起的工具调用。
type : "tool_call"
输出项的类型。
tool : string
调用的工具名称。
arguments : object
传递给工具的参数。根据工具定义,可以包含任何键/值。
output : string
工具返回的结果。
provider_info : object
关于工具提供者的信息。
type : "plugin" | "ephemeral_mcp"
提供者类型。
plugin_id (可选) : string
插件标识符(当 type 为 "plugin" 时)。
server_label (可选) : string
MCP 服务器标签(当 type 为 "ephemeral_mcp" 时)。
推理 : object
来自模型的推理内容。
type : "reasoning"
输出项的类型。
content : string
推理的文本内容。
无效工具调用 : object
模型发起的无效工具调用 - 可能是由于工具名称无效或工具参数无效。
type : "invalid_tool_call"
输出项的类型。
reason : string
工具调用无效的原因。
metadata : object
关于无效工具调用的元数据。
type : "invalid_name" | "invalid_arguments"
发生的错误类型。
tool_name : string
尝试调用的工具名称。
arguments (可选) : object
传递给工具的参数(仅在 invalid_arguments 错误时存在)。
provider_info (可选) : object
关于工具提供者的信息(仅在 invalid_arguments 错误时存在)。
type : "plugin" | "ephemeral_mcp"
提供者类型。
plugin_id (可选) : string
插件标识符(当 type 为 "plugin" 时)。
server_label (可选) : string
MCP 服务器标签(当 type 为 "ephemeral_mcp" 时)。
stats : object
Token 使用情况和性能指标。
input_tokens : number
输入 token 的数量。包括格式化、工具定义以及对话中的先前消息。
total_output_tokens : number
生成的输出 token 总数。
reasoning_output_tokens : number
用于推理的 token 数量。
tokens_per_second : number
每秒生成的 token 速度。
time_to_first_token_seconds : number
生成第一个 token 所需的时间(秒)。
model_load_time_seconds (可选) : number
为此请求加载模型所花费的时间(秒)。仅在模型尚未加载时存在。
response_id (可选) : string
用于后续请求的响应标识符。以 "resp_" 开头。当 store 为 true 时存在。
{
"model_instance_id": "ibm/granite-4-micro",
"output": [
{
"type": "tool_call",
"tool": "model_search",
"arguments": {
"sort": "trendingScore",
"query": "",
"limit": 1
},
"output": "...",
"provider_info": {
"server_label": "huggingface",
"type": "ephemeral_mcp"
}
},
{
"type": "message",
"content": "..."
},
{
"type": "tool_call",
"tool": "browser_navigate",
"arguments": {
"url": "https://lm-studio.cn"
},
"output": "...",
"provider_info": {
"plugin_id": "mcp/playwright",
"type": "plugin"
}
},
{
"type": "message",
"content": "**Top Trending Model on Hugging Face** ... Below is a quick snapshot of what’s on the landing page ... more details on the model or LM Studio itself!"
}
],
"stats": {
"input_tokens": 646,
"total_output_tokens": 586,
"reasoning_output_tokens": 0,
"tokens_per_second": 29.753900615398926,
"time_to_first_token_seconds": 1.088,
"model_load_time_seconds": 2.656
},
"response_id": "resp_4ef013eba0def1ed23f19dde72b67974c579113f544086de"
}
此页面的源代码可在 GitHub 上获取