Universal.LMStudio.Client
2.0.0
dotnet add package Universal.LMStudio.Client --version 2.0.0
NuGet\Install-Package Universal.LMStudio.Client -Version 2.0.0
<PackageReference Include="Universal.LMStudio.Client" Version="2.0.0" />
<PackageVersion Include="Universal.LMStudio.Client" Version="2.0.0" />
<PackageReference Include="Universal.LMStudio.Client" />
paket add Universal.LMStudio.Client --version 2.0.0
#r "nuget: Universal.LMStudio.Client, 2.0.0"
#:package Universal.LMStudio.Client@2.0.0
#addin nuget:?package=Universal.LMStudio.Client&version=2.0.0
#tool nuget:?package=Universal.LMStudio.Client&version=2.0.0
Universal.LMStudio.Client
.NET client for LM Studio's native and compatibility v1 APIs.
Start the LM Studio server and load a model first. All clients default to http://localhost:1234.
Native API
Use the native API for stateful chats, LM Studio MCP integrations, and model lifecycle operations.
using Universal.LMStudio.Client.Api.V1;
using Universal.LMStudio.Client.Api.V1.Chat;
using var client = new LMStudioClient();
ChatResponse response = await client.Chat.CreateAsync(new ChatRequest
{
Model = "qwen3.5-2b",
Input = "Reply with one short sentence.",
Reasoning = "off",
Store = false,
});
foreach (ChatOutputItem item in response.Output)
Console.WriteLine(item.Content);
Continue a stored native chat with its response ID:
ChatResponse first = await client.Chat.CreateAsync(new ChatRequest
{
Model = "qwen3.5-2b",
Input = "Remember the word cobalt.",
Store = true,
});
ChatResponse next = await client.Chat.CreateAsync(new ChatRequest
{
Model = "qwen3.5-2b",
Input = "What word did I ask you to remember?",
PreviousResponseId = first.ResponseId,
Store = true,
});
OpenAI-compatible chat
The compatibility types mirror Universal.OpenAI.Client naming where LM Studio supports the corresponding endpoint.
using Universal.LMStudio.Client.V1.Chat;
using var chat = new ChatClient("lm-studio");
CreateCompletionResponse response = await chat.CreateCompletionAsync(
new CreateCompletionRequest
{
Model = "qwen3.5-2b",
Messages = [new UserMessage("Hello from LM Studio")],
Temperature = 0.2f,
});
Console.WriteLine(response.Choices[0].Message.Content);
Function tools
LM Studio returns the requested tool call; your application executes it and sends back the result.
using Universal.Common.Json;
using Universal.LMStudio.Client.V1.Chat;
var weather = new Tool
{
Type = ToolTypes.Function,
Function = new Function
{
Name = "get_weather",
Description = "Get the weather for a city.",
Parameters = new JsonSchema
{
Type = "object",
Properties = new Dictionary<string, JsonSchema>
{
["city"] = new JsonSchema { Type = "string" },
},
Required = ["city"],
},
},
};
using var chat = new ChatClient("lm-studio");
CreateCompletionResponse response = await chat.CreateCompletionAsync(
new CreateCompletionRequest
{
Model = "qwen3.5-2b",
Messages = [new UserMessage("What is the weather in Sydney?")],
Tools = [weather],
ToolChoice = "required",
});
AssistantMessage assistant = (AssistantMessage)response.Choices[0].Message;
ToolCall call = assistant.ToolCalls[0];
Console.WriteLine($"Call {call.Function.Name}: {call.Function.Arguments}");
// Execute the function, then continue the conversation.
CreateCompletionResponse final = await chat.CreateCompletionAsync(
new CreateCompletionRequest
{
Model = "qwen3.5-2b",
Messages =
[
new UserMessage("What is the weather in Sydney?"),
assistant,
new ToolMessage("{\"temperature_c\":22}", call.Id),
],
Tools = [weather],
});
Responses API
using Universal.LMStudio.Client.V1.Responses;
using var responses = new ResponsesClient("lm-studio");
CreateResponseResponse response = await responses.CreateResponseAsync(
new CreateResponseRequest
{
Model = "qwen3.5-2b",
Input = "Give me a prime number below 20.",
Reasoning = new ReasoningOptions { Effort = "low" },
});
Console.WriteLine(response.OutputText);
Continue a stateful Responses conversation with PreviousResponseId:
CreateResponseResponse next = await responses.CreateResponseAsync(
new CreateResponseRequest
{
Model = "qwen3.5-2b",
Input = "Multiply it by two.",
PreviousResponseId = response.Id,
});
Anthropic-compatible Messages
using Universal.LMStudio.Client.V1.Messages;
using var messages = new AnthropicClient("lm-studio");
MessageResponse response = await messages.CreateMessageAsync(new MessageRequest
{
Model = "qwen3.5-2b",
MaxTokens = 256,
System = "Answer concisely.",
Messages = [new Message(Roles.User, "Say hello from LM Studio.")],
});
foreach (TextContentBlock block in response.Content.OfType<TextContentBlock>())
Console.WriteLine(block.Text);
Streaming
Chat Completions, Responses, Messages, and the native chat API support streaming.
using Universal.LMStudio.Client.V1.Chat;
using var chat = new ChatClient("lm-studio");
var request = new CreateCompletionRequest
{
Model = "qwen3.5-2b",
Messages = [new UserMessage("Write one sentence.")],
Stream = true,
};
await foreach (CompletionChunk chunk in chat.CreateCompletionStreamingAsync(request))
{
foreach (CompletionChunkChoice choice in chunk.Choices)
Console.Write(choice.Delta?.Content);
}
Embeddings and models
using Universal.LMStudio.Client.V1;
using var client = new V1Client("lm-studio");
var models = await client.Models.ListModelsAsync();
foreach (var model in models.Data)
Console.WriteLine(model.Id);
var embeddings = await client.Embeddings.CreateEmbeddingsAsync(new()
{
Model = "text-embedding-nomic-embed-text-v1.5",
Input = "Embed this text.",
});
float[] vector = embeddings.Data[0].Embedding;
V1Client aggregates every /v1/* endpoint through Chat, Responses, Embeddings, Completions, Models, and Messages.
Custom endpoint and authentication
Pass LMStudioClientOptions when LM Studio is remote, mounted below a path, requires authentication, or needs a custom timeout.
using Universal.LMStudio.Client.Api.V1;
using Universal.LMStudio.Client.V1;
var options = new LMStudioClientOptions
{
Endpoint = new Uri("http://lmstudio.example:1234/"),
ApiToken = Environment.GetEnvironmentVariable("LM_STUDIO_API_TOKEN"),
Timeout = TimeSpan.FromMinutes(5),
};
using var client = new V1Client(options);
Namespace map
/api/v1/*—Universal.LMStudio.Client.Api.V1.*/v1/chat/completions—Universal.LMStudio.Client.V1.Chat/v1/responses—Universal.LMStudio.Client.V1.Responses/v1/embeddings—Universal.LMStudio.Client.V1.Embeddings/v1/completions—Universal.LMStudio.Client.V1.Completions/v1/models—Universal.LMStudio.Client.V1.Models/v1/messages—Universal.LMStudio.Client.V1.Messages
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Bcl.AsyncInterfaces (>= 10.0.11)
- Newtonsoft.Json (>= 13.0.4)
- Universal.Common.Json (>= 1.9.0)
- Universal.Common.Net.Http (>= 5.2.0)
- Universal.Common.Serialization (>= 2.4.0)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on Universal.LMStudio.Client:
| Package | Downloads |
|---|---|
|
Universal.Operative.Sdk.Discrete.LMStudio
LM Studio native and compatibility API adapters for Universal.Operative.Sdk. |
GitHub repositories
This package is not used by any popular GitHub repositories.
Add complete LM Studio v1 compatibility APIs and tool calling.