LM Studio Local Server: An OpenAI-Compatible Endpoint

JS
Jai Singh
28 Nov, 2026 3 min read 10 views

LM Studio can run a local server that speaks the OpenAI API format. Any code written for the OpenAI client library can talk to your own model by changing the base URL. The server listens on port 1234 by default, and you turn it on from the developer or server view of the app.

Start the server

Load a model in the app, open the server section (called Developer in recent versions) and switch the server on. The app shows the address it listens on, normally http://localhost:1234. The same section shows request logs, which are useful when you debug why a client does not get the answer you expected.

LM Studio also ships a command-line tool named lms. It can list downloaded models (lms ls), load one (lms load), and start or stop the server (lms server start, lms server stop). Run lms --help to see the exact commands in your version, because the tool is still evolving.

Check that it works

The first call to make is the model list. It tells you the exact identifier to use in later requests:

curl http://localhost:1234/v1/models

The response follows the OpenAI shape: a data array of objects, each with an id. Copy the id of your loaded model. Now send a chat request:

curl http://localhost:1234/v1/chat/completions \
  -H "Content-Type: application/json" \
  -d '{
    "model": "YOUR_MODEL_ID",
    "messages": [
      {"role": "system", "content": "You are concise."},
      {"role": "user", "content": "What is a mutex?"}
    ],
    "temperature": 0.3
  }'

Replace YOUR_MODEL_ID with the identifier from the previous call. The answer is in choices[0].message.content, and the usage object reports prompt and completion token counts, exactly as the hosted API does.

Use the OpenAI Python library

from openai import OpenAI

client = OpenAI(base_url="http://localhost:1234/v1", api_key="lm-studio")

models = client.models.list()
model_id = models.data[0].id

resp = client.chat.completions.create(
    model=model_id,
    messages=[{"role": "user", "content": "Explain a race condition in two sentences."}],
)
print(resp.choices[0].message.content)

The library insists on an API key string even though the local server does not check it, so any non-empty value works. The code asks the server which models are loaded and uses the first one, which avoids hard-coding a name that might change.

What the endpoint supports

Chat completions, plain completions, embeddings (if you load an embedding model) and the model list are the usual set. Streaming works by adding "stream": true to the request. Support for extras such as tool calling or structured output depends on the model and on the app version, so test them with a small request before building on them.

Network access and safety

By default the server only accepts connections from your own machine, which is the safe choice. The settings include an option to serve on the local network. Turning it on lets other computers use your model, but the server has no real access control for casual use, so anyone who can reach the port can use your hardware and read nothing else but run any prompt. Only enable it on a trusted network, and put a proxy with authentication in front for anything shared. Post 82 shows how to do that for any local server.

Common problems

  • Model not found: the model string must match an identifier the server reports. Fetch /v1/models to see it.
  • Connection refused: the server is off, or another program uses port 1234. Change the port in settings.
  • Slow first reply: the model is loading. Load it in advance, or keep it loaded.
  • Docker clients cannot connect: inside a container, localhost means the container itself. Use host.docker.internal on Docker Desktop, and make sure the server listens on a reachable address.

When to prefer another server

LM Studio's server is great for a single developer. If you need many parallel users, headless operation on a Linux box, or fine control, look at llama.cpp's server, vLLM or Ollama, which later posts cover.

Was this article helpful?

Comments

No comments yet. Have a question or a tip? Be the first to share it.

Leave a comment

Comments are reviewed before they appear.