LM Studio API Setup 2026: OpenAI-Compatible Local LLM Server for Python & JavaScript
LM Studio is often introduced as a desktop app for downloading and chatting with local language models. That is useful, but developers can get much more out of it by running the local model as an API server.
Once the server is running, a Python script, Node.js application, backend service or existing OpenAI-style client can send requests to the model on your own machine. This makes LM Studio useful as a local development backend rather than only a chat application.
This guide shows the cleanest setup for 2026: start the LM Studio server, load a model, test the OpenAI-compatible API with curl, connect from Python, connect from JavaScript, stream responses, and troubleshoot the most common connection and model-name problems.
What the LM Studio API actually gives you
| Need | LM Studio option |
|---|---|
| Chat manually | LM Studio Chat |
| Call a local model from Python | OpenAI-compatible API |
| Call it from Node.js | OpenAI-compatible API |
| Stream generated text | Supported |
| Run a local API on your LAN | Supported through server settings |
| Manage models programmatically | LM Studio native REST API |
LM Studio's current developer documentation provides both its own REST API and OpenAI-compatible endpoints. The OpenAI-compatible route is particularly convenient when your application already uses the OpenAI SDK.
Step 1: Start the LM Studio server
Open LM Studio and switch to the Developer tab. Start the local server.
You can also start it from the command line:
lms server start
The default local address is commonly:
http://localhost:1234
If you changed the server port in LM Studio settings, use that port instead.
Step 2: Load a model first
Before debugging an API client, make sure the model itself works in LM Studio.
Load a model through the application or with the CLI:
lms load
Run a normal prompt in LM Studio Chat. If that works, you have already eliminated a large class of model-loading problems.
This simple sequence saves time:
- Model works in Chat.
- Server starts.
- curl request works.
- Python request works.
- Your application connects.
Step 3: Find the exact model identifier
One of the most common mistakes is using the friendly model name shown in a download page instead of the identifier exposed by the running server.
Do not guess the identifier. Get the list of available models from your LM Studio API and use the exact value returned by your installation.
curl http://localhost:1234/v1/models
The response contains the models available through the OpenAI-compatible endpoint. Copy the relevant id value into your application.
Step 4: Make your first API request with curl
Once the server is running and you know the model ID, test a simple chat request:
curl http://localhost:1234/v1/chat/completions -H "Content-Type: application/json" -d '{
"model": "YOUR_MODEL_ID",
"messages": [
{
"role": "user",
"content": "Explain local LLM quantization in three short paragraphs."
}
],
"temperature": 0.2
}'
Replace YOUR_MODEL_ID with the exact ID returned by /v1/models.
If this request returns a normal assistant message, your local API is working.
Step 5: Connect LM Studio from Python
If your project already uses the OpenAI Python SDK, you can point its base URL at LM Studio.
from openai import OpenAI
client = OpenAI(
base_url="http://localhost:1234/v1",
api_key="lm-studio"
)
response = client.chat.completions.create(
model="YOUR_MODEL_ID",
messages=[
{
"role": "user",
"content": "Give me five practical uses for a local LLM."
}
]
)
print(response.choices[0].message.content)
The API key in this example is simply a placeholder because some client libraries expect the field. If you enable authentication in LM Studio, use the real token instead.
Step 6: Stream the response
Streaming is useful for interactive applications because the user can see the answer while the model is generating it instead of waiting for the complete response.
stream = client.chat.completions.create(
model="YOUR_MODEL_ID",
messages=[
{
"role": "user",
"content": "Explain how a local AI API works."
}
],
stream=True
)
for chunk in stream:
text = chunk.choices[0].delta.content
if text:
print(text, end="", flush=True)
This pattern is useful for local chat interfaces, developer tools and applications where perceived latency matters.
Step 7: Connect LM Studio from Node.js
The same OpenAI-compatible design works from JavaScript and TypeScript.
import OpenAI from "openai";
const client = new OpenAI({
baseURL: "http://localhost:1234/v1",
apiKey: "lm-studio"
});
const response = await client.chat.completions.create({
model: "YOUR_MODEL_ID",
messages: [
{
role: "user",
content: "Explain local inference to a beginner."
}
]
});
console.log(response.choices[0].message.content);
This is particularly convenient for a Next.js or Node backend because the application code can keep the familiar OpenAI client interface while the inference happens locally.
LM Studio as a local backend for a web application
A common architecture looks like this:
Browser
|
v
Next.js / Django / Node backend
|
v
LM Studio API
|
v
Local LLM
|
v
CPU / GPU / Apple Silicon
For a web application, keep the LM Studio connection on the backend whenever possible. Do not expose your model server directly to an untrusted browser unless you have deliberately designed the authentication and network boundaries.
Can another computer use your LM Studio model?
Yes. LM Studio can be configured to serve the API on the local network instead of only on localhost.
This is useful when a desktop has the GPU or memory needed to run the model and another device is only being used as the client.
Before enabling LAN access, configure authentication and check your firewall. A local API becomes a network service once another machine can reach it.
Authentication and network access
LM Studio's server settings include an option to require authentication and an option to serve the API on the local network.
A sensible setup sequence is:
- Develop on localhost.
- Confirm your application works.
- Enable API authentication if network access is required.
- Enable local-network serving.
- Test from the second machine.
- Keep the server off the public internet unless you have deliberately designed a secure deployment.
The goal is simple: do not turn a private model-running desktop into an accidentally reachable API endpoint.
LM Studio API vs Ollama API
| Area | LM Studio | Ollama |
|---|---|---|
| Desktop model management | Strong | Minimal |
| OpenAI-compatible API | Yes | Yes |
| Visual model experimentation | Strong | Usually external UI |
| Simple headless deployment | Possible | Core strength |
| Model API for local development | Yes | Yes |
The right choice depends on the workflow. If you want a desktop application that combines model downloads, testing and API serving, LM Studio is convenient. If you want a lightweight runtime that primarily lives as a background service, Ollama is often simpler.
Our Ollama vs LM Studio comparison goes deeper into that decision.
Using LM Studio with Open WebUI
You do not have to use the LM Studio interface as your final frontend. Because LM Studio exposes OpenAI-compatible endpoints, another local-AI interface can use it as the model backend.
This creates a useful separation:
Open WebUI
|
v
LM Studio API
|
v
Local model
If you want the browser-based interface instead, see our Open WebUI + Ollama connection guide and adapt the provider configuration to your LM Studio endpoint.
Common LM Studio API errors
Connection refused
The server is probably not running, or the client is using the wrong port. Confirm the Developer server is running and check the configured port.
404 on /v1/chat/completions
Check the URL carefully. The base URL should normally end at /v1, while the client adds the endpoint path.
Model not found
Call /v1/models and copy the exact model ID. Do not rely on the display name from the model browser.
The request hangs
Check whether the model is actually loaded and whether the machine has enough memory. A model that barely fits can take a long time to begin generating.
Python says an API key is required
Some SDKs require a non-empty key even when the local server does not enforce authentication. Use a placeholder for local development or configure LM Studio authentication and use the real token.
Works on localhost but not from another computer
Check the LM Studio network-serving setting, the machine's firewall, the IP address, the port and authentication.
Use the native LM Studio REST API when you need model management
The OpenAI-compatible endpoints are ideal for inference. LM Studio also has its own v1 REST API for application-level model management.
The current documentation includes endpoints for listing models, loading models, unloading models, downloading models and checking download status.
This is useful if you are building a local model manager or a development service that needs to select which model is loaded rather than simply sending prompts to whichever model is already running.
How to test a local API before building a full application
Do not start with your entire Next.js application. Use a tiny smoke test.
# 1. Is the server reachable?
curl http://localhost:1234/v1/models
# 2. Does the model answer?
curl http://localhost:1234/v1/chat/completions -H "Content-Type: application/json" -d '{"model":"YOUR_MODEL_ID","messages":[{"role":"user","content":"Say hello."}]}'
# 3. Does your SDK work?
python test_lmstudio.py
Once all three work, move the same configuration into your real application.
Where this becomes useful for developers
- Local RAG: keep model inference on your own machine while your application handles retrieval.
- Coding tools: provide a local model to a development workflow.
- Student projects: build an AI feature without paying for every development request.
- Prototypes: test an OpenAI-style integration before deciding on a hosted provider.
- Private applications: keep model inference on a controlled machine.
FAQ
What is the LM Studio API?
It is the developer interface for sending requests to local models managed by LM Studio. It includes a native REST API and OpenAI-compatible endpoints.
What is the default LM Studio API URL?
The common local base URL is http://localhost:1234. The exact port can be changed in LM Studio server settings.
Can I use the OpenAI Python SDK with LM Studio?
Yes. Point the SDK's base URL to your LM Studio /v1 endpoint.
Can I connect a Next.js application to LM Studio?
Yes. A Next.js server-side route or backend service can call the OpenAI-compatible LM Studio endpoint.
Can LM Studio serve a model to another computer?
Yes. Enable local-network serving and configure authentication and firewall rules appropriately.
Is LM Studio API compatible with OpenAI?
LM Studio provides OpenAI-compatible endpoints, which makes it possible to reuse many OpenAI-style clients and application patterns against a local model.
Official documentation
LM Studio Local LLM API Server 路 LM Studio REST API 路 LM Studio Tool Use 路 LM Studio Developer Docs
Final takeaway
LM Studio becomes much more useful once you stop treating it only as a desktop chat application. Its local API lets your own software talk to the same models, while the OpenAI-compatible interface means you can reuse familiar development patterns.
Start small: run the server, check /v1/models, make one curl request, then connect Python or JavaScript. Once that foundation works, you can add streaming, RAG and more advanced application logic without guessing which layer is responsible when something breaks.